예제 #1
0
 public void checkUpdate()
 {
     app.UpdateFinish += new UpdateState(app_UpdateFinish);
     try
     {
         if (app.IsUpdate)
         {
             app.Update();
         }
         else
         {
             MessageBox.Show("未检测到新版本!");
             Application.Exit();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
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);
            }
        }