Ext MVC 增刪改 【公司用】
阿新 • • 發佈:2017-12-04
too msg country con urn comm public sql als
在上一篇博客的基礎上繼續寫
增
1 //1) Controller 2 public string Add()//add添加方法 3 { 4 Models.CCC item = JsonTool.JsonToObject<Models.CCC>(this.RequestParam()); 5 string Message = ""; 6 if (CCCBLL.Create.Add(item, out Message)) 7 { 8 return"{\"success\":true}"; 9 } 10 else 11 { 12 return "{\"success\":false,\"error\":\"添加失敗:" + Message.Replace("\"", "") + "\"}"; 13 } 14 } 15 16 //2) CCCDAL 17 public bool Add(Models.CCC item, out BaseClass.Message.MSG Message)18 { 19 string sql = "insert into CCC (Name,Number,Country,Configure,Price,Time,Note) values 20 21 (@Name,@Number,@Country,@Configure,@Price,@Time,@Note)"; 22 23 DBParameter[] param ={ 24 DBParameter.Create("Name",DbType.String,item.Name),25 DBParameter.Create("Number",DbType.String,item.Number), 26 DBParameter.Create("Country",DbType.String,item.Country), 27 DBParameter.Create("Configure",DbType.String,item.Configure), 28 DBParameter.Create("Price",DbType.String,item.Price), 29 DBParameter.Create("Time",DbType.String,item.Time), 30 DBParameter.Create("Note",DbType.String,item.Note) 31 }; 32 bool result = sop.ReturnExecuteCount(sql, false, param) > 0 ? true : false; 33 Message = sop.Parent.Parent.msg; 34 return result; 35 } 36 //3) CCCBLL 37 public bool Add(Models.CCC item, out string Message) 38 { 39 bool result = DAL.Add(item, out OpMessage); 40 Message = OpMessage.MessageError; 41 //日誌 42 AddSysLog(OpMessage, "車車車添加", "飛車"); 43 return result; 44 }
刪
1 //1) Controller 2 public string Delete()//刪除方法 3 { 4 Models.CCC item = JsonTool.JsonToObject<Models.CCC>(this.RequestParam()); 5 string Message = ""; 6 if (CCCBLL.Create.Delete(out Message, item.Ids.ToString())) 7 { 8 return "{\"success\":true}"; 9 } 10 else 11 { 12 return "{\"success\":false,\"error:\":\"刪除失敗:" + Message.Replace("\"", "") + "\"}"; 13 } 14 } 15 16 //2) CCCDAL 17 public bool Delete(out BaseClass.Message.MSG Message, params object[] PrimaryKey) 18 { 19 List<IDbCommand> mycmds = new List<IDbCommand>(); 20 string sql = ""; 21 foreach (object o in PrimaryKey) 22 { 23 sql = "delete CCC where Ids = @Ids"; 24 mycmds.Add(sop.ReturnCommand(sql, false, DBParameter.Create("Ids", DbType.Int32, o))); 25 } 26 bool result = sop.RunTrans(mycmds); 27 28 Message = sop.Parent.Parent.msg; 29 return result; 30 } 31 //3) CCCBLL 32 public bool Delete(out string Message, string Ids) 33 { 34 bool result = false; 35 //是否刪除 36 bool temp = false; 37 if (temp) 38 { 39 Message = "訂單{0}正在使用中,無法刪除"; 40 } 41 else 42 { 43 Ids = Ids.Replace(" ", ""); 44 result = DAL.Delete(out OpMessage, Ids.Split(‘,‘)); 45 Message = OpMessage.MessageError; 46 } 47 //日誌 48 AddSysLog(OpMessage, "車車車刪除", "飛車"); 49 return result; 50 }
改
1 //1) Controller 2 public string Edit()//修改方法 3 { 4 Models.CCC item = JsonTool.JsonToObject<Models.CCC>(this.RequestParam()); 5 string Message = ""; 6 7 if (CCCBLL.Create.Edit(item, out Message)) 8 { 9 return "{\"success\":true}"; 10 } 11 else 12 { 13 return "{\"success\":false,\"error\":\"編輯失敗:" + Message.Replace("\"", "") + "\"}"; 14 } 15 } 16 17 //2) CCCDAL 18 public bool Edit(Models.CCC item, out BaseClass.Message.MSG Message) 19 { 20 string sql = " update CCC set 21 22 Name=@Name,Number=@Number,Country=@Country,Configure=@Configure,Price=@Price,Time=@Time,Note=@Note where Ids=@Ids"; 23 DBParameter[] param ={ 24 DBParameter.Create("Ids",DbType.Int32,item.Ids), 25 DBParameter.Create("Name",DbType.String,item.Name), 26 DBParameter.Create("Number",DbType.String,item.Number), 27 DBParameter.Create("Country",DbType.String,item.Country), 28 DBParameter.Create("Configure",DbType.String,item.Configure), 29 DBParameter.Create("Price",DbType.String,item.Price), 30 DBParameter.Create("Time",DbType.String,item.Time), 31 DBParameter.Create("Note",DbType.String,item.Note) 32 }; 33 bool result = sop.ReturnExecuteCount(sql, false, param) > 0 ? true : false; 34 Message = sop.Parent.Parent.msg; 35 return result; 36 } 37 //3) CCCBLL 38 public bool Edit(Models.CCC item, out string Message) 39 { 40 bool result = DAL.Edit(item, out OpMessage); 41 Message = OpMessage.MessageError; 42 //日誌 43 AddSysLog(OpMessage, "車車車編輯", "飛車"); 44 return result; 45 }
Ext MVC 增刪改 【公司用】