public override BaseResult Add(dynamic entity) { #region 获取数据 Hashtable param = (Hashtable)entity; BaseResult br = new BaseResult(); Hashtable ht = new Hashtable(); List <Td_Hy_Czrule_1_ReqModel> list = (List <Td_Hy_Czrule_1_ReqModel>)param["list"]; string id_masteruser = param["id_masteruser"].ToString(); string id_user = param["id_user"].ToString(); string id_shop = param["id_shop"].ToString(); #endregion List <Td_Hy_Czrule_1> addList1 = new List <Td_Hy_Czrule_1>(); List <Td_Hy_Czrule_2> addList2 = new List <Td_Hy_Czrule_2>(); foreach (var item in list) { Td_Hy_Czrule_1 model = new Td_Hy_Czrule_1(); model.id_masteruser = id_masteruser; model.id = GetGuid; model.id_shop = id_shop; model.id_shop_cz = item.id_shop_cz; model.flag_cancel = (byte)Enums.FlagCancel.NoCancel; model.day_b = item.day_b; model.day_e = item.day_e; model.id_hyfl = item.id_hyfl; model.je_cz = item.je_cz; model.je_cz_zs = item.je_cz_zs; model.flag_delete = (byte)Enums.FlagDelete.NoDelete; model.bz = item.bz; model.id_create = id_user; model.rq_create = DateTime.Now; model.id_rule = ""; addList1.Add(model); int sort_id = 1; foreach (var item2 in item.czrule_2_list) { item2.id_masteruser = id_masteruser; item2.id = GetGuid; item2.id_bill = model.id; item2.sort_id = sort_id; item2.rq_create = model.rq_create; addList2.Add(item2); sort_id++; } } #region 新增数据 DAL.AddRange <Td_Hy_Czrule_1>(addList1); DAL.AddRange <Td_Hy_Czrule_2>(addList2); #endregion #region 执行存储过程并返回结果 foreach (var item in addList1) { ht.Clear(); ht.Add("proname", "p_czrule_sh"); ht.Add("errorid", "-1"); ht.Add("errormessage", "未知错误!"); ht.Add("id_bill", item.id); ht.Add("id_user", id_user); DAL.RunProcedure(ht); if (!ht.ContainsKey("errorid") || !ht.ContainsKey("errormessage")) { br.Success = false; br.Message.Add("过账失败,执行审核出现异常!"); throw new CySoftException(br); } if (!string.IsNullOrEmpty(ht["errorid"].ToString()) || !string.IsNullOrEmpty(ht["errormessage"].ToString())) { br.Success = false; br.Message.Add(ht["errormessage"].ToString()); throw new CySoftException(br); } } #endregion br.Message.Add(String.Format("操作成功!!")); br.Success = true; return(br); }
public override BaseResult Update(dynamic entity) { #region 获取数据 Hashtable param = (Hashtable)entity; BaseResult br = new BaseResult(); Hashtable ht = new Hashtable(); List <Td_Hy_Czrule_1_ReqModel> list = (List <Td_Hy_Czrule_1_ReqModel>)param["list"]; string id_masteruser = param["id_masteruser"].ToString(); string id_user = param["id_user"].ToString(); string id_shop = param["id_shop"].ToString(); #endregion #region 构建Model if (list.Count() != 1 || string.IsNullOrEmpty(list.FirstOrDefault().id)) { br.Success = false; br.Message.Add("参数不符合要求!"); throw new CySoftException(br); } var newModel = list.FirstOrDefault(); List <Td_Hy_Czrule_1> tdAddList1 = new List <Td_Hy_Czrule_1>(); List <Td_Hy_Czrule_2> tdAddList2 = new List <Td_Hy_Czrule_2>(); List <Tb_Hy_Czrule_Zssp> tbAddList2 = new List <Tb_Hy_Czrule_Zssp>(); ht.Clear(); ht.Add("id_masteruser", id_masteruser); ht.Add("id", list.FirstOrDefault().id); var head = DAL.GetItem <Tb_Hy_Czrule_Query>(typeof(Tb_Hy_Czrule), ht); if (head == null || string.IsNullOrEmpty(head.id)) { br.Success = false; br.Message.Add("未找到此规则信息!"); throw new CySoftException(br); } foreach (var item in list) { Td_Hy_Czrule_1 model = new Td_Hy_Czrule_1(); model.id_masteruser = id_masteruser; model.id = GetGuid; model.id_shop = head.id_shop; model.id_shop_cz = item.id_shop_cz; model.flag_cancel = (byte)Enums.FlagCancel.NoCancel; model.day_b = item.day_b; model.day_e = item.day_e; model.id_hyfl = item.id_hyfl; model.je_cz = item.je_cz; model.je_cz_zs = item.je_cz_zs; model.flag_delete = (byte)Enums.FlagDelete.NoDelete; model.bz = item.bz; model.id_create = id_user; model.rq_create = DateTime.Now; model.id_rule = head.id; tdAddList1.Add(model); int sort_id = 1; foreach (var item2 in item.czrule_2_list) { item2.id_masteruser = id_masteruser; item2.id = GetGuid; item2.id_bill = model.id; item2.sort_id = sort_id; item2.rq_create = model.rq_create; tdAddList2.Add(item2); sort_id++; } } foreach (var item in tdAddList2) { Tb_Hy_Czrule_Zssp zsspModel = new Tb_Hy_Czrule_Zssp(); zsspModel.id_masteruser = head.id_masteruser; zsspModel.id = GetGuid; zsspModel.id_bill = head.id_bill; zsspModel.id_sp = item.id_sp; zsspModel.sl = item.sl; zsspModel.id_create = head.id_create; zsspModel.rq_create = head.rq_create; zsspModel.flag_delete = head.flag_delete; tbAddList2.Add(zsspModel); } #endregion #region 操作数据库 ht.Clear(); ht.Add("id", head.id); ht.Add("new_id_shop", newModel.id_shop_cz); ht.Add("new_day_b", newModel.day_b); ht.Add("new_day_e", newModel.day_e); ht.Add("new_id_hyfl", newModel.id_hyfl); ht.Add("new_je_cz", newModel.je_cz); ht.Add("new_je_cz_zs", newModel.je_cz_zs); DAL.UpdatePart(typeof(Tb_Hy_Czrule), ht); ht.Clear(); ht.Add("id_bill", head.id_bill); ht.Add("id_masteruser", id_masteruser); DAL.Delete(typeof(Tb_Hy_Czrule_Zssp), ht); DAL.AddRange <Tb_Hy_Czrule_Zssp>(tbAddList2); DAL.AddRange <Td_Hy_Czrule_1>(tdAddList1); DAL.AddRange <Td_Hy_Czrule_2>(tdAddList2); #endregion br.Message.Add(String.Format("操作成功!!")); br.Success = true; return(br); }