private Dictionary <string, ListStatusByFac> BuildMonthObj(JArray Monthstatusjarr)
    {
        Dictionary <string, ListStatusByFac> MonthstatusObj = new Dictionary <string, ListStatusByFac>();

        foreach (JObject statusobj in Monthstatusjarr)
        {
            string           ObjFactory = statusobj["车间"].ToString();
            string           ObjTime    = statusobj["时间"].ToString();
            string           KeyStr     = ObjFactory + "|" + ObjTime;
            ListStatusbyRule newLStatu  = new ListStatusbyRule(statusobj["RuleId"].ToString(), ObjTime, ObjFactory, statusobj["项目"].ToString(), statusobj["规则类"].ToString(), float.Parse(((JValue)statusobj["阀值"]).Value.ToString()), (bool)(((JValue)statusobj["自动"]).Value));
            newLStatu.CollectionValue = float.Parse(((JValue)statusobj["采集值"]).Value.ToString());
            newLStatu.ListValue       = (bool)(((JValue)statusobj["挂牌"]).Value);
            if (MonthstatusObj.ContainsKey(KeyStr))              //有这个车间
            {
                MonthstatusObj[KeyStr].Factory_List_Status.Add(newLStatu);
            }
            else              //暂时没有这个车间
            {
                ListStatusByFac newfac = new ListStatusByFac(ObjFactory, ObjTime);
                newfac.Factory_List_Status.Add(newLStatu);
                MonthstatusObj.Add(KeyStr, newfac);
            }
        }
        return(MonthstatusObj);
    }
    public string CreateStatus()
    {
        string DBcommand;
        string source          = ConfigurationManager.ConnectionStrings["EPInfoSys"].ConnectionString.ToString();
        JArray Monthstatusjarr = JArray.Parse(this._MonthstatusStr);
        Dictionary <string, ListStatusByFac> MonthstatusObj = BuildMonthObj(Monthstatusjarr);
        string ListRulesStr = this.ReadRules();
        JArray LRulesObj    = JArray.Parse(ListRulesStr);

        foreach (JObject Ruleobj in LRulesObj)
        {
            //看Monthstatus有没有这个规则结果。如果有,那么更新则使用update语句,如果没有这个Id的规则结果,则使用insert语句
            string ObjFactory = Ruleobj["车间"].ToString();
            string ObjTime    = this._Time;
            string KeyStr     = ObjFactory + "|" + ObjTime;
            string Objid      = Ruleobj["RuleId"].ToString();
            int    hasrule;
            if (MonthstatusObj.ContainsKey(KeyStr))
            {
                hasrule = MonthstatusObj[KeyStr].Factory_List_Status.FindIndex(delegate(ListStatusbyRule sch) { return(sch.RuleId == Objid); });
            }
            else
            {
                hasrule = -1;
            }
            //不管有没有这个规则,都需要先实例化由rule生成的规则结果类,以录入或覆盖原来的规则
            ListStatusbyRule newLStatu = new ListStatusbyRule(Ruleobj["RuleId"].ToString(), ObjTime, ObjFactory, Ruleobj["项目"].ToString(), Ruleobj["规则"].ToString(), float.Parse(((JValue)Ruleobj["阀值"]).Value.ToString()), true);
            newLStatu.GetCValueFromDB();
            newLStatu.ListValue = newLStatu.SetListValue();
            int ifauto;
            int lvalue;
            if (newLStatu.IfAuto)
            {
                ifauto = 1;
            }
            else
            {
                ifauto = 0;
            }
            if (newLStatu.ListValue)
            {
                lvalue = 1;
            }
            else
            {
                lvalue = 0;
            }
            if (hasrule == -1)                          //没有这个规则
            {
                if (MonthstatusObj.ContainsKey(KeyStr)) //有车间无规则,直接在车间里面加这个规则
                {
                    MonthstatusObj[KeyStr].Factory_List_Status.Add(newLStatu);
                }
                else                  //规则车间都没有
                {
                    ListStatusByFac newfac = new ListStatusByFac(ObjFactory, ObjTime);
                    newfac.Factory_List_Status.Add(newLStatu);
                    MonthstatusObj.Add(KeyStr, newfac);
                }
                DBcommand =
                    @"INSERT INTO [EPInfoSystem].[dbo].[ListStatus]
											   ([时间]
											   ,[车间]
											   ,[项目]
											   ,[RuleId]
											   ,[规则类]
											   ,[阀值]
											   ,[采集值]
											   ,[自动]
											   ,[挂牌])
										 VALUES
											   ('"                                             + this._Time + @"'
											   ,'"                                             + ObjFactory + @"'
											   ,'"                                             + newLStatu.Type + @"'
											   ,'"                                             + newLStatu.RuleId + @"'
											   ,'"                                             + newLStatu.RuleType + @"'
											   ,'"                                             + newLStatu.ThresHold + @"'
											   ,'"                                             + newLStatu.CollectionValue + @"'
											   ,"                                             + ifauto + @"
											   ,"                                             + lvalue + @"
												)"                                                ;
            }
            else              //有这个规则,修改Month类中的这个规则,然后使用update语句而不是insert
            {
                MonthstatusObj[KeyStr].Factory_List_Status[hasrule] = newLStatu;
                DBcommand = @"
								UPDATE [EPInfoSystem].[dbo].[ListStatus]
								   SET 
									   [车间] = '"                                     + ObjFactory + @"'
									  ,[项目] = '"                                     + newLStatu.Type + @"'									
									  ,[规则类] = '"                                     + newLStatu.RuleType + @"'
									  ,[阀值] = "                                     + newLStatu.ThresHold + @"
									  ,[采集值] ="                                     + newLStatu.CollectionValue + @"
									  ,[自动] = "                                     + ifauto + @"
									  ,[挂牌] = "                                     + lvalue + @"
								 WHERE [时间] ='"                                 + this._Time + "'AND [RuleId]=" + newLStatu.RuleId;
            }
            DBOper dbcom = new DBOper(source, DBcommand);
            string _ret  = dbcom.ReturnRows();
        }
        return(JsonConvertHelper.SerializeObject(MonthstatusObj));
    }