예제 #1
0
        public void OperatorDefects(OracleCommand cmd, IDictionary <string, Model.DecisionProjectObjGJ> ts, Model.DetectRecordObjGJ detectRecordObj, DataTable dtUnitAreaConfig, DataTable dtDefectsData, int intImpID, int intRecordID, int intTaskID, int intPlanID)
        {
            try
            {
                int    intDectsionProjectID = 0;
                int    intDurationTime      = 0;//偏差持续时间
                string str = "CALL P_TBL00_DETECT_EXCEPTION";
                //string strMain = "CALL P_TBL00_DETECT_EXCEPTION_MAIN";
                Model.DecisionProjectObjGJ obj = null;
                string strValue = string.Empty;
                //int intNewRecordID = 0, intDetectType = 0;

                //1、根据RecordID从record表 获得,detectdate、linecode,linedir、plan表中的type
                //2、select TaskID from record表 where 检测日期<:detectdate and linecode==  and linedir== and type==order by 检测日期 DESC
                //cmd.CommandText = "select id RecordID, detectType from (" +
                //                  " select r.id,linecode,linedir,p.type detectType from tbl00_detect_record r,tbl00_detect_plan p " +
                //                  " where linecode = '" + detectRecordObj.LineCode + "' and r.linedir = '" + detectRecordObj.LineDir + "' and " +
                //                  " r.detectdate < to_date('" + detectRecordObj.DetectDate.ToString("yyyy-MM-dd") + "','yyyy-MM-dd') " +
                //                  " and r.planid = " + detectRecordObj.PlanID + " order by detectdate desc) " +
                //                  "where rownum = 1";
                //this.myRed = cmd.ExecuteReader();
                //if (this.myRed.Read())
                //{
                //    intNewRecordID = int.Parse(this.myRed["RecordID"].ToString());
                //    intDetectType = int.Parse(this.myRed["detectType"].ToString());
                //}
                //if (!this.myRed.IsClosed) this.myRed.Close();
                string sYear  = detectRecordObj.iXunCi.Substring(0, 4);
                string sMonth = detectRecordObj.iXunCi.Substring(4, 2);
                string sCi    = detectRecordObj.iXunCi.Substring(7, 1);
                foreach (DataRow row in dtDefectsData.Rows)
                {
                    #region 内部循环遍历
                    float  fMile          = 0F;
                    int    intRepeateTime = 0;//1重复;0未重复
                    int    intDefectClass = int.Parse(row["defectclass"].ToString());
                    string strDefectType  = row["defecttype"].ToString();
                    if (ts.TryGetValue(strDefectType, out obj))
                    {
                        intDectsionProjectID = obj.ProjectID;
                    }
                    else
                    {
                        intDectsionProjectID = 0;
                        continue;
                    }

                    float maxM = float.Parse(row["MAXMINOR"].ToString()) / 1000;
                    fMile = float.Parse(row["MAXPOST"].ToString()) + maxM;

                    float fFromPost  = string.IsNullOrEmpty(row["frompost"].ToString()) ? 0F : float.Parse(row["frompost"].ToString());
                    float fFromMinor = string.IsNullOrEmpty(row["fromminor"].ToString()) ? 0F : float.Parse(row["fromminor"].ToString());
                    float fToPost    = string.IsNullOrEmpty(row["topost"].ToString()) ? 0F : float.Parse(row["topost"].ToString());
                    float fToMinor   = string.IsNullOrEmpty(row["tominor"].ToString()) ? 0F : float.Parse(row["tominor"].ToString());

                    //if (intDefectClass >= 2)
                    //{
                    //    if (intNewRecordID != 0)
                    //        intRepeateTime = SpExeFor(cmd, intNewRecordID, intDectsionProjectID, intDefectClass, detectRecordObj.LineCode, detectRecordObj.LineDir,
                    //            detectRecordObj.DetectDate.ToString("yyyy-MM-dd"), intDetectType, fMile);
                    //}

                    //IMPID,RECORDID,TASKID,PLANID,DETECTTYPE,LINEID,LINEDIRECTION,DETECT_DATE,MAX_KM,MAX_M,EXCEPTIONITEMID,EXCEPTION_LEVEL,START_KM,START_M,END_KM,END_M,DURATION_TIME,DURATION_DISTANCE,
                    //EXCEPTION_VALUE,SPEEDSECTION,DETECTTRAINID,SPEED,TRACKLINETYPE,SEVERITY,TBCE,valid,DECISIONPROJECTID,REPEATTIME)
                    strValue = "(" + intImpID + "," + intRecordID + "," + intTaskID + "," + intPlanID + ",'" +
                               detectRecordObj.DetectType + "','" + detectRecordObj.LineCode + "','" + detectRecordObj.LineDir + "'," +
                               "'" + detectRecordObj.DetectDate.ToString("yyyy-MM-dd") + "'," + row["MAXPOST"] + "," + row["MAXMINOR"] + "," +
                               intDectsionProjectID + "," + row["defectclass"] + "," + fFromPost + "," + fFromMinor + "," +
                               fToPost + "," + fToMinor + "," + intDurationTime + ",'" + row["LENGTH"] + "'," + row["MAXVAL1"] + "," + row["postedspd"] + ",'" +
                               detectRecordObj.DetectTrain + "'," + row["speedatmaxval"] + ",'" + detectRecordObj.LineType + "'," +
                               row["severity"] + ",'" + row["TBCE"] + "'," + intDectsionProjectID + "," + intRepeateTime + ",'" + sYear + "','" +
                               sMonth + "','" + sCi + "')";
                    //基础偏差
                    this.strOra     = str + strValue;
                    cmd.CommandText = this.strOra;;
                    cmd.ExecuteNonQuery();
                    #endregion
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message.ToString());
            }
        }
        /// <summary>
        /// IIC文件导入
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool IICDataImp(int id)
        {
            #region IIC文件导入
            DataTable dtReadIICFiles = new DataTable();
            DataSet   ds             = new DataSet();
            IDictionary <string, Model.DecisionProjectObjGJ> ts             = null;
            IDictionary <int, Model.DetectRecordObjGJ>       tsDetectRecord = null;
            DataTable dtUnitAreaConfig = new DataTable("UnitAreaConfig");
            DataTable dtSystemConfig   = new DataTable("SystemConfig");
            string    strOra           = "select * from tbl00_detect_data_manage t where completestatus = 1 and id=" + id;
            using (OracleConnection cn = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OraConnStringGJ"].ConnectionString))
            {
                try
                {
                    OracleDataAdapter dap = new OracleDataAdapter();
                    OracleCommand     cmd = new OracleCommand();
                    cmd.CommandType   = CommandType.Text;
                    cmd.CommandText   = strOra;
                    cmd.Connection    = cn;
                    dap.SelectCommand = cmd;
                    dap.Fill(ds);

                    strOra = "select id, unittypeid, unit_code, unit_name, line_code, line_id, line_dir, startmile, endmile, status from tbl00_dic_unit_areaconfig";
                    dap.SelectCommand.CommandText = strOra;
                    dap.Fill(dtUnitAreaConfig);

                    strOra = "select * from tbl00_system_config";
                    dap.SelectCommand.CommandText = strOra;
                    dap.Fill(dtSystemConfig);

                    strOra          = "select exceptionid,exceptioncn,exceptionitem,exceptionen from tbl01_dic_01exceptiontype where exceptionid<200";
                    cmd.CommandText = strOra;
                    cn.Open();
                    OracleDataReader red = cmd.ExecuteReader();
                    ts = new Dictionary <string, Model.DecisionProjectObjGJ>();
                    while (red.Read())
                    {
                        Model.DecisionProjectObjGJ obj = new Model.DecisionProjectObjGJ
                        {
                            ProjectID         = int.Parse(red["exceptionid"].ToString()),
                            MethodID          = int.Parse(red["exceptionid"].ToString()),
                            ProjectList       = red["exceptioncn"].ToString(),
                            ProjectDes        = red["exceptionitem"].ToString(),
                            ProjectSourceName = red["exceptionen"].ToString()
                        };
                        ts.Add(obj.ProjectSourceName, obj);
                    }
                    if (!red.IsClosed)
                    {
                        red.Close();
                    }

                    strOra = "select d.detecttrain,c.linetype,b.type detecttype,a.detectid, a.taskid, a.planid, a.detectdate, " +
                             "     a.lineid, a.linedirection, a.linename, a.rundirection, a.sys_train_id, '' as des,d.taskindex " +
                             "  from pw_run_record a,tbl00_detect_plan b,tbl01_dic_06iiclinecode c,tbl00_detect_task d " +
                             " where a.planid=b.id and a.lineid=c.linecode and a.taskid=d.id";
                    cmd.CommandText = strOra;
                    red             = cmd.ExecuteReader();
                    tsDetectRecord  = new Dictionary <int, Model.DetectRecordObjGJ>();
                    while (red.Read())
                    {
                        Model.DetectRecordObjGJ obj = new Model.DetectRecordObjGJ
                        {
                            DetectTrain = red["detecttrain"].ToString(),
                            LineType    = red["linetype"].ToString(),
                            DetectType  = red["detecttype"].ToString(),
                            ID          = int.Parse(red["detectid"].ToString()),
                            TaskID      = int.Parse(red["taskid"].ToString()),
                            PlanID      = int.Parse(red["planid"].ToString()),
                            DetectDate  = DateTime.Parse(red["detectdate"].ToString()),
                            LineName    = red["linename"].ToString(),
                            LineDir     = red["linedirection"].ToString(),
                            TrainDir    = red["rundirection"].ToString(),
                            LineCode    = red["lineid"].ToString(),
                            TrainNumber = red["sys_train_id"].ToString(),
                            Des         = red["des"].ToString(),
                            iXunCi      = red["taskindex"].ToString()
                        };
                        tsDetectRecord.Add(obj.ID, obj);
                    }
                    if (!red.IsClosed)
                    {
                        red.Close();
                    }
                }
                catch (Exception ex)
                {
                    string ss = ex.Message.ToString();
                }
                finally
                {
                    if (cn.State != ConnectionState.Closed)
                    {
                        cn.Close();
                    }
                    if (cn != null)
                    {
                        cn.Dispose();
                    }
                }
            }

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                try
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        string strIICPath     = row["DATAPATH"].ToString();
                        string strIICFileName = row["DATANAME"].ToString();
                        int    intDataID      = int.Parse(row["ID"].ToString());
                        int    intRecordID    = int.Parse(row["RECORDID"].ToString());
                        int    intTaskID      = int.Parse(row["TASKID"].ToString());
                        int    intPlanID      = int.Parse(row["PLANID"].ToString());

                        if (tsDetectRecord.ContainsKey(intRecordID))
                        {
                            Model.DetectRecordObjGJ obj = tsDetectRecord[intRecordID];
                            ReadIIC(ts, obj, dtUnitAreaConfig, dtSystemConfig, intDataID, intRecordID, intTaskID, intPlanID, strIICPath, strIICFileName, string.Empty);
                        }
                    }
                }
                catch
                {
                    return(false);
                }
            }
            return(true);

            #endregion
        }