public bool ReadFileToDatabase(FixedAssetInfoModel model, List <FixedAssetInfoModel> list) { try { int result = 0; // string sqlMain = string.Format(@" INSERT INTO [QMA1001] ([FAC],[DIV],[LOTNO],[MCHID],[MATYPE],[ITNBR],[ITDSC],[LOGINNAM],[ENAM],[SHIFT],[WDATE],[CRTIM],[RESULT],RESERVE1) //SELECT TOP 1 '{7}' AS [FAC] ,'{1}' AS [DIV] ,[LOTID] ,[AUMCH] ,DIV AS [MATYPE] ,[AITNBR] ,[AITDSC] ,'{2}' AS [LOGINNAM] ,'{3}' AS [ENAM] ,'{4}' AS [SHIFT] ,'{5}' AS [WDATE],GETDATE() ,'{6}' AS [RESULT],[VERSION] FROM LTC0001(NOLOCK) WHERE [LOTID] = '{0}';SELECT @@IDENTITY;", model.LOTNO, model.DIV, model.LOGINNAM, model.ENAM, model.SHIFT, model.WDATE, model.RESULT, model.FAC); // int id = Convert.ToInt32(db.ExecuteScalar(sqlMain)); // for (int i = 0; i < list.Count; i++) // { // FixedAssetInfoModel publicEntity = list[i] as FixedAssetInfoModel; // string sql = string.Format(@" INSERT INTO [QMA1002] ([QAID],[ITEMCODE],[LVALUE],[RVALUE],[LOK],[ROK])VALUES //({0},{3} ,'{1}' ,'{2}','{4}','{5}')", id, publicEntity.Value, publicEntity.Result, publicEntity.Id, publicEntity.Remark, publicEntity.Img); // result += db.ExecuteNonQuery(sql); // } return(result > 0); } catch { throw; } }
/// <summary> /// 解析字符串转换list /// </summary> /// <param name="jsList"></param> /// <returns></returns> //public List<PublicEntity> StringToModel(string strList) //{ // try // { // List<PublicEntity> list = new List<PublicEntity>(); // JArray ja = (JArray)JsonConvert.DeserializeObject(strList); // PublicEntity model; // foreach (JObject item in ja) // { // model = new PublicEntity(); // model.Id = item["Id"].ToString().Replace("\"", "").Trim(); // model.Value = item["Value"].ToString().Replace("\"", "").Trim(); // model.Result = item["Result"].ToString().Replace("\"", "").Trim(); // model.Remark = item["Remark"].ToString().Replace("\"", "").Trim(); // model.Img = item["Img"].ToString().Replace("\"", "").Trim(); // list.Add(model); // } // return list; // } // catch { throw; } //} public List <FixedAssetInfoModel> StringToModel(string strList) { try { List <FixedAssetInfoModel> list = new List <FixedAssetInfoModel>(); JArray ja = (JArray)JsonConvert.DeserializeObject(strList); FixedAssetInfoModel model; foreach (JObject item in ja) { model = new FixedAssetInfoModel(); model.Barcode = item["Barcode"].ToString().Replace("\"", "").Trim(); model.Assetcode = item["Assetcode"].ToString().Replace("\"", "").Trim(); model.Assetname = item["Assetname"].ToString().Replace("\"", "").Trim(); model.Kuaijileibie = item["Kuaijileibie"].ToString().Replace("\"", "").Trim(); model.Shebeileibie = item["Shebeileibie"].ToString().Replace("\"", "").Trim(); model.Guigexinghao = item["Guigexinghao"].ToString().Replace("\"", "").Trim(); model.Zichanzhuangtai = item["Zichanzhuangtai"].ToString().Replace("\"", "").Trim(); model.Cunfangdidian = item["Cunfangdidian"].ToString().Replace("\"", "").Trim(); model.Shiyongbumen = item["Shiyongbumen"].ToString().Replace("\"", "").Trim(); model.Guyuanbianhao = item["Guyuanbianhao"].ToString().Replace("\"", "").Trim(); model.Zichanshibeima = item["Zichanshibeima"].ToString().Replace("\"", "").Trim(); model.Beizhu = item["Beizhu"].ToString().Replace("\"", "").Trim(); model.Xuliehao = item["Xuliehao"].ToString().Replace("\"", "").Trim(); model.Supplier = item["Supplier"].ToString().Replace("\"", "").Trim(); model.Admindept = item["Admindept"].ToString().Replace("\"", "").Trim(); model.Assetclassify = item["Assetclassify"].ToString().Replace("\"", "").Trim(); model.Jdeupdatedate = item["Jdeupdatedate"].ToString().Replace("\"", "").Trim(); model.Jdeupdatetime = item["Jdeupdatetime"].ToString().Replace("\"", "").Trim(); model.Dataflag = item["Dataflag"].ToString().Replace("\"", "").Trim(); model.Flag = item["Flag"].ToString().Replace("\"", "").Trim(); list.Add(model); } return(list); } catch { throw; } }
private string Upload(HttpContext context) { try { string jsList = context.Request["dataList"]; List <FixedAssetInfoModel> list = new ComUtilDal().StringToModel(jsList); FixedAssetInfoModel model = new FixedAssetInfoModel(); { //FAC = context.Request["FAC"], //DIV = context.Request["DIV"], //LOTNO = context.Request["BARCODE"], //ENAM = context.Request["ENAM"], //LOGINNAM = context.Request["LOGINNAM"], //RESULT = context.Request["RESULT"] }; //DataTable dtComUtil = new ComUtilDal().GetShift(); //model.WDATE = DateTime.Parse(dtComUtil.Rows[0]["WDATE"].ToString()); //model.SHIFT = dtComUtil.Rows[0]["SHT"].ToString(); if (dal.Upload(model, list)) { return(JsonHelper <Messaging <string> > .EntityToJson(new Messaging <string>("0", xml.ReadLandXml("0")))); } else { return(JsonHelper <Messaging <string> > .EntityToJson(new Messaging <string>("1", xml.ReadLandXml("1")))); } } catch (Exception ex) { SystemErrorPlug.ErrorRecord(ex.ToString()); return(JsonHelper <Messaging <string> > .EntityToJson(new Messaging <string>("500", ex.Message.ToString().Replace("\r\n", "")))); } }