/// <summary> /// 更新信息 /// </summary> public void SaveData() { var json = Request["data"]; var rows = (ArrayList)PluSoft.Utils.JSON.Decode(json); var bllAdminFlag = new AdminFlag(); Sys.Model.AdminFlag model; foreach (Hashtable row in rows) { var id = row["ID"] != null ? row["ID"].ToString() : ""; //根据记录状态,进行不同的增加、删除、修改操作 var state = row["_state"] != null ? row["_state"].ToString() : ""; if (state == "added" || id == "") //新增:id为空,或_state为added { model = new Sys.Model.AdminFlag(); model.AppUrl = row["AppUrl"] == null ? "" : row["AppUrl"].ToString(); model.CreateTime = DateTime.Now; model.Flag = row["Flag"] == null ? "" : row["Flag"].ToString(); model.FlagAction = row["FlagAction"] == null ? "" : row["FlagAction"].ToString(); model.FlagGroup = Utils.StrToInt(row["FlagGroup"], 0); model.FlagName = row["FlagName"] == null ? "" : row["FlagName"].ToString(); model.FlagType = Utils.StrToInt(row["FlagType"], 0); model.HaveChildNav = Utils.StrToInt(row["HaveChildNav"], 0) == 1 ? true : false; model.Icon = ""; model.IsNav = Utils.StrToInt(row["IsNav"], 0); model.IsOpen = Utils.StrToInt(row["IsOpen"], 0) == 1 ? true : false; model.OrderID = bllAdminFlag.GetMaxId(); model.ParentID = Utils.StrToInt(row["ParentID"], 0); bllAdminFlag.Add(model); } else if (state == "modified" || state == "") //更新:_state为空或modified { model = bllAdminFlag.GetModel(Utils.StrToInt(row["ID"], 0)); if (model != null) { model.AppUrl = row["AppUrl"] == null ? "" : row["AppUrl"].ToString(); model.Flag = row["Flag"] == null ? "" : row["Flag"].ToString(); model.FlagAction = row["FlagAction"] == null ? "" : row["FlagAction"].ToString(); model.FlagGroup = Utils.StrToInt(row["FlagGroup"], 0); model.FlagName = row["FlagName"] == null ? "" : row["FlagName"].ToString(); model.FlagType = Utils.StrToInt(row["FlagType"], 0); model.HaveChildNav = Utils.StrToInt(row["HaveChildNav"], 0) == 1 ? true : false; model.Icon = ""; model.IsNav = Utils.StrToInt(row["IsNav"], 0); model.IsOpen = Utils.StrToInt(row["IsOpen"], 0) == 1 ? true : false; model.OrderID = bllAdminFlag.GetMaxId(); model.ParentID = Utils.StrToInt(row["ParentID"], 0); bllAdminFlag.Update(model); } } } }
/// <summary> /// 获得数据列表 /// </summary> public List <Sys.Model.AdminFlag> DataTableToList(DataTable dt) { var modelList = new List <Model.AdminFlag>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.AdminFlag model; for (int n = 0; n < rowsCount; n++) { model = new Sys.Model.AdminFlag(); if (dt.Rows[n]["ID"].ToString() != "") { model.ID = int.Parse(dt.Rows[n]["ID"].ToString()); } if (dt.Rows[n]["ParentID"].ToString() != "") { model.ParentID = int.Parse(dt.Rows[n]["ParentID"].ToString()); } model.Flag = dt.Rows[n]["Flag"].ToString(); model.FlagName = dt.Rows[n]["FlagName"].ToString(); model.FlagAction = dt.Rows[n]["FlagAction"].ToString(); if (dt.Rows[n]["FlagType"].ToString() != "") { model.FlagType = int.Parse(dt.Rows[n]["FlagType"].ToString()); } if (dt.Rows[n]["IsNav"].ToString() != "") { model.IsNav = int.Parse(dt.Rows[n]["IsNav"].ToString()); } model.AppUrl = dt.Rows[n]["AppUrl"].ToString(); model.Icon = dt.Rows[n]["Icon"].ToString(); if (dt.Rows[n]["OrderID"].ToString() != "") { model.OrderID = int.Parse(dt.Rows[n]["OrderID"].ToString()); } if (dt.Rows[n]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(dt.Rows[n]["CreateTime"].ToString()); } if (dt.Rows[n]["IsOpen"].ToString() != "") { if ((dt.Rows[n]["IsOpen"].ToString() == "1") || (dt.Rows[n]["IsOpen"].ToString().ToLower() == "true")) { model.IsOpen = true; } else { model.IsOpen = false; } } if (dt.Rows[n]["HaveChildNav"].ToString() != "") { if ((dt.Rows[n]["HaveChildNav"].ToString() == "1") || (dt.Rows[n]["HaveChildNav"].ToString().ToLower() == "true")) { model.HaveChildNav = true; } else { model.HaveChildNav = false; } } modelList.Add(model); } } return(modelList); }