Example #1
0
 private void ShowReadyTestForm_Load(object sender, EventArgs e)
 {
     try
     {
         CaijiCommHelper _CaijiCommHelper = new CaijiCommHelper(log, module);
         DataTable       dt = _CaijiCommHelper.GetStadiumList(module.SpecialSetting.TestRoomCode, module.SpecialSetting.MachineType);
         if (dt != null && dt.Rows.Count > 0)
         {
             TreeNode TopNode = new TreeNode();
             TopNode.Text = "待做试验项目";
             this.treeView_Select.Nodes.Add(TopNode);
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 TreeNode Node = new TreeNode();
                 Node.Text = dt.Rows[i]["名称"].ToString() + dt.Rows[i]["委托编号"].ToString();
                 Node.Tag  = dt.Rows[i];
                 this.treeView_Select.TopNode.Nodes.Add(Node);
             }
         }
         else
         {
             this.treeView_Select.Visible = false;
             Label NotHaveData = new Label();
             NotHaveData.Text = "当前没有待做试验";
             NotHaveData.Dock = DockStyle.Fill;
             this.Controls.Add(NotHaveData);
         }
         this.treeView_Select.ExpandAll();
     }
     catch (Exception ex)
     {
         log.WriteLog(ex.Message + "\r\n" + ex.StackTrace, true, true);
     }
 }
Example #2
0
 public LoginForm(Logger log, CaijiCommHelper caijiCommHelper,
                  SXCJModule jzmodel)
 {
     InitializeComponent();
     _Log             = log;
     _CaijiCommHelper = caijiCommHelper;
     _Module          = jzmodel;
     LoadUsers();
 }
Example #3
0
        private static void  InitUpdate()
        {
            #region 工管中心MD5验证

            string          ErrMsg           = string.Empty;
            Logger          log              = new Logger(Path.Combine(Directory.GetCurrentDirectory(), "Log"));
            CaijiCommHelper _CaijiCommHelper = new CaijiCommHelper(log);
            if (!GetMD5(_CaijiCommHelper.GetECode(Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Machinecode"])), out ErrMsg))
            {
            }
            else
            {
            }


            #endregion
        }
Example #4
0
        public static void DoMain()
        {
            Logger log = new Logger(Path.Combine(Directory.GetCurrentDirectory(), "Log"));


            logger.Info("正在获取操作员信息...");
            String        Operator  = "";
            StringBuilder sql_login = new StringBuilder();

            sql_login.Append("select top 1 * from sys_login");

            DataTable LoginData = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_login.ToString() }) as DataTable;

            if (LoginData != null && LoginData.Rows.Count > 0)
            {
                Operator = LoginData.Rows[0]["username"].ToString();
            }

            logger.Info(string.Format("操作员的信息为 {0}", Operator));

            StringBuilder sql_select = new StringBuilder();

            sql_select.Append("select * from sys_testdata");

            DataTable Data = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;

            if (Data == null || Data.Columns.Count == 0)
            {
                logger.Info("获取待上传的数据失败");
            }
            else
            {
                if (!ConfigurationManager.ConfigurationManager.AppSettings.ContainsKey("TestCode") || System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["TestCode"]) == "")
                {
                    throw new Exception("应用配置错误,无效的TestCode标记值");
                }

                String TestCode = System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["TestCode"]);

                if (!ConfigurationManager.ConfigurationManager.AppSettings.ContainsKey("EquipmentCode") || System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["EquipmentCode"]) == "")
                {
                    throw new Exception("应用配置错误,无效的EquipmentCode标记值");
                }

                String EquipmentCode = System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["EquipmentCode"]);

                if (!ConfigurationManager.ConfigurationManager.AppSettings.ContainsKey("Type") || (System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Type"]) != "1" &&
                                                                                                   System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Type"]) != "2"))
                {
                    throw new Exception("应用配置错误,无效的Type标记值" + (ConfigurationManager.ConfigurationManager.AppSettings.ContainsKey("Type") ? ":" + ConfigurationManager.ConfigurationManager.AppSettings["Type"].ToString() : ""));
                }

                String Type = System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Type"]);

                if (!ConfigurationManager.ConfigurationManager.AppSettings.ContainsKey("ZSXH") || System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["ZSXH"]) == "")
                {
                    throw new Exception("应用配置错误,无效的ZSXH标记值");
                }

                String ZSXH = System.Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["ZSXH"]);

                logger.Info(string.Format("待上传的试验数据共{0}条", Data.Rows.Count));

                //完善待发送数据的信息
                foreach (DataRow Row in Data.Rows)
                {
                    logger.Info("开始循环data数据");
                    try
                    {
                        Row["testcode"] = TestCode;
                        Row["sb_code"]  = EquipmentCode;
                        Row["fsdate"]   = DateTime.Now.ToString("yyyy-MM-dd");
                        Row["postinfo"] = Serialize.SerializeToBytes(GetPostInfo(Operator, Type, EquipmentCode, ZSXH, Row));

                        //2014.2.12 yuhongxi 新增新架构上传代码
                        byte[] b = (byte[])Data.Rows[0]["curve"];

                        string CurveText = System.Text.Encoding.Default.GetString(b);
                        logger.Info("1");
                        JZTestData _JZTestData = new JZTestData();

                        List <JZTestConfig> _JZTestConfig    = null;
                        CaijiCommHelper     _CaijiCommHelper = new CaijiCommHelper(log);
                        _JZTestConfig = _CaijiCommHelper.GetConfigJson(Row["modelid"].ToString(), true);
                        if (_JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].SerialNumber <= _JZTestConfig.Count)
                        {
                            for (int i = 0; i < _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config.Count; i++)
                            {
                                switch (_JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config[i].Name)
                                {
                                case JZTestEnum.DHBJ:
                                {
                                    _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config[i].Value = Row["dhbj"];
                                    break;
                                }

                                case JZTestEnum.LDZDL:
                                {
                                    _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config[i].Value = Row["zdlz"];
                                    break;
                                }

                                case JZTestEnum.PHHZ:
                                {
                                    _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config[i].Value = Row["zdlz"];
                                    break;
                                }

                                case JZTestEnum.QFL:
                                {
                                    _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config[i].Value = Row["qflz"];
                                    break;
                                }
                                }
                            }
                        }
                        _JZTestData.SerialNumber = _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].SerialNumber;
                        _JZTestData.TestCells    = _JZTestConfig[int.Parse(Row["curorder"].ToString()) - 1].Config;
                        if (string.IsNullOrEmpty(_JZTestData.WTBH))
                        {
                            _JZTestData.WTBH     = Row["synum"].ToString();
                            _JZTestData.ModuleID = new Guid(Row["modelid"].ToString());
                        }
                        logger.Info(_JZTestData.WTBH);

                        _JZTestData.RealTimeData = new List <JZRealTimeData>();
                        string[] CurveTexts = CurveText.Split(';');
                        DateTime _SartTime;
                        _SartTime = DateTime.Now;
                        for (int i = 0; i < CurveTexts.Length; i++)
                        {
                            try
                            {
                                string[]       DataText           = CurveTexts[i].Split(',');
                                JZRealTimeData tempJZRealTimeData = new JZRealTimeData();
                                tempJZRealTimeData.Time  = _SartTime.AddSeconds(float.Parse(DataText[0]));
                                tempJZRealTimeData.Value = float.Parse(DataText[2]);
                                _JZTestData.RealTimeData.Add(tempJZRealTimeData);
                            }
                            catch (Exception ex)
                            {
                                logger.Info(ex.Message);
                            }
                        }
                        DataTable dt = _CaijiCommHelper.GetSingleStadium((ConfigurationManager.ConfigurationManager.AppSettings["TestCode"].ToString()), _JZTestData.WTBH);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            _JZTestData.StadiumID  = new Guid(dt.Rows[0]["id"].ToString());
                            _JZTestData.DocumentID = new Guid(dt.Rows[0]["DataID"].ToString());
                        }
                        logger.Info(_JZTestData.StadiumID.ToString());
                        logger.Info(_JZTestData.DocumentID.ToString());

                        sql_select = new StringBuilder();
                        sql_select.Append("select testcount from sys_testnum where synum ='" + _JZTestData.WTBH + "'");

                        DataTable dtcount     = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                        int       TotalNumber = System.Convert.ToInt32(dtcount.Rows[0]["testcount"]);

                        if (_CaijiCommHelper.UploadTestData(_JZTestData, TotalNumber, _JZTestData.SerialNumber, (ConfigurationManager.ConfigurationManager.AppSettings["MachineCode"].ToString()), "", "", _JZTestData.TestCells, _JZTestData.RealTimeData))
                        {
                            StringBuilder sql_delete = new StringBuilder();
                            sql_delete.Append("delete from sys_testdata where id = ");
                            sql_delete.Append(System.Convert.ToInt32(Row["id"]));
                            object r = Agent.CallLocalService("Yqun.BO.BOBase.dll", "ExcuteCommand", new object[] { sql_delete.ToString() });
                            logger.Info(string.Format("清空sys_testdata数据表返回状态值:{0}", r));
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Info(ex.Message);
                    }
                    logger.Info("结束循环data数据");
                }
                #region OldCode
                //logger.Info("开始上传数据");
                ////调用传输服务将采集的数据上传到服务器
                //Boolean Result = System.Convert.ToBoolean(Agent.CallRemoteService("Yqun.BO.DataTransportManager.dll", "WriteTestData", new object[] { Data }));

                //String Message = (Result ? "上传采集的试验数据成功" : "上传采集的试验数据失败");
                //logger.Info(Message);

                //if (Result)
                //{
                //    logger.Info(string.Format("共上传试验数据{0}条", Data.Rows.Count));
                //    List<string> SynumList = new List<string>();
                //    foreach (DataRow Row in Data.Rows)
                //    {
                //        String synum = Row["synum"].ToString();
                //        if (!SynumList.Contains(synum))
                //        {
                //            SynumList.Add(synum);
                //        }
                //    }
                //    foreach (string synum in SynumList)
                //    {
                //        logger.Info(synum);
                //    }
                //}
                //else//将数据缓存到sys_testdata_bak表中
                //{
                //    //修改PostDataInfo对象中的重发标记为1(重发数据)
                //    foreach (DataRow Row in Data.Rows)
                //    {
                //        if (Row["postinfo"] != DBNull.Value)
                //        {
                //            PostDataInfo Info = Serialize.DeSerializeFromBytes((byte[])Row["postinfo"]) as PostDataInfo;
                //            Info.CFBS = "1";
                //            Row["postinfo"] = Serialize.SerializeToBytes(Info);
                //        }
                //    }

                //    Result = System.Convert.ToBoolean(Agent.CallLocalService("Yqun.BO.BOBase.dll", "WriteTestDataBak", new object[] { Data }));
                //    if (Result)
                //    {
                //        logger.Info("采集数据成功保存到缓存表中");
                //    }
                //    else
                //    {
                //        logger.Info("采集数据保存到缓存表中失败");
                //    }
                //}

                //logger.Info(string.Format("正在标记试验项目已做:{0}", Result));

                ////标记试验项目已做
                //sql_select = new StringBuilder();
                //sql_select.Append("select modelId,itemId,synum,lq from sys_testdata");
                //DataTable testdata = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                //if (testdata != null && testdata.Columns.Count > 0)
                //{
                //    Result = System.Convert.ToBoolean(Agent.CallRemoteService("Yqun.BO.DataTransportManager.dll", "RemoteUpdateIsDone", new object[] { testdata }));
                //    logger.Info(string.Format("标记试验项目已做:{0}", Result));
                //}
                //else
                //{
                //    logger.Info("标记试验项目已做出错");
                //}

                ////清空sys_testdata中的数据
                //StringBuilder sql_delete = new StringBuilder();
                //sql_delete.Append("delete from sys_testdata");
                //object r = Agent.CallLocalService("Yqun.BO.BOBase.dll", "ExcuteCommand", new object[] { sql_delete.ToString() });
                //logger.Info(string.Format("清空sys_testdata数据表返回状态值:{0}", r));
                #endregion
            }
        }
Example #5
0
        public void StartInit()
        {
            log = new Logger(Path.Combine(Directory.GetCurrentDirectory(), "Log"));
            /// <summary>
            /// 登录实例
            /// </summary>
            LoginForm _LoginForm = null;

            /// <summary>
            /// 获取调用实例
            /// </summary>
            CaijiCommHelper _CaijiCommHelper = null;

            /// <summary>
            /// 试验初始化配置信息
            /// </summary>
            SXCJModule _Module = null;

            try
            {
                _Module          = CalHelper.LoadModule();
                _CaijiCommHelper = new CaijiCommHelper(log, _Module);

                _LoginForm = new LoginForm(log, _CaijiCommHelper, _Module);
ReLogin:
                if (DialogResult.OK == _LoginForm.ShowDialog())
                {
                    if (_LoginForm.IsUpdate && !IsRuningProcess("JZUpgradeAgent"))
                    {
                        JZUpgrade.UpdateAlert ua = new JZUpgrade.UpdateAlert(2);
                        if (ua.ShowDialog() != DialogResult.OK)
                        {
                            goto ReLogin;
                        }

                        ProcessStartInfo Info = new ProcessStartInfo();
                        Info.CreateNoWindow  = false;
                        Info.UseShellExecute = true;
                        Info.FileName        = Path.Combine(Application.StartupPath, "JZUpgrade.exe");
                        Info.Arguments       = "\"5\"";
                        Process.Start(Info);
                        _LoginForm.Enabled = false;
                        _LoginForm.lblUpdateStatus.Text = "正在更新...";
                        goto ReLogin;
                    }

                    #region 用户登录
                    if (_LoginForm.bNetWorkIsConnected)
                    {
                        #region 在线登陆
                        ShowForm();
                        SetText("用户登录中.......");
                        try
                        {
                            string msg = _CaijiCommHelper.Login(_LoginForm.cmbUserName.Text, _LoginForm.txtUserPwd.Text, _Module.SpecialSetting.MachineCode, true);
                            if (msg.ToLower().Trim() != "true")
                            {
                                CloseFrom();
                                if (MessageBox.Show(msg, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                                {
                                    goto ReLogin;
                                }
                                else
                                {
                                    Application.Exit();
                                    return;
                                }
                            }
                            else
                            {
                                #region 网络登录成功

                                _LoginForm.timerUpdate.Stop();

                                #region  步本地用户

                                SetText("同步本地用户.......");
                                _CaijiCommHelper.SysUserInfo(Yqun.Common.ContextCache.ApplicationContext.Current.UserName,
                                                             Yqun.Common.ContextCache.ApplicationContext.Current.Password,
                                                             Yqun.Common.ContextCache.ApplicationContext.Current.UserCode,
                                                             Yqun.Common.ContextCache.ApplicationContext.Current.InTestRoom.Code);
                                #endregion

                                #region  步本地模板
                                SetText("初始化用户配置信息.......");

                                SetText("同步本地模板.......");
                                _CaijiCommHelper.UpdateLocalModelInfo(_Module.SpecialSetting.TestRoomCode);
                                #endregion

                                if (!Yqun.Common.ContextCache.ApplicationContext.Current.IsAdministrator)
                                {
                                    #region  步本地配置信息

                                    try
                                    {
                                        SetText("检查本地配置信息状态.......");
                                        switch (_CaijiCommHelper.GetClientConfigStatus(_Module.SpecialSetting.MachineCode))
                                        {
                                        case -1:
                                            SetText("本地配置信息状态检查失败,请联系管理员.......");
                                            break;

                                        case 0:
                                            //SetText("同步本地配置信息.......");
                                            //_CaijiCommHelper.UploadClientConfig(_Module.SpecialSetting.TestRoomCode, _Module.SpecialSetting.MachineCode, Newtonsoft.Json.JsonConvert.SerializeObject(_Module.SpecialSetting));
                                            MessageBox.Show("本地设备信息未在服务上注册,请联系管理员!", "本地配置提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                                            CloseFrom();
                                            goto ReLogin;

                                        case 1:
                                            SetText("同步本地配置信息.......");
                                            _CaijiCommHelper.UpDateClientConfig(_Module.SpecialSetting.MachineCode, Newtonsoft.Json.JsonConvert.SerializeObject(_Module.SpecialSetting));
                                            break;

                                        case 2:
                                            SetText("同步本地配置信息.......");
                                            _CaijiCommHelper.GetClientConfig(ref _Module, _Module.SpecialSetting.MachineCode);
                                            break;
                                        }
                                        SetText("同步本地配置信息完成.......");
                                    }
                                    catch (Exception exSysConfig)
                                    {
                                        log.WriteLog(exSysConfig.Message + System.Environment.NewLine + exSysConfig.TargetSite, true, true);
                                    }

                                    #endregion
                                }
                                #region   本地数据

                                if (!Yqun.Common.ContextCache.ApplicationContext.Current.IsAdministrator)
                                {
                                    SetText("上传本地数据中.......");
                                    if (_CaijiCommHelper.UpdateLocalDateToServer())
                                    {
                                        SetText("上传本地数据成功.......");
                                    }
                                    else
                                    {
                                        SetText("上传本地数据失败,下次启动将继续上传.......");
                                    }
                                }

                                #endregion

                                #region 记录历史登陆
                                _LoginForm.MemberUser();
                                #endregion

                                #endregion
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("网络连接失败!已经转至本地服务登录!" + ex.Message, "登录提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                            Yqun.Common.ContextCache.ApplicationContext.Current.ISLocalService = true;
                        }
                        #endregion
                    }
                    else
                    {
                        #region 本地用户登录
                        ShowForm();
                        SetText("用户登录中.......");
                        SetText("读取本地登录用户信息.......");
                        DataTable _DataTable = new DataTable();

                        _DataTable = _CaijiCommHelper.GetUserInfo(_LoginForm.cmbUserName.Text, _LoginForm.txtUserPwd.Text);

                        if (_DataTable != null && _DataTable.Rows.Count > 0)
                        {
                            Yqun.Common.ContextCache.ApplicationContext.Current.UserName        = _LoginForm.cmbUserName.Text;
                            Yqun.Common.ContextCache.ApplicationContext.Current.Password        = _LoginForm.txtUserPwd.Text;
                            Yqun.Common.ContextCache.ApplicationContext.Current.UserCode        = _DataTable.Rows[0]["UserCode"].ToString();
                            Yqun.Common.ContextCache.ApplicationContext.Current.InTestRoom.Code = _DataTable.Rows[0]["UserTestCode"].ToString();
                            Yqun.Common.ContextCache.ApplicationContext.Current.ISLocalService  = true;
                            _Module = CalHelper.LoadModule();
                        }
                        else
                        {
                            if (MessageBox.Show("用户名或密码错误,请查证后在登录!", "登录错误", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                            {
                                goto ReLogin;
                            }
                            else
                            {
                                Application.Exit();
                                return;
                            }
                        }
                        #endregion
                    }

                    #region 释放资源
                    if (_SplashScreen != null)
                    {
                        CloseFrom();
                    }
                    #endregion


                    #endregion

                    Application.EnableVisualStyles();
                    //Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm(log, _Module, _CaijiCommHelper));
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.StackTrace, true, false);
            }
        }
Example #6
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public SystemSetupForm(Logger log, CaijiCommHelper TCaijiCommHelper)
 {
     InitializeComponent();
     this.log         = log;
     _CaijiCommHelper = TCaijiCommHelper;
 }
Example #7
0
        public static void DoMain()
        {
            Logger  log = new Logger(Path.Combine(Directory.GetCurrentDirectory(), "Log"));
            Boolean r;

            try
            {
                String itemId    = "";
                String itemName  = "";
                String testCount = "";
                //2014.2.12 yuhongxi 新增参数
                String        Type      = "";
                List <String> modelList = new List <string>();

                StringBuilder sql_select = new StringBuilder();
                sql_select.Append("select Top 1 * from sys_testselecteditem");

                DataTable Data = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                if (Data != null && Data.Rows.Count > 0)
                {
                    DataRow Row = Data.Rows[0];
                    itemId    = Row["Id"].ToString();
                    itemName  = Row["ItemName"].ToString();
                    testCount = Row["testCount"].ToString();
                    //2014.2.12 yuhongxi 新增参数
                    Type = Row["Type"].ToString();
                }
                else
                {
                    logger.Error("获取选中的试验项目时失败!");
                }

                logger.Info(string.Format("当前选中的试验项目是{0},编号为{1}", itemName, itemId));

                //从服务器端查询当前试验室所选试验项目的所有委托编号
                if (itemId != "")
                {
                    //清空sys_testnum数据表
                    r = ClearTestNumInfo();
                    logger.Info(string.Format("清空sys_testnum数据表返回的状态值是{0}", r));

                    //获取与该试验项目相关的委托编号
                    if (!ConfigurationManager.ConfigurationManager.AppSettings.ContainsKey("TestCode") || Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["TestCode"]) == "")
                    {
                        throw new Exception("应用配置错误,获取标记为TestCode的信息失败");
                    }

                    String TestCode = Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["TestCode"]);

                    #region OldCode
                    //DataTable WTBHData = Agent.CallRemoteService("Yqun.BO.DataTransportManager.dll", "GetRemoteWTBHDataTable", new object[] { itemId, TestCode }) as DataTable;
                    #endregion

                    //2014.2.12 yuhongxi 新架构获取提醒信息表
                    logger.Info(Type.ToString());
                    CaijiCommHelper _CaijiCommHelper = new CaijiCommHelper(log);
                    DataTable       WTBHData         = _CaijiCommHelper.GetStadiumList(TestCode, int.Parse(Type));
                    logger.Info(string.Format("当前提醒总共{0}条", WTBHData.Rows.Count));
                    if (WTBHData == null || WTBHData.Columns.Count == 0)
                    {
                        logger.Info(string.Format("获取选中试验项目{0}关联的委托编号失败", itemName));
                    }
                    else
                    {
                        sql_select = new StringBuilder();
                        sql_select.Append("select * from sys_testnum where 1<>1");
                        DataTable TestNumData = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                        if (TestNumData == null || TestNumData.Columns.Count == 0)
                        {
                            logger.Info(string.Format("获取选中试验项目{0}关联的委托编号数据表结构失败", itemName));
                        }
                        else
                        {
                            if (WTBHData.Rows.Count > 0)
                            {
                                logger.Info(string.Format("获取选中试验项目{0}关联的委托编号个数为{1}", itemName, WTBHData.Rows.Count));

                                foreach (DataRow Row in WTBHData.Rows)
                                {
                                    #region OldCode
                                    //String ModelIndex = Row["ModelIndex"].ToString();
                                    //String ModelName = "";
                                    //String WTBH = Row["F_WTBH"].ToString();
                                    //String SJSize = Row["F_SJSize"].ToString();
                                    //String F_ZJRQ = Row["F_ZJRQ"].ToString();
                                    //String TestCount = testCount;
                                    //String lq = Row["DateSpan"].ToString();
                                    #endregion

                                    //2014.2.12 yuhongxi
                                    String ModelIndex = Row["ModuleID"].ToString();
                                    String ModelName  = "";
                                    String WTBH       = Row["委托编号"].ToString();
                                    String SJSize     = Row["试件尺寸"].ToString();
                                    String F_ZJRQ     = Row["制件日期"].ToString();
                                    String TestCount  = testCount;
                                    String lq         = Row["DateSpan"].ToString();

                                    DataRow NewRow = TestNumData.NewRow();
                                    NewRow["ItemId"]    = itemId;
                                    NewRow["modelId"]   = ModelIndex;
                                    NewRow["modelName"] = ModelName;
                                    NewRow["synum"]     = WTBH;
                                    NewRow["testCount"] = TestCount;
                                    NewRow["size"]      = SJSize;
                                    NewRow["zjdate"]    = F_ZJRQ;
                                    NewRow["lq"]        = lq;
                                    TestNumData.Rows.Add(NewRow);
                                }

                                object o = Agent.CallLocalService("Yqun.BO.BOBase.dll", "Update", new object[] { TestNumData });
                                r = (Convert.ToInt32(o) == 1);
                                logger.Info(string.Format("插入选中试验项目{0}关联的委托编号的返回状态为{1}", itemName, r));
                            }
                            else
                            {
                                logger.Info(string.Format("没有与选中试验项目{0}关联的委托编号", itemName));
                            }
                        }
                    }
                }
                else
                {
                    logger.Error(string.Format("当前所选试验项目的ID为{0}", itemId));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    logger.Error(ex.InnerException.Message);
                }

                //访问网络失败,清空sys_testnum数据表
                r = ClearTestNumInfo();
                logger.Error(string.Format("应用出错:{0},清空sys_testnum数据表,返回的状态值是{1}", ex.Message, r));
            }
        }
Example #8
0
        public static void DoMain()
        {
            try
            {
                #region 更新或执行更新\工管中心MD5验证
                Thread _Thread = new Thread(new ThreadStart(InitUpdate));
                _Thread.Start();
                #endregion

                Logger        log        = new Logger(Path.Combine(Directory.GetCurrentDirectory(), "Log"));
                StringBuilder sql_select = new StringBuilder();
                sql_select.Append("select top 1 * from sys_login order by loginId");

                DataTable Data = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                if (Data != null)
                {
                    logger.Info(string.Format("发现{0}条登录记录", Data.Rows.Count));

                    DataRow Row = null;
                    if (Data.Rows.Count > 0)
                    {
                        Row = Data.Rows[0];
                    }
                    else
                    {
                        Row = Data.NewRow();
                        Data.Rows.Add(Row);
                    }

                    String  UserName = Row["username"].ToString();
                    String  Password = Row["password"].ToString();
                    Boolean r        = Agent.LoginProcess(UserName, Password);
                    int     Result   = (r ? 1 : 0);

                    logger.Info(string.Format("用户‘{0}’登录{1}", UserName, r ? "成功" : "失败"));

                    Row["loginresult"] = Result;

                    object o = Agent.CallLocalService("Yqun.BO.BOBase.dll", "Update", new object[] { Data });
                    r = (Convert.ToInt32(o) == 1);
                    logger.Info(string.Format("保存用户‘{0}’登录状态{1}", UserName, r ? "成功" : "失败"));

                    if (!ProcessHelper.IsRuningProcess("JZUpgradeAgent"))
                    {
                        ProcessStartInfo Info = new ProcessStartInfo();
                        Info.CreateNoWindow  = false;
                        Info.UseShellExecute = true;
                        Info.FileName        = Path.Combine(Application.StartupPath, "JZUpgrade.exe");
                        Info.Arguments       = "\"9\"";
                        //1 管理系统文件+不执行,2 采集系统文件+不执行,3 管理系统数据+不执行,
                        //4 管理系统文件+数据+执行;
                        //5 采集系统文件+执行
                        //6 管理系统执行
                        //7 采集系统执行
                        //8 管理系统文件+执行
                        //9 电液伺服系统执行
                        Process.Start(Info);
                    }
                    CaijiCommHelper _CaijiCommHelper = new CaijiCommHelper(log);
                    SXCJModule      _Module          = new SXCJModule();
                    _Module.SpecialSetting.MachineType = Convert.ToInt32(ConfigurationManager.ConfigurationManager.AppSettings["type"]);
                    switch (_CaijiCommHelper.GetClientConfigStatus(Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Machinecode"])))
                    {
                    case -1:
                        break;

                    case 0:
                        _CaijiCommHelper.UploadClientConfig(Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["testcode"]), Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Machinecode"]), Newtonsoft.Json.JsonConvert.SerializeObject(_Module.SpecialSetting));
                        break;

                    case 1:
                        _CaijiCommHelper.UpDateClientConfig(Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Machinecode"]), Newtonsoft.Json.JsonConvert.SerializeObject(_Module.SpecialSetting));
                        break;

                    case 2:
                        _CaijiCommHelper.GetClientConfig(ref _Module, Convert.ToString(ConfigurationManager.ConfigurationManager.AppSettings["Machinecode"]));
                        break;
                    }


                    #region OldCode
                    //if (Internet.IsWanAlive())
                    //{
                    //    logger.Info("正在更新试验项目...");
                    //    sql_select = new StringBuilder();
                    //    sql_select.Append("select * from sys_testitem");
                    //    DataTable networkData = Agent.CallRemoteService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                    //    DataTable localData = Agent.CallLocalService("Yqun.BO.BOBase.dll", "GetDataTable", new object[] { sql_select.ToString() }) as DataTable;
                    //    if (networkData != null && localData != null)
                    //    {
                    //        foreach (DataRow testRow in networkData.Rows)
                    //        {
                    //            String Index = testRow["ID"].ToString();
                    //            DataRow[] DataRows = localData.Select("ID='" + Index + "'");
                    //            if (DataRows.Length == 0)
                    //            {
                    //                DataRow localRow = localData.NewRow();
                    //                localRow["ID"] = testRow["ID"];
                    //                localRow["ItemName"] = testRow["ItemName"];
                    //                localRow["TestCount"] = testRow["TestCount"];
                    //                localRow["Type"] = testRow["Type"];
                    //                localData.Rows.Add(localRow);
                    //            }
                    //            else
                    //            {
                    //                DataRow localRow = DataRows[0];
                    //                localRow["ID"] = testRow["ID"];
                    //                localRow["ItemName"] = testRow["ItemName"];
                    //                localRow["TestCount"] = testRow["TestCount"];
                    //                localRow["Type"] = testRow["Type"];
                    //            }
                    //        }

                    //        object rt = Agent.CallLocalService("Yqun.BO.BOBase.dll", "Update", new object[] { localData });
                    //        r = (Convert.ToInt32(o) == 1);
                    //        logger.Info(string.Format("更新用户‘{0}’的试验项目{1}", UserName, r ? "成功" : "失败"));
                    //    }
                    //    else if (networkData == null)
                    //    {
                    //        logger.Info("获得服务端的试验项目失败");
                    //        logger.Info(string.Format("更新用户‘{0}’的试验项目失败", UserName));
                    //    }
                    //    else if (localData == null)
                    //    {
                    //        logger.Info("获得本机的试验项目表结构失败");
                    //        logger.Info(string.Format("更新用户‘{0}’的试验项目失败", UserName));
                    //    }
                    //}
                    //else
                    //{
                    //    logger.Info("无法访问Internet,更新试验项目失败");
                    //}
                    #endregion
                }
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("应用出错:{0}", ex.Message));
            }
        }