コード例 #1
0
ファイル: StaidumInfoForm.cs プロジェクト: scaperow/-V2.0
 private void SetJZTestData()
 {
     _JZTestData = new JZTestData();
     _JZTestData.RealTimeData = new List <JZRealTimeData>();
     _JZTestData.TestCells    = new List <JZTestCell>();
     _JZTestData.TestRoomCode = module.SpecialSetting.TestRoomCode;
     _JZTestData.UserName     = Yqun.Common.ContextCache.ApplicationContext.Current.UserName;
     _JZTestData.DocumentID   = Guid.Empty;
     _JZTestData.ModuleID     = Guid.Empty;
     _JZTestData.StadiumID    = Guid.Empty;
     _JZTestData.WTBH         = "";
     SJCC = "";
     QDDJ = "";
     if (this.treeView_Select.Visible)
     {
         foreach (TreeNode Node in treeView_Select.Nodes[0].Nodes)
         {
             if (Node.Checked)
             {
                 DataRow row = Node.Tag as DataRow;
                 if (row != null)
                 {
                     _JZTestData.DocumentID = new Guid(row["DataID"].ToString());
                     _JZTestData.ModuleID   = new Guid(row["ModuleID"].ToString());
                     _JZTestData.StadiumID  = new Guid(row["ID"].ToString());
                     _JZTestData.WTBH       = row["委托编号"].ToString();
                     SJCC = row["试件尺寸"].ToString();
                     QDDJ = row["强度等级"].ToString();
                     LQ   = (Convert.ToInt32(row["DateSpan"]) / 24).ToString();
                 }
                 break;
             }
         }
     }
 }
コード例 #2
0
ファイル: CaijiCommHelper.cs プロジェクト: scaperow/-V2.0
        /// <summary>
        ///  上传数据,返回GUID
        /// </summary>
        /// <param name="_JZTestData"></param>
        /// <param name="_TotalNumber"></param>
        /// <param name="currentNumber"></param>
        /// <param name="_EquipmentCode"></param>
        /// <param name="_UploadJson"></param>
        /// <param name="UploadCode"></param>
        /// <param name="testData"></param>
        /// <param name="realTimeData"></param>
        /// <param name="_Guid"></param>
        /// <returns></returns>
        public bool UploadTestData(JZTestData _JZTestData, Int32 _TotalNumber, Int32 currentNumber, string _EquipmentCode, string _UploadJson, string UploadCode, List<JZTestCell> testData, List<JZRealTimeData> realTimeData,out Guid _Guid)
        {
            _Guid = Guid.Empty;
            try
            {
                _Guid = UpdateCurrentDataAsLocal(_JZTestData, _TotalNumber, currentNumber, _EquipmentCode, _UploadJson, UploadCode, testData, realTimeData);
                log.WriteLog("数据保存本地WTBH:" + _JZTestData.WTBH, false, false);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message + "\r\n" + ex.StackTrace, true, true);
            }
            try
            {

                Boolean uploaded = UploadTestData(_JZTestData.
DocumentID, _JZTestData.ModuleID, _JZTestData.StadiumID, _JZTestData.WTBH, _JZTestData.TestRoomCode, currentNumber, _JZTestData.UserName, ObjectToJson(testData), DataEncoder.GZipCompressString(ObjectToJson(realTimeData)), _TotalNumber, _EquipmentCode, _UploadJson, UploadCode, DateTime.Now.AddMinutes(_SXCJModule.SpecialSetting.TimeSpanMinute));
                if (uploaded)
                {
                    log.WriteLog("数据WTBH:" + _JZTestData.WTBH + "上传成功", false, false);
                    DelUpdateSuceesData(_Guid.ToString());
                    return true;
                }
                else
                {
                    log.WriteLog("数据WTBH:" + _JZTestData.WTBH + "上传失败", false, false);
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message + "\r\n" + ex.StackTrace, true, true);
            }
            _Guid = Guid.Empty;
            return false;
        }
コード例 #3
0
ファイル: CaijiCommHelper.cs プロジェクト: scaperow/-V2.0
        private Guid UpdateCurrentDataAsLocal(JZTestData _JZTestData, int _TotalNumber, int currentNumber, string EquipmenCode, string UpDataInfo, string UploadCode, List<JZTestCell> testData, List<JZRealTimeData> realTimeData)
        {
            Guid _tempGuid=Guid.NewGuid();
            StringBuilder _tempSB = new StringBuilder();
            _tempSB.Append("insert into sys_test_data values(");
            _tempSB.AppendFormat("'{0}'", _tempGuid);
            _tempSB.AppendFormat(",'{0}'", _JZTestData.DocumentID);
            _tempSB.AppendFormat(",'{0}'", _JZTestData.StadiumID);
            _tempSB.AppendFormat(",'{0}'", _JZTestData.ModuleID.ToString());
            _tempSB.AppendFormat(",'{0}'", _JZTestData.WTBH.ToString());
            _tempSB.AppendFormat(",'{0}'", _JZTestData.TestRoomCode.ToString());
            _tempSB.AppendFormat(",{0}", currentNumber.ToString());
            _tempSB.AppendFormat(",'{0}'", _JZTestData.UserName.ToString());
            _tempSB.AppendFormat(",'{0}'",DateTime.Now.AddMinutes(_SXCJModule.SpecialSetting.TimeSpanMinute));
            _tempSB.AppendFormat(",'{0}'", ObjectToJson(testData));
            _tempSB.AppendFormat(",'{0}'", DataEncoder.GZipCompressString(ObjectToJson(realTimeData)));
            _tempSB.AppendFormat(",1");
            _tempSB.AppendFormat(",{0}", _TotalNumber);
            _tempSB.AppendFormat(",'{0}'", _JZTestData.TestRoomCode);
            _tempSB.AppendFormat(",'{0}'", EquipmenCode);
            _tempSB.AppendFormat(",'{0}'", UpDataInfo.Replace("'","''"));
            _tempSB.AppendFormat(",'{0}'", UploadCode);
            _tempSB.AppendFormat(",0");
            _tempSB.AppendFormat(",0");
            _tempSB.Append(");");
            try
            {
                log.WriteLog(_tempSB.ToString(), false, false);

                lock (_LockObject)
                {
                    _SqlLocalHlper.Execute(_tempSB.ToString());
                }
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message + "\r\n" + ex.StackTrace, true, true);
                try
                {
                    if (GetColumCount())
                    {
                        _SqlLocalHlper.Execute(_tempSB.ToString());
                    }
                }
                catch (Exception ex2)
                {
                    log.WriteLog(ex2.Message + "\r\n" + ex2.StackTrace, true, true);
                    log.WriteLog(_tempSB.ToString(), true, true);
                    if (ex2.Message.Trim() == "")
                    {
                        UpdateCurrentDataAsLocalFor2Sql(_JZTestData, _TotalNumber, currentNumber, EquipmenCode, UpDataInfo, UploadCode, testData, realTimeData);
                    }
                }
            }
            return _tempGuid;
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: scaperow/-V2.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
            }
        }
コード例 #5
0
ファイル: CaijiCommHelper.cs プロジェクト: scaperow/-V2.0
        /// <summary>
        /// 保存实验数据到本地;分2条sql完成
        /// </summary>
        /// <param name="_JZTestData"></param>
        /// <param name="_TotalNumber"></param>
        /// <param name="currentNumber"></param>
        /// <param name="EquipmenCode"></param>
        /// <param name="UpDataInfo"></param>
        /// <param name="UploadCode"></param>
        /// <param name="testData"></param>
        /// <param name="realTimeData"></param>
        /// <returns></returns>
        public bool UpdateCurrentDataAsLocalFor2Sql(JZTestData _JZTestData, int _TotalNumber, int currentNumber, string EquipmenCode, string UpDataInfo, string UploadCode, List<JZTestCell> testData, List<JZRealTimeData> realTimeData)
        {
            bool IsSuceess = false;
            Guid _tempGuid = Guid.NewGuid();
            StringBuilder _tempSB = new StringBuilder();
            _tempSB.Append("insert into sys_test_data values(");
            _tempSB.AppendFormat("'{0}'", _tempGuid);
            _tempSB.AppendFormat(",'{0}'", Guid.Empty);
            _tempSB.AppendFormat(",'{0}'", Guid.Empty);
            _tempSB.AppendFormat(",'{0}'", _JZTestData.ModuleID.ToString());
            _tempSB.AppendFormat(",'{0}'", _JZTestData.WTBH.ToString());
            _tempSB.AppendFormat(",'{0}'", _JZTestData.TestRoomCode.ToString());
            _tempSB.AppendFormat(",{0}", currentNumber.ToString());
            _tempSB.AppendFormat(",'{0}'", _JZTestData.UserName.ToString());
            _tempSB.AppendFormat(",'{0}'", DateTime.Now.AddMinutes(_SXCJModule.SpecialSetting.TimeSpanMinute));
            _tempSB.AppendFormat(",'{0}'", ObjectToJson(testData));
            _tempSB.AppendFormat(",'{0}'", "");
            _tempSB.AppendFormat(",1");
            _tempSB.AppendFormat(",{0}", _TotalNumber);
            _tempSB.AppendFormat(",'{0}'", _JZTestData.TestRoomCode);
            _tempSB.AppendFormat(",'{0}'", EquipmenCode);
            _tempSB.AppendFormat(",'{0}'", UpDataInfo.Replace("'", "''"));
            _tempSB.AppendFormat(",'{0}'", UploadCode);
            _tempSB.AppendFormat(",0");
            _tempSB.AppendFormat(",0");
            _tempSB.Append(");");
            try
            {
                log.WriteLog(_tempSB.ToString(), false, false);
                _SqlLocalHlper.Execute(_tempSB.ToString());
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.Message + "\r\n" + ex.StackTrace, true, true);
                try
                {
                    if (GetColumCount())
                    {
                        _SqlLocalHlper.Execute(_tempSB.ToString());
                    }
                }
                catch (Exception ex2)
                {
                    log.WriteLog(ex2.Message + "\r\n" + ex2.StackTrace, true, true);
                    log.WriteLog(_tempSB.ToString(), true, true);
                    IsSuceess = false;
                }
            }
            _tempSB.Remove(0, _tempSB.Length);
            _tempSB.AppendFormat("update sys_test_data set RealTimeDate='{0}' where ID='{1}'", ObjectToJson(realTimeData),_tempGuid.ToString());
            try
            {
                log.WriteLog(_tempSB.ToString(), false, false);
                _SqlLocalHlper.Execute(_tempSB.ToString());
                IsSuceess = true;
            }
            catch (Exception ex1)
            {
                log.WriteLog(ex1.Message + "\r\n" + ex1.StackTrace, true, true);
            }

            return IsSuceess;
        }