Ejemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //
            path = Application.StartupPath;
            //注册表
            Registry();

            /*
             * IBLL.IPayBLL pbll = new BLL.PayBLL();
             * string sheet_no = "";
             * Program.jh = "001";
             * pbll.MicroPay("81231000525321", "W", 0.01M, "135495986333499595", out sheet_no);
             */

            //处理未捕获的异常
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            //处理UI线程异常
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            //处理非UI线程异常
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            try
            {
                //更新软件
                if (!Debugger.IsAttached)
                {
                    SoftUpdate.Update();
                }


                //验证程序
                //if (SoftUpdate.VerifySoft() != 1)
                //{
                //    MessageBox.Show("没有找到加密狗!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    System.Environment.Exit(0);
                //}

                //创建数据库文件
                try
                {
                    if (!System.IO.Directory.Exists(path + "\\logs"))
                    {
                        System.IO.Directory.CreateDirectory(path + "\\logs");
                    }
                    if (!System.IO.Directory.Exists(path + "\\setting"))
                    {
                        System.IO.Directory.CreateDirectory(path + "\\setting");
                    }
                    if (System.IO.Directory.Exists(path + "\\data") == false)
                    {
                        System.IO.Directory.CreateDirectory(path + "\\data");
                    }
                    string db_file = Application.StartupPath + "\\data\\data";
                    if (System.IO.File.Exists(db_file) == false)
                    {
                        SQLiteByHandClose.CreateFile(db_file);
                    }
                    conn = "Data Source=" + db_file + ";Version=3;Pooling=False;Max Pool Size=100;";
                    var db = new DB.SQLiteByHandClose(conn);
                    db.Open();
                    Program.db = db;
                    Program.db.ExecuteScalar("PRAGMA synchronous = OFF;", null);
                    create_table.bt_sysn_info.Upgrade(db);
                    create_table.bt_par_setting.Upgrade(db);
                    create_table.bi_t_item_cls.Upgrade(db);
                    create_table.bi_t_item_info.Upgrade(db);
                    create_table.bi_t_supcust_info.Upgrade(db);
                    create_table.ic_t_branch_stock.Upgrade(db);
                    create_table.ot_pay_flow.Upgrade(db);
                    create_table.ic_t_inout_store_detail.Upgrade(db);
                    create_table.ic_t_inout_store_master.Upgrade(db);
                    create_table.sa_t_operator_i.Upgrade(db);
                    create_table.sm_t_salesheet.Upgrade(db);
                    create_table.sm_t_salesheet_detail.Upgrade(db);
                    create_table.t_order_detail.Upgrade(db);
                    create_table.bi_t_branch_info.Upgrade(db);
                    create_table.sys_t_sheet_no.Upgrade(db);
                    create_table.bi_t_cust_price.Upgrade(db);
                    create_table.bi_t_sup_item.Upgrade(db);
                    create_table.sys_t_system.Upgrade(db);
                    create_table.t_print_log.Upgrade(db);
                    create_table.t_clear_db_log.Upgrade(db);
                    create_table.t_click_log.Upgrade(db);
                }
                catch (Exception ex)
                {
                    Log.writeLog("创建数据库失败", ex.ToString(), null);
                    var frm = new Forms.MsgForm(ex.GetMessage());
                    frm.ShowDialog();
                    return;
                    //throw ex;
                }

                //检测打印机参数设置
                if (Appsetting.is_print == "1" && Appsetting.print_name == "")
                {
                    var frm = new Forms.MsgForm("请先设置打印机");
                    frm.ShowDialog();
                    return;
                }

                //删除过期数据
                IBLL.ISysBLL bll = new BLL.SysBLL();
                if (1 == 1)
                {
                    try
                    {
                        bll.DeleteOldData();
                    }
                    catch (Exception ex)
                    {
                        Log.writeLog("删除过期数据失败", ex.ToString(), null);
                        var frm = new Forms.MsgForm(ex.GetMessage());
                        frm.ShowDialog();
                    }
                }

                //
                ReadWeight = new BLL.ReadWeight_Common();
                is_run     = true;
                try
                {
                    Thread t = new Thread(() => {
                        while (true)
                        {
                            try
                            {
                                IBLL.IClientBLL bll2 = new BLL.ClientBLL();
                                //判断网络连接状态
                                is_connect = bll2.CheckConnect();

                                for (var i = 0; i < 30; i++)
                                {
                                    Thread.Sleep(1000);
                                    if (!is_run)
                                    {
                                        System.Environment.Exit(0);
                                        break;
                                    }
                                }

                                //30秒自动上传销售和采购数据
                                if (is_connect && is_login)
                                {
                                    int errId     = 0;
                                    string errMsg = "";
                                    bll2.UpLoadSale(out errId, out errMsg);

                                    errId  = 0;
                                    errMsg = "";
                                    bll2.UpLoadInOut(out errId, out errMsg);
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("网络异常[2001]:" + ex.GetMessage());
                            }
                        }
                    });
                    t.Start();
                }
                catch (Exception ex)
                {
                    Log.writeLog("连接服务器异常", ex.ToString(), null);
                    var frm = new Forms.MsgForm(ex.GetMessage());
                    frm.ShowDialog();
                }
                //判断基础档案更新
                try
                {
                    Thread t = new Thread(() =>
                    {
                        while (true)
                        {
                            try
                            {
                                IBLL.IClientBLL bll2 = new BLL.ClientBLL();
                                int errId            = 0;
                                string errMsg        = "";
                                item_count           = bll2.GetItemCount(out errId, out errMsg);
                                sup_count            = bll2.GetSupCusCount(out errId, out errMsg);
                                cus_price_count      = bll2.GetCusPriceCount("", "", out errId, out errMsg);
                                sup_price_count      = bll2.GetSupPriceCount("", "", out errId, out errMsg);


                                if (is_connect && is_login)
                                {
                                    errId  = 0;
                                    errMsg = "";
                                    bll2.DownLoadItemCls(out errId, out errMsg);

                                    errId  = 0;
                                    errMsg = "";
                                    bll2.DownLoadItem(out errId, out errMsg);

                                    errId  = 0;
                                    errMsg = "";
                                    bll2.DownLoadSupCus(out errId, out errMsg);

                                    errId  = 0;
                                    errMsg = "";
                                    bll2.DownLoadCusPrice("", "", out errId, out errMsg);

                                    errId  = 0;
                                    errMsg = "";
                                    bll2.DownLoadSupPrice("", "", out errId, out errMsg);
                                }

                                Thread.Sleep(5 * 60 * 1000);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("网络异常[2002]:" + ex.GetMessage());
                            }
                        }
                    });
                    t.Start();
                }
                catch (Exception ex)
                {
                    Log.writeLog("判断基础档案更新异常", ex.ToString(), null);
                }
                //
                try
                {
                    var lst = bll.GetParSettingList();
                    foreach (Model.bt_par_setting item in lst)
                    {
                        if (item.par_id == "mo_ling")
                        {
                            mo_ling = item.par_val;
                        }
                        else if (item.par_id == "weight_model")
                        {
                            weight_model = item.par_val;
                        }
                        else if (item.par_id == "branch_no")
                        {
                            branch_no = item.par_val;
                        }
                        else if (item.par_id == "jh")
                        {
                            jh = item.par_val;
                        }
                        else if (item.par_id == "input_cus_model")
                        {
                            input_cus_model = item.par_val;
                        }
                        else if (item.par_id == "print_count")
                        {
                            print_count = Conv.ToInt(item.par_val);
                        }
                        else if (item.par_id == "can_input_qty")
                        {
                            can_input_qty = item.par_val;
                        }
                        else if (item.par_id == "is_continue_weight")
                        {
                            is_continue_weight = item.par_val;
                        }
                    }
                    if (branch_no.Length == 0)
                    {
                        if (new Forms.frmInitSetting().ShowDialog() == DialogResult.OK)
                        {
                            if (new Forms.WaitForm("正在加载数据,请稍候", "1").ShowWait())
                            {
                                if (new Forms.NewLoginForm().Login())
                                {
                                    Application.Run(new Forms.frmMenu());
                                }
                            }
                        }
                        else
                        {
                            System.Environment.Exit(0);
                        }
                    }
                    else
                    {
                        if (new Forms.WaitForm("正在加载数据,请稍候", "1").ShowWait())
                        {
                            if (new Forms.NewLoginForm().Login())
                            {
                                Application.Run(new Forms.frmMenu());
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.writeLog("系统异常", ex.ToString(), null);
                    var frm = new Forms.MsgForm(ex.GetMessage());
                    frm.ShowDialog();
                }
            }
            catch (Exception e)
            {
                string str         = "";
                string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";

                if (e != null)
                {
                    str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n",
                                        e.GetType().Name, e.Message, e.StackTrace);
                }
                else
                {
                    str = string.Format("应用程序线程错误:{0}", e);
                }
                Log.writeLog("Main", str);

                MessageBox.Show("系统错误!Message:" + e.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
            public void down()
            {
                try
                {
                    IBLL.IClientBLL bll = new BLL.ClientBLL();
                    if (1 == 1)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadBranch(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载机构档案异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载机构档案完成");
                            }
                        }
                    }

                    if (chk1 == true)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadItemCls(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载品类档案异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载品类档案完成");
                            }
                        }

                        bll.DownLoadItem(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载商品档案异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载商品档案完成");
                            }
                        }
                    }
                    if (chk2 == true)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadOper(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载操作员档案异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载操作员档案完成");
                            }
                        }
                    }
                    if (chk3 == true)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadStock(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载库存/成本异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载库存/成本完成");
                            }
                        }
                    }
                    if (chk4 == true)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadSupCus(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载供应商/客户档案异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载供应商/客户档案完成");
                            }
                        }
                    }
                    if (chk5 == true)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadSupPrice("", "", out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载供应商价格异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载供应商价格完成");
                            }
                        }

                        errId  = 0;
                        errMsg = "";
                        bll.DownLoadCusPrice("", "", out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载客户价格异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载客户价格完成");
                            }
                        }
                    }
                    if (1 == 1)
                    {
                        int    errId  = 0;
                        string errMsg = "";
                        bll.DownLoadSystemPars(out errId, out errMsg);
                        if (errId != 0)
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, -2, "下载系统参数异常:" + errMsg);
                            }
                            else
                            {
                                throw new Exception(errMsg);
                            }
                        }
                        else
                        {
                            if (deleg != null)
                            {
                                mainCon.Invoke(deleg, 1, "下载系统参数完成");
                            }
                        }
                    }

                    if (deleg != null)
                    {
                        mainCon.Invoke(deleg, 0, "");
                    }
                }
                catch (Exception ex)
                {
                    Log.writeLog("frmDownload ->downThread()", ex.GetMessage(), ex.StackTrace);
                    if (deleg != null)
                    {
                        mainCon.Invoke(deleg, -1, ex.GetMessage());
                    }
                }
            }