//
        public HttpResponseMessage ItemSave(eqia_pdsavedata itemvalue)
        {
            string result = string.Empty;

            try
            {
                if (itemvalue.fldUserID == null || itemvalue.fldUserName == null)
                {
                    itemvalue.fldUserID   = rule.ConductUserinfo(itemvalue.fldUserID);
                    itemvalue.fldUserName = "";
                }
                if (itemvalue.BeginDate != null && itemvalue.EndDate != null)
                {
                    if (itemvalue.fldSTCode != null)
                    {
                        if (itemvalue.fldPCode != null)
                        {
                            if (itemvalue.fldType != null)
                            {
                                if (itemvalue.fldItemData.Count > 0)
                                {
                                    List <tblEQIA_PPI_BaseData_Pre> lstData = new List <tblEQIA_PPI_BaseData_Pre>();
                                    tblEQIA_PPI_BaseData_Pre        objData = new tblEQIA_PPI_BaseData_Pre();
                                    tblEQI_InputDate inputdate_new          = new tblEQI_InputDate();
                                    objData.fldType   = short.Parse(itemvalue.fldType);
                                    objData.fldSTCode = itemvalue.fldSTCode;
                                    objData.fldPCode  = itemvalue.fldPCode;

                                    objData.fldSYear   = inputdate_new.fldSYear = decimal.Parse(Convert.ToDateTime(itemvalue.BeginDate).Year.ToString());
                                    objData.fldSMonth  = inputdate_new.fldSMonth = decimal.Parse(Convert.ToDateTime(itemvalue.BeginDate).Month.ToString());
                                    objData.fldSDay    = inputdate_new.fldSDay = decimal.Parse(Convert.ToDateTime(itemvalue.BeginDate).Day.ToString());
                                    objData.fldSHour   = inputdate_new.fldSHour = decimal.Parse(Convert.ToDateTime(itemvalue.BeginDate).Hour.ToString());
                                    objData.fldSMinute = inputdate_new.fldSMinute = decimal.Parse(Convert.ToDateTime(itemvalue.BeginDate).Minute.ToString());
                                    objData.fldEYear   = inputdate_new.fldEYear = decimal.Parse(Convert.ToDateTime(itemvalue.EndDate).Year.ToString());
                                    objData.fldEMonth  = inputdate_new.fldEMonth = decimal.Parse(Convert.ToDateTime(itemvalue.EndDate).Month.ToString());
                                    objData.fldEDay    = inputdate_new.fldEDay = decimal.Parse(Convert.ToDateTime(itemvalue.EndDate).Day.ToString());
                                    objData.fldEHour   = inputdate_new.fldEHour = decimal.Parse(Convert.ToDateTime(itemvalue.EndDate).Hour.ToString());
                                    objData.fldEMinute = inputdate_new.fldEMinute = decimal.Parse(Convert.ToDateTime(itemvalue.EndDate).Minute.ToString());

                                    objData.fldUserID         = inputdate_new.fldUserID = int.Parse(itemvalue.fldUserID);
                                    objData.fldFlag           = 0;
                                    objData.fldCityID_Operate = inputdate_new.fldCityID = int.Parse(itemvalue.fldCityID_Operate);
                                    objData.fldCityID_Submit  = itemvalue.fldCityID_Submit;
                                    objData.fldDate_Operate   = DateTime.Now;
                                    inputdate_new.fldObject   = "eqia_p";

                                    Regex regexvalue2 = new Regex(@"^(\d*\.?\d+)?[lL]$");
                                    for (int i = 0; i < itemvalue.fldItemData.Count; i++)
                                    {
                                        decimal dValue = -1;
                                        if (itemvalue.fldItemData[i].itemvalue.Trim() != "")
                                        {
                                            if (regexvalue2.IsMatch(itemvalue.fldItemData[i].itemvalue.ToString().Trim()))
                                            {
                                                if (itemvalue.fldItemData[i].itemvalue.ToString().Trim().ToLower() == "l")
                                                {
                                                }
                                                else
                                                {
                                                    dValue = -Convert.ToDecimal(itemvalue.fldItemData[i].itemvalue.ToString().Trim().Replace("l", "").Replace("L", ""));
                                                }
                                                if (dValue == -1)
                                                {
                                                    dValue = Convert.ToDecimal(-0.99999999);
                                                }
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    dValue = Convert.ToDecimal(itemvalue.fldItemData[i].itemvalue.ToString().Trim());
                                                }
                                                catch (Exception e)
                                                {
                                                    result = rule.JsonStr("error", "监测值只能输入数字或字符L和l!", "");
                                                    return(new HttpResponseMessage {
                                                        Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
                                                    });
                                                }
                                            }
                                        }
                                        tblEQIA_PPI_BaseData_Pre objTmp = objData.Clone();
                                        objTmp.fldItemCode       = itemvalue.fldItemData[i].itemcode.ToString();
                                        objTmp.fldItemValue      = dValue;
                                        objTmp.fldCityID_Operate = Int32.Parse(itemvalue.fldCityID_Operate);
                                        objTmp.fldCityID_Submit  = itemvalue.fldCityID_Submit;
                                        lstData.Add(objTmp);
                                    }
                                    RuletblEQIA_PPI_Basedata_Pre rule_basedata = new RuletblEQIA_PPI_Basedata_Pre();
                                    bool issave = rule_basedata.InsertAll(lstData, inputdate_new);
                                    if (issave)
                                    {
                                        RuleWriteOperateLog rule_wol = new RuleWriteOperateLog();
                                        rule_wol.WriteLog(0, "录入降水数据到临时表,测点代码:" + itemvalue.fldPCode +
                                                          ";时间:" + itemvalue.BeginDate + " " + itemvalue.EndDate + ";录入者ID:" + int.Parse(itemvalue.fldUserID), itemvalue.fldUserName, int.Parse(itemvalue.fldUserID), int.Parse(itemvalue.fldCityID_Submit));
                                        result = rule.JsonStr("error", "录入成功!您保存的数据,已进入“待提交审核的数据”状态", "");
                                    }
                                    else
                                    {
                                        result = rule.JsonStr("error", "数据保存失败,请重试", "");
                                    }
                                }
                                else
                                {
                                    result = rule.JsonStr("error", "请提交因子监测值", "");
                                }
                            }
                            else
                            {
                                result = rule.JsonStr("error", "缺少降水类型", "");
                            }
                        }
                        else
                        {
                            result = rule.JsonStr("error", "缺少点位代码", "");
                        }
                    }
                    else
                    {
                        result = rule.JsonStr("error", "缺少城市代码", "");
                    }
                }
                else
                {
                    result = rule.JsonStr("error", "缺少监测时间", "");
                }
            }
            catch (InputException ex)
            {
                result = rule.JsonStr("error", "数据保存失败," + ex.Message, "");
            }
            catch (InsertException ex)
            {
                PageException pagex = new PageException(int.Parse(itemvalue.fldUserID), ex.Message,
                                                        "Eqia_pPointInputController", "ItemSave", "");
                result = rule.JsonStr("error", "数据写入数据库失败," + ex.Message, "");
            }
            catch (Exception ex)
            {
                PageException pagex = new PageException(int.Parse(itemvalue.fldUserID), ex.Message,
                                                        "Eqia_pPointInputController", "ItemSave", "");
                result = rule.JsonStr("error", "数据保存时出现了错误," + ex.Message, "");
            }
            return(new HttpResponseMessage {
                Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 功能描述:数据插入到临时表
        /// 创建  人:周文卿
        /// 创建时间:2017/07/12
        /// </summary>
        /// <param name="inputdata">插入的实体类</param>
        /// <returns>json(是否成功)</returns>
        public HttpResponseMessage ItemSave(List <tbleqia_p_table> inputdata)
        {
            string returntext = "";

            try
            {
                Regex regexvalue  = new Regex(@"^(\d*\.?\d+)+$");
                Regex regexvalue2 = new Regex(@"^(\d*\.?\d+)?[lL]$");
                List <tblEQIA_PPI_BaseData_Pre> lstData = new List <tblEQIA_PPI_BaseData_Pre>();
                tblEQIA_PPI_BaseData_Pre        objData = new tblEQIA_PPI_BaseData_Pre();
                for (int i = 0; i < inputdata.Count; i++)
                {
                    List <tbaeqia_p_value> valueall = inputdata[i].valueall;
                    for (int j = 0; j < valueall.Count; j++)
                    {
                        objData.fldSTCode         = valueall[j].fldSTCode;
                        objData.fldUserID         = int.Parse(inputdata[i].fldUserID);
                        objData.fldFlag           = 0;
                        objData.fldCityID_Operate = int.Parse(inputdata[i].fldCityID_Operate);
                        objData.fldCityID_Submit  = inputdata[i].fldCityID_Submit;
                        objData.fldDate_Operate   = DateTime.Now;
                        objData.fldType           = short.Parse(inputdata[i].fldType);
                        #region 因子值的修改
                        decimal dValue     = -1;
                        string  samphvalue = valueall[j].monitorvalue;
                        if (samphvalue != "")
                        {
                            if (regexvalue2.IsMatch(samphvalue))
                            {
                                if (samphvalue.ToLower() == "l")
                                {
                                    decimal temp = Convert.ToDecimal(valueall[j].monitorvalue);
                                    if (temp <= 0)
                                    {
                                        returntext = rule.JsonStr("error", "项目的检出限<=0,不能输入 L 作为监测值", "");
                                        return(new HttpResponseMessage {
                                            Content = new StringContent(returntext, System.Text.Encoding.UTF8, "application/json")
                                        });
                                    }
                                    dValue = -temp;
                                }
                                else
                                {
                                    dValue = -Convert.ToDecimal(samphvalue.Replace("l", "").Replace("L", ""));
                                }
                                if (dValue == -1)
                                {
                                    dValue = Convert.ToDecimal(-0.99999999);
                                }
                            }
                            else
                            {
                                dValue = Convert.ToDecimal(samphvalue);
                            }
                        }
                        #endregion
                        tblEQIA_PPI_BaseData_Pre objTmp = objData.Clone();
                        objTmp.fldPCode = valueall[j].fldPCode;
                        DateTime time = DateTime.Parse(valueall[j].fldDate.ToString());
                        objTmp.fldSYear     = time.Year;
                        objTmp.fldSMonth    = time.Month;
                        objTmp.fldSDay      = time.Day;
                        objTmp.fldSHour     = 0;
                        objTmp.fldSMinute   = 0;
                        objTmp.fldEYear     = time.Year;
                        objTmp.fldEMonth    = time.Month;
                        objTmp.fldEDay      = time.Day;
                        objTmp.fldEHour     = 0;
                        objTmp.fldEMinute   = 0;
                        objTmp.fldItemCode  = inputdata[i].itemcode;
                        objTmp.fldItemValue = dValue;
                        lstData.Add(objTmp);
                    }
                }
                RuletblEQIA_PPI_Basedata_Pre rule_basedata = new RuletblEQIA_PPI_Basedata_Pre();
                bool issave = rule_basedata.InsertAll(lstData);
                if (issave)
                {
                    RuleWriteOperateLog rule_wol = new RuleWriteOperateLog();
                    rule_wol.WriteLog(0, "录入降水数据到临时表", "", int.Parse(inputdata[0].fldUserID), int.Parse(inputdata[0].fldCityID_Operate));
                    returntext = rule.JsonStr("ok", "录入成功!您保存的数据,已进入“待提交审核的数据”状态", "");
                }
                else
                {
                    returntext = rule.JsonStr("error", "保存数据失败!请重试!", "");
                }
            }
            catch (InputException ex)
            {
                returntext = rule.JsonStr("error", ex.Message, "");
            }
            catch (InsertException ex)
            {
                returntext = rule.JsonStr("error", ex.Message, "");
            }
            catch (Exception ex)
            {
                returntext = rule.JsonStr("error", ex.Message, "");
            }
            return(new HttpResponseMessage {
                Content = new StringContent(returntext, System.Text.Encoding.UTF8, "application/json")
            });
        }