/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.customerBank model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("update MS_customerBank set "); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("cb_id")) { //判断属性值是否为空 if (pi.GetValue(model, null) != null) { str1.Append(pi.Name + "=@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(" where cb_id=@id "); paras.Add(new SqlParameter("@id", model.cb_id)); return(DbHelperSQL.ExecuteSql(strSql.ToString(), paras.ToArray()) > 0); }
private string DoEdit(int _id) { BLL.customerBank bll = new BLL.customerBank(); Model.customerBank model = bll.GetModel(_id); string _content = string.Empty; if (model.cb_bankName != txtBankName.Text.Trim()) { _content += "银行账户名称:" + model.cb_bankName + "→<font color='red'>" + txtBankName.Text.Trim() + "</font><br/>"; } model.cb_bankName = txtBankName.Text.Trim(); if (model.cb_bankNum != txtBankNum.Text.Trim()) { _content += "客户银行账号:" + model.cb_bankNum + "→<font color='red'>" + txtBankNum.Text.Trim() + "</font><br/>"; } model.cb_bankNum = txtBankNum.Text.Trim(); if (model.cb_bank != txtBank.Text.Trim()) { _content += "开户行:" + model.cb_bank + "→<font color='red'>" + txtBank.Text.Trim() + "</font><br/>"; } model.cb_bank = txtBank.Text.Trim(); if (model.cb_bankAddress != txtBankAddress.Text.Trim()) { _content += "开户地址:" + model.cb_bankAddress + "→<font color='red'>" + txtBankAddress.Text.Trim() + "</font><br/>"; } model.cb_bankAddress = txtBankAddress.Text.Trim(); if (model.cb_flag != cbIsUse.Checked) { _content += "状态:" + (model.cb_flag.Value ? "启用" : "禁用") + "→<font color='red'>" + (cbIsUse.Checked ? "启用" : "禁用") + "</font><br/>"; } model.cb_flag = cbIsUse.Checked; return(bll.Update(model, _content, manager)); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.customerBank GetModel(int id) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); Model.customerBank model = new Model.customerBank(); //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); foreach (PropertyInfo p in pros) { str1.Append(p.Name + ",");//拼接字段 } strSql.Append("select top 1 " + str1.ToString().Trim(',')); strSql.Append(" from MS_customerBank"); strSql.Append(" where cb_id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0]; if (dt.Rows.Count > 0) { return(DataRowToModel(dt.Rows[0])); } else { return(null); } }
private string DoAdd() { Model.customerBank model = new Model.customerBank(); BLL.customerBank bll = new BLL.customerBank(); model.cb_cid = cid; model.cb_bankName = txtBankName.Text.Trim(); model.cb_bankNum = txtBankNum.Text.Trim(); model.cb_bank = txtBank.Text.Trim(); model.cb_bankAddress = txtBankAddress.Text.Trim(); model.cb_flag = cbIsUse.Checked; return(bll.Add(model, manager)); }
/// <summary> /// 更新一条数据 /// </summary> public string Update(Model.customerBank model, string content, Model.manager manager) { if (string.IsNullOrEmpty(model.cb_bankName)) { return("请填写银行账户名称"); } if (string.IsNullOrEmpty(model.cb_bankNum)) { return("请填写客户银行账号"); } if (Exists(model.cb_bankNum, model.cb_cid.Value, model.cb_id.Value)) { return("该银行账号已存在"); } if (string.IsNullOrEmpty(model.cb_bank)) { return("请填写开户行"); } if (string.IsNullOrEmpty(model.cb_bankAddress)) { return("请填写开户地址"); } Model.Customer cu = new BLL.Customer().GetModel(model.cb_cid.Value); if (cu == null) { return("客户不存在"); } if (cu.c_flag == 2) { return("客户已经审批通过,不能编辑联系人"); } if (cu.c_owner != manager.user_name && cu.c_ownerName != manager.real_name) { if (!new BLL.permission().checkHasPermission(manager, "0301")) { return("不是客户所属人或无权限修改客户信息"); } } if (dal.Update(model)) { Model.business_log log = new Model.business_log(); log.ol_cid = model.cb_cid.Value; log.ol_relateID = model.cb_id.Value; log.ol_title = "编辑客户银行账号"; log.ol_content = content; log.ol_operateDate = DateTime.Now; log.ol_operaterNum = manager.user_name; log.ol_operaterName = manager.real_name; new business_log().Add(DTEnums.ActionEnum.Edit.ToString(), log, manager.user_name, manager.real_name); return(""); } return("更新失败"); }
/// <summary> /// 增加一条数据 /// </summary> public string Add(Model.customerBank model, Model.manager manager) { if (model.cb_cid == 0) { return("请选择客户"); } if (string.IsNullOrEmpty(model.cb_bankName)) { return("请填写银行账户名称"); } if (string.IsNullOrEmpty(model.cb_bankNum)) { return("请填写客户银行账号"); } if (Exists(model.cb_bankNum, model.cb_cid.Value)) { return("该银行账号已存在"); } if (string.IsNullOrEmpty(model.cb_bank)) { return("请填写开户行"); } if (string.IsNullOrEmpty(model.cb_bankAddress)) { return("请填写开户地址"); } int ret = dal.Add(model); if (ret > 0) { Model.business_log log = new Model.business_log(); log.ol_cid = model.cb_cid.Value; log.ol_relateID = ret; log.ol_title = "添加客户银行账号"; log.ol_content = "银行账户名称:" + model.cb_bankName + "<br/>客户银行账号:" + model.cb_bankNum + "<br/>开户行:" + model.cb_bank + "<br/>开户地址:" + model.cb_bankAddress + "<br/>状态:" + (model.cb_flag.Value ? "启用" : "禁用"); log.ol_operateDate = DateTime.Now; log.ol_operaterNum = manager.user_name; log.ol_operaterName = manager.real_name; new business_log().Add(DTEnums.ActionEnum.Add.ToString(), log, manager.user_name, manager.real_name); return(""); } return("添加失败"); }
/// <summary> /// 将对象转换实体 /// </summary> public Model.customerBank DataRowToModel(DataRow row) { Model.customerBank model = new Model.customerBank(); if (row != null) { //利用反射获得属性的所有公共属性 Type modelType = model.GetType(); for (int i = 0; i < row.Table.Columns.Count; i++) { //查找实体是否存在列表相同的公共属性 PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName); if (proInfo != null && row[i] != DBNull.Value) { proInfo.SetValue(model, row[i], null);//用索引值设置属性值 } } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.customerBank model) { StringBuilder strSql = new StringBuilder(); StringBuilder str1 = new StringBuilder(); //数据字段 StringBuilder str2 = new StringBuilder(); //数据参数 //利用反射获得属性的所有公共属性 PropertyInfo[] pros = model.GetType().GetProperties(); List <SqlParameter> paras = new List <SqlParameter>(); strSql.Append("insert into MS_customerBank("); foreach (PropertyInfo pi in pros) { //如果不是主键则追加sql字符串 if (!pi.Name.Equals("cb_id")) { //判断属性值是否为空 if (pi.GetValue(model, null) != null) { str1.Append(pi.Name + ","); //拼接字段 str2.Append("@" + pi.Name + ","); //声明参数 paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值 } } } strSql.Append(str1.ToString().Trim(',')); strSql.Append(") values ("); strSql.Append(str2.ToString().Trim(',')); strSql.Append(") "); strSql.Append(";select @@IDENTITY;"); object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 删除一条数据 /// </summary> public string Delete(int id, Model.manager manager) { Model.customerBank na = GetModel(id); if (na == null) { return("数据不存在"); } //if (isUse(id)) //{ // return "已被使用,不能删除"; //} Model.Customer cu = new BLL.Customer().GetModel(na.cb_cid.Value); if (cu == null) { return("客户不存在"); } if (cu.c_flag == 2) { return("客户已经审批通过,不能删除客户银行账号"); } if (cu.c_owner != manager.user_name && cu.c_ownerName != manager.real_name) { if (!new BLL.permission().checkHasPermission(manager, "0301")) { return("不是客户所属人或无权限修改客户信息,不能删除客户银行账号"); } } if (dal.Delete(id)) { Model.business_log logmodel = new Model.business_log(); logmodel.ol_relateID = id; logmodel.ol_title = "删除客户银行账号"; logmodel.ol_content = "客户ID:" + na.cb_cid + "<br/>银行账户名称:" + na.cb_bankName + "<br/>客户银行账号:" + na.cb_bankNum + ""; logmodel.ol_operateDate = DateTime.Now; new business_log().Add(DTEnums.ActionEnum.Delete.ToString(), logmodel, manager.user_name, manager.real_name); return(""); } return("删除失败"); }