protected void btnSave_Click(object sender, EventArgs e) { //实例化一个控件数据映射对象 ControlDataMap cdm = new ControlDataMap(); //收集数据到实体对象 CustomerContactInfo info = cdm.CollectDataToObject <CustomerContactInfo>( MyWebForm.GetIBControls(this.tbCustomerInfo.Controls) ); //调用业务类,保存数据 bool result = false; CustomerManageBIZ biz = new CustomerManageBIZ(); if (dbtCID.ReadOnly) { //这里规定主键对应的控件是只读状态,表示当前表单是修改状态,否则是新增状态 result = biz.UpdateContactInfo(info); } else { result = biz.AddContactInfo(info); dbtCID.ReadOnly = true; txtComeIn.Text = dbtCID.Text; } lblMsg.Text = result ? "保存成功!请进入本超市!(也可以继续修改你的个人信息)" : "保存失败"; }
protected void btnSave_Click(object sender, EventArgs e) { if (dbtSN.Text.Trim() == "") { lblMsg.Text = "没有条码号,请输入!"; return; } //实例化一个控件数据映射对象 ControlDataMap cdm = new ControlDataMap(); //收集数据到实体对象 GoodsBaseInfo info = cdm.CollectDataToObject <GoodsBaseInfo>( MyWebForm.GetIBControls(this.tbGoosBaseInfo.Controls) ); //调用业务类,保存数据 GoodsManageBIZ biz = new GoodsManageBIZ(); if (biz.SaveGoodsBaseInfo(info)) { lblMsg.Text = "保存成功!"; } else { lblMsg.Text = "保存失败."; } bindGrid(); }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { lblMsg.Text = "Selected id=" + GridView1.SelectedRow.Cells[1].Text; string sn = GridView1.SelectedRow.Cells[1].Text; //调用业务层方法获取实体 GoodsManageBIZ biz = new GoodsManageBIZ(); GoodsBaseInfo info = biz.GetGoodsBaseInfo(sn); //将实体与页面控件绑定 WebControlDataMap.FillDataFromEntityClass(info, MyWebForm.GetIBControls(this.tbGoosBaseInfo.Controls) ); }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { lblMsg.Text = "Selected id=" + GridView1.SelectedRow.Cells[1].Text; string customerId = GridView1.SelectedRow.Cells[1].Text; //调用业务层方法获取实体 CustomerManageBIZ biz = new CustomerManageBIZ(); CustomerContactInfo info = biz.GetCustomerContactInfo(customerId); //将实体与页面控件绑定 WebControlDataMap.FillDataFromEntityClass(info, MyWebForm.GetIBControls(this.tbCustomerInfo.Controls) ); //标记当前表单为编辑状态,主键控件不可编辑 dbtCID.ReadOnly = true; this.tbCustomerInfo.Visible = true; lblMsg.Text = "编辑客户联系信息后请保存!"; }
protected void btnSubmit_Click(object sender, EventArgs e) { this.dlMsg.CssClass = "label label-danger"; if (this.dtName.Text == "") { this.dlMsg.Text = "请输入姓名!"; return; } if (this.dtPhone.Text == "") { this.dlMsg.Text = "请输入电话!"; return; } if (this.dtPersonID.Text == "") { this.dlMsg.Text = "请输入身份ID!"; return; } else { //从页面收集数据到实体类 ContactInfo info = MyWebForm.DataMap.CollectDataToObject <ContactInfo>( MyWebForm.GetIBControls(this.Controls)); info.AtTime = DateTime.Now; //保存数据到数据库 ClassReunionRepository rep = new ClassReunionRepository(); //如果查询到名字和身份证号一致的数据,则修改,否则添加数据 var existsInfo = rep.UserQuery.GetObject( OQL.From(info) .Select() .Where(cmp => cmp.EqualValue(info.Name) & cmp.EqualValue(info.PersonID)) .END ); int count = 0; string optMsg = ""; if (existsInfo == null) { optMsg = "添加"; count = rep.Add <ContactInfo>(info); } else { optMsg = "修改"; info.CID = existsInfo.CID; //指定ID主键的值,才可以修改 count = rep.Update <ContactInfo>(info); } if (count > 0) { this.dlMsg.CssClass = "label label-info"; this.dlMsg.Text = optMsg + " 成功!"; //重新绑定数据 BindLIstData(); } else { this.dlMsg.CssClass = "label label-danger"; this.dlMsg.Text = optMsg + " 失败![数据库操作异常,详细信息请检查SQL日志]"; } } }