/// <summary> /// 获得数据列表 /// </summary> public List <Sys.Model.EquipmentModel> DataTableToList(DataTable dt) { List <Sys.Model.EquipmentModel> modelList = new List <Sys.Model.EquipmentModel>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Sys.Model.EquipmentModel model; for (int n = 0; n < rowsCount; n++) { model = new Sys.Model.EquipmentModel(); if (dt.Rows[n]["ModelId"] != null && dt.Rows[n]["ModelId"].ToString() != "") { model.ModelId = int.Parse(dt.Rows[n]["ModelId"].ToString()); } if (dt.Rows[n]["ModelName"] != null && dt.Rows[n]["ModelName"].ToString() != "") { model.ModelName = dt.Rows[n]["ModelName"].ToString(); } if (dt.Rows[n]["EqpType"] != null && dt.Rows[n]["EqpType"].ToString() != "") { model.EqpType = int.Parse(dt.Rows[n]["EqpType"].ToString()); } if (dt.Rows[n]["ParentModelId"] != null && dt.Rows[n]["ParentModelId"].ToString() != "") { model.ParentModelId = int.Parse(dt.Rows[n]["ParentModelId"].ToString()); } if (dt.Rows[n]["CreateUserId"] != null && dt.Rows[n]["CreateUserId"].ToString() != "") { model.CreateUserId = dt.Rows[n]["CreateUserId"].ToString(); } if (dt.Rows[n]["CreateDate"] != null && dt.Rows[n]["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(dt.Rows[n]["CreateDate"].ToString()); } if (dt.Rows[n]["ModifyUserId"] != null && dt.Rows[n]["ModifyUserId"].ToString() != "") { model.ModifyUserId = dt.Rows[n]["ModifyUserId"].ToString(); } if (dt.Rows[n]["ModifyDate"] != null && dt.Rows[n]["ModifyDate"].ToString() != "") { model.ModifyDate = DateTime.Parse(dt.Rows[n]["ModifyDate"].ToString()); } if (dt.Rows[n]["Status"] != null && dt.Rows[n]["Status"].ToString() != "") { model.Status = dt.Rows[n]["Status"].ToString(); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 更新信息 /// </summary> public void SaveData() { var json = Request["data"]; UtilLog.WriteTextLog("Eqp Model Add", json); var rows = (ArrayList)PluSoft.Utils.JSON.Decode(json); var bllEquipmentModel = new EquipmentModel(); Sys.Model.EquipmentModel model; foreach (Hashtable row in rows) { var id = row["ModelId"] != null ? row["ModelId"].ToString() : ""; //根据记录状态,进行不同的增加、删除、修改操作 var state = row["_state"] != null ? row["_state"].ToString() : ""; if (state == "added" || id == "") //新增:id为空,或_state为added { model = new Sys.Model.EquipmentModel(); model.ModelName = row["ModelName"].ToString(); if (!string.IsNullOrEmpty(row["EqpType"].ToString())) { model.EqpType = Convert.ToInt32(row["EqpType"]); } model.ParentModelId = Utils.StrToInt(row["ParentModelId"], 0); model.Status = "1"; model.CreateDate = DateTime.Now; bllEquipmentModel.Add(model); } else if (state == "modified" || state == "") //更新:_state为空或modified { model = bllEquipmentModel.GetModel(Utils.StrToInt(row["ModelId"], 0)); if (model != null) { model.ModelName = row["ModelName"].ToString(); if (!string.IsNullOrEmpty(row["EqpType"].ToString())) { model.EqpType = Convert.ToInt32(row["EqpType"]); } else { model.EqpType = null; } model.ParentModelId = Utils.StrToInt(row["ParentModelId"], 0); model.ModifyDate = DateTime.Now; bllEquipmentModel.Update(model); } } } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Sys.Model.EquipmentModel model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Sys.Model.EquipmentModel model) { return(dal.Add(model)); }