using HH.YiDaSyncNC.DataSync;
using HH.YiDaSyncNC.Helper;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace HH.YiDaSyncNC
{
    class Program
    {
        #region 数据库对象
        public static SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = ConfigurationManager.AppSettings["Conn_NC"].ToString(),
            DbType = DbType.SqlServer,
            IsAutoCloseConnection = true
        });

        public static SqlSugarClient db_nc = new SqlSugarClient(new ConnectionConfig()
        {
            ConnectionString = ConfigurationManager.AppSettings["Conn_NC"].ToString(),
            DbType = DbType.SqlServer,
            IsAutoCloseConnection = true
        });
        #endregion

        public static string _Static_AppType = ConfigurationManager.AppSettings["AppType"];
        public static string _Static_SystemToken = ConfigurationManager.AppSettings["SystemToken"];
        public static string _Static_UserId = ConfigurationManager.AppSettings["UserId"];
        public static string _Static_FormId_WL = ConfigurationManager.AppSettings["FormId_WL"];
        public static string _Static_FormId_XMD = ConfigurationManager.AppSettings["FormId_XMD"];
        public static string _Static_FormId_GYS = ConfigurationManager.AppSettings["FormId_GYS"];
        public static string _Static_FormId_KH = ConfigurationManager.AppSettings["FormId_KH"];
        public static string _Static_FormId_ZC = ConfigurationManager.AppSettings["FormId_ZC"];
        public static string _Static_FormId_CGDD = ConfigurationManager.AppSettings["FormId_CGDD"];
        public static string _Static_FormId_KP = ConfigurationManager.AppSettings["FormId_KP"];
        public static string _Static_FormId_FK = ConfigurationManager.AppSettings["FormId_FK"];
        public static string _Static_FormId_FYBX = ConfigurationManager.AppSettings["FormId_FYBXD"];
        public static string _Static_FormId_clBX = ConfigurationManager.AppSettings["FormId_CLBXD"];
        public static string _Static_FormCode_fyBX = ConfigurationManager.AppSettings["FormCode_FYBXD"];
        public static string _Static_FormCode_clBX = ConfigurationManager.AppSettings["FormCode_CLBXD"];
        public static string _Static_FormId_ZZDA = ConfigurationManager.AppSettings["FormId_ZZDA"];
        public static string _Static_FormId_ZZHX = ConfigurationManager.AppSettings["FormId_ZZHX"];
        public static string _Static_FormId_ZZSQ = ConfigurationManager.AppSettings["FormId_ZZSQ"];
        public static string _Static_FormId_BZJ = ConfigurationManager.AppSettings["FormId_BZJ"];
        public static string _Static_FormCode_FPRZD = ConfigurationManager.AppSettings["FormCode_FPRZD"];
        public static string _Static_FormId_FPRZD = ConfigurationManager.AppSettings["FormId_FPRZD"];

        public static string _Static_NCApiUrl = ConfigurationManager.AppSettings["NCApiUrl"];

        static void Main(string[] args)
        {
            try
            {
                #region 基础档案
                //// 物料
                WL_SyncService wL_SyncService = new WL_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_WL, db, db_nc, _Static_NCApiUrl);
                wL_SyncService.DataSync();

                //// 项目点
                XMD_SyncService xMD_SyncService = new XMD_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_XMD, db, db_nc, _Static_NCApiUrl);
                xMD_SyncService.DataSync();

                //// 资产
                ZC_SyncService zc_SyncService = new ZC_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_ZC, db, db_nc, _Static_NCApiUrl);
                zc_SyncService.DataSync();

                //////供应商
                GYS_SyncService gYS_SyncService = new GYS_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_GYS, db, db_nc, _Static_NCApiUrl);
                gYS_SyncService.DataSync();

                //客户
                KH_SyncService kh_SyncService = new KH_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_KH, db, db_nc, _Static_NCApiUrl);
                kh_SyncService.DataSync();
                #endregion

                #region 开票
                KP_SyncService kp_SyncService = new KP_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_KP, db, db_nc, _Static_NCApiUrl);
                kp_SyncService.DataSync();

                // 退票
                KP_TP_SyncService kp_tp_SyncService = new KP_TP_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_KP, db, db_nc, _Static_NCApiUrl);
                kp_tp_SyncService.DataSync();
                #endregion

                #region 采购订单
                ////////// 采购订单
                CGDD_SyncService cgdd_SyncService = new CGDD_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_CGDD, db, db_nc, _Static_NCApiUrl);
                cgdd_SyncService.DataSync();
                #endregion

                #region 付款单
                // 付款单
                //FK_FKD_SyncService fk_fkd_SyncService = new FK_FKD_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FK, db, db_nc, _Static_NCApiUrl);
                //fk_fkd_SyncService.DataSync();

                // 日常费用付款
                //FK_SyncService fk_SyncService = new FK_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FK, db, db_nc, _Static_NCApiUrl);
                //fk_SyncService.DataSync();

                // 费用报销付款
                //FK_FYBX_SyncService fk_fybx_SyncService = new FK_FYBX_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FYBX, db, db_nc, _Static_NCApiUrl);
                //fk_fybx_SyncService.DataSync();

                // 差旅报销付款
                //FK_CLBX_SyncService fk_clbx_SyncService = new FK_CLBX_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_clBX, db, db_nc, _Static_NCApiUrl);
                //fk_clbx_SyncService.DataSync();

                // 付款单 预付类型 生成凭证 zxh
                //FKGL_SyncService fkgl_SyncService = new FKGL_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FK, db, db_nc, _Static_NCApiUrl);
                //fkgl_SyncService.DataSync();
                // 付款单 预付类型 生成应付单 zxh 没用
                //FKYF_SyncService fkyf_SyncService = new FKYF_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FK, db, db_nc, _Static_NCApiUrl);
                //fkyf_SyncService.DataSync();

                // 日常费用付款（预付）
                //FK_YF_SyncService fk_yf_SyncService = new FK_YF_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FK, db, db_nc, _Static_NCApiUrl);
                //fk_yf_SyncService.DataSync();

                //// 预付 发票入账  生成凭证 zxh
                //YF_FPRZ_SyncService yf_fprz_SyncService = new YF_FPRZ_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FPRZD, db, db_nc, _Static_NCApiUrl);
                //yf_fprz_SyncService.DataSync();

                // 费用报销单 zxh 用不到
                //BX_SyncService bx_SyncService = new BX_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FYBX, db, db_nc, _Static_NCApiUrl);
                //bx_SyncService.DataSyncFYBX();
                #endregion

                #region 薪资付款
                // 应付
                //FK_XZ_SyncService fk_xz_SyncService = new FK_XZ_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_FK, db, db_nc, _Static_NCApiUrl);
                //fk_xz_SyncService.DataSync_公积金();
                //fk_xz_SyncService.DataSync_社保();
                //fk_xz_SyncService.DataSync_薪资();
                //fk_xz_SyncService.DataSync_发放人力外包工资();

                //fk_xz_SyncService.DataSync_业务外包付款();

                //fk_xz_SyncService.DataSync_公积金_预付();
                //fk_xz_SyncService.DataSync_社保_预付();
                //fk_xz_SyncService.DataSync_薪资_预付();
                //fk_xz_SyncService.DataSync_发放人力外包工资_预付();

                #endregion

                #region 借还款
                //// 暂支申请  生成凭证 zxh
                //ZZD_GL_SyncService zzsq_SyncService = new ZZD_GL_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_ZZSQ, db, db_nc, _Static_NCApiUrl);
                //zzsq_SyncService.DataSync();
                //// 还款单  生成凭证 zxh
                //HKD_GL_SyncService hkd_SyncService = new HKD_GL_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_ZZHX, db, db_nc, _Static_NCApiUrl);
                //hkd_SyncService.DataSync();
                #endregion

                #region 保证金
                BZJ_SyncService bzj_SyncService = new BZJ_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_BZJ, db, db_nc, _Static_NCApiUrl);
                bzj_SyncService.DataSync();
                #endregion

                #region 开票档案回款回写
                //KP_HK_SyncService kp_hk_SyncService = new KP_HK_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_KP, db, db_nc, _Static_NCApiUrl);
                //kp_hk_SyncService.DataSync();
                #endregion

                #region 资产折旧回写
                //ZC_ZJHX_SyncService zc_zjhx_SyncService = new ZC_ZJHX_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_ZC, db, db_nc, _Static_NCApiUrl);
                //zc_zjhx_SyncService.DataSync();
                #endregion

                #region 保证金回款
                //BZJ_HK_SyncService bzj_hk_SyncService = new BZJ_HK_SyncService(_Static_AppType, _Static_SystemToken, _Static_UserId, _Static_FormId_BZJ, db, db_nc, _Static_NCApiUrl);
                //bzj_hk_SyncService.DataSync();
                #endregion

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(JsonConvert.SerializeObject(ex), "同步异常");
                Console.WriteLine($@"结束同步:{DateTime.Now}");
                Environment.Exit(0);
            }
        }
    }
}
