public void Add(T entity) { table.Add(entity); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
private int add(IEntity entity) { if (GetType(entity) == "Student") { ctx.Students.Add((Student)entity); return(ctx.SaveChanges()); } else if (GetType(entity) == "Lecturer") { ctx.Lecturers.Add((Lecturer)entity); return(ctx.SaveChanges()); } else if (GetType(entity) == "Course") { ctx.Courses.Add((Course)entity); return(ctx.SaveChanges()); } else if (GetType(entity) == "Attendance") { ctx.Attendances.Add((Attendance)entity); return(ctx.SaveChanges()); } else if (GetType(entity) == "StdAttendance") { ctx.StdAttendances.Add((StdAttendance)entity); return(ctx.SaveChanges()); } else { return(0); } }
public virtual T Create <T>(T TObject) where T : class { var newEntry = dbContext.Set <T>().Add(TObject); dbContext.SaveChanges(); return(newEntry); }
public ActionResult Edit(Company company) { if (ModelState.IsValid) { db.Companies.Attach(company); // db.ObjectStateManager.ChangeObjectState(company, EntityState.Modified); // TODO: BLL code db.SaveChanges(); return(RedirectToAction("Index")); } return(View(company)); }
public ActionResult Create(EmployeeTask employeetask) { if (ModelState.IsValid) { db.EmployeeTasks.AddObject(employeetask); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", employeetask.EmployeeId); return(View(employeetask)); }
public ActionResult Create(Leave leave) { if (ModelState.IsValid) { db.Leaves.AddObject(leave); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", leave.EmployeeId); return(View(leave)); }
public static void Save(AMSEntities amsContext) { try { amsContext.SaveChanges(); } catch (OptimisticConcurrencyException) { throw new Exception("并发冲突,请重载数据"); } catch (UpdateException uex) { if (uex.InnerException == null) { throw new Exception("更新错误:" + uex.Message); } else { throw new Exception("更新错误:" + uex.InnerException.Message); } } catch (Exception ex) { ErrorLog.Write(ex); throw ex; } }
private void btnOK_Click(object sender, EventArgs e) { try { if (txtLimitCode.Text == "" || txtLimitName.Text == "") { throw new Exception("角色代码和名称都不能为空"); } if (!txtLimitCode.Text.StartsWith("OP")) { throw new Exception("角色代码需以OP开头"); } using (AMSEntities amsContext = new AMSEntities()) { int i = amsContext.tbLimit.Count(l => l.vcLimitCode == txtLimitCode.Text || l.vcLimitName == txtLimitName.Text); if (i > 0) { throw new Exception("相同角色代码或名称的角色已存在"); } tbLimit limit = new tbLimit(); limit.vcLimitCode = txtLimitCode.Text; limit.vcLimitName = txtLimitName.Text; amsContext.AddTotbLimit(limit); amsContext.SaveChanges(); this.Close(); } } catch (Exception ex) { ErrorLog.Write(this, ex); } }
private void btnDelete_Click(object sender, EventArgs e) { try { if (txtOperID.Text.Equals("admin")) { throw new Exception("系统管理员帐户不能注销"); } DialogResult dr = MessageBox.Show(this, "是否注销\"" + txtOperName.Text + "\"操作员", "注销操作员", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { using (AMSEntities amsContext = new AMSEntities()) { tbOper oper = amsContext.tbOper.FirstOrDefault(o => o.vcOperID == txtOperID.Text); //oper.vcLimit = cmbRole.SelectedValue.ToString(); //oper.vcOperName = txtOperName.Text; //oper.vcOperPwd = txtOperPwd.Text; //oper.vcOperLevel = cmbOperLevel.SelectedValue.ToString(); oper.iFlag = 1; oper.dtExpDate = DateTime.Now; amsContext.SaveChanges(); MessageBox.Show(this, "操作员注销成功", "注销操作员"); } //frmOper_Load(null, null); } } catch (Exception ex) { ErrorLog.Write(this, ex, "操作员"); } }
private void treeView2_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Tag.ToString().Length > 1 && treeView1.SelectedNode.Name != "limit") { tbOperLimit ol = new tbOperLimit(); ol.vcLimitCode = treeView1.SelectedNode.Name; ol.vcMenu1 = e.Node.Tag.ToString().Substring(0, 1); ol.vcMenu2 = e.Node.Tag.ToString().Substring(1, 1); using (AMSEntities amsContext = new AMSEntities()) { try { //amsContext.s tbOperLimit ol2 = amsContext.tbOperLimit.FirstOrDefault(l => l.vcLimitCode == ol.vcLimitCode && l.vcMenu1 == ol.vcMenu1 && l.vcMenu2 == ol.vcMenu2); if (e.Node.Checked) { if (ol2 == null) { amsContext.AddTotbOperLimit(ol); amsContext.SaveChanges(); } } else { if (ol2 != null) { amsContext.DeleteObject(ol2); amsContext.SaveChanges(); } } } catch (Exception ex) { ErrorLog.Write(this, ex); } } } }
protected void submit_Click(object sender, EventArgs e) { AMSEntities ae = new AMSEntities(); Company company = new Company(); company.CompanyName = this.cName.Text; company.CompanyAddress = this.cAddress.Text; company.CompanyPhone = this.cPhone.Text; company.CompanyStatus = true; ae.Companies.AddObject(company); ae.SaveChanges(); string url = "CreateUserAdmin.aspx" + "?companyID=" + company.CompanyID; Server.Transfer(url, true); }
protected void submit_Click(object sender, EventArgs e) { string uName = this.uName.Text; string uPass = Membership.GeneratePassword(12, 1); string uEmail = this.uEmail.Text; int companyID = Convert.ToInt32(Request.QueryString["companyID"]); AMSEntities ae = new AMSEntities(); using (TransactionScope t = new TransactionScope()) { /* Add to User .NET Membership */ //UserProfile + webpages_membership tables WebSecurity.CreateUserAndAccount(uName, uPass); /* Add User .NET Membership to User Admin Role */ Roles.AddUserToRole(uName, "User Admin"); /* Add to Users table */ User user = new User(); user.MembershipUserID = WebSecurity.GetUserId(uName); user.UserFirstName = this.fName.Text; user.UserLastName = this.lName.Text; user.UserEmail = uEmail; user.UserTitle = this.title.Text; user.UserDescription = this.description.Text; user.UserPhone = this.phone.Text; user.CompanyID = companyID; ae.Users.AddObject(user); ae.SaveChanges(); t.Complete(); } string subject = "Your Appointment Management System Account has been created"; string content = "Dear " + this.title.Text + " " + this.lName.Text + ","; content += "\n\n" + "Your username is \"" + uName + "\" and your system generated password is \"" + uPass + "\"."; content += "\n\n" + "Please change your password after logging in."; content += "\n\n" + "Regards,\n" + "The AMS Team"; Emailer.Send(uEmail, subject, content); /* Redirect to new page */ Server.Transfer("ViewCompanies.aspx", true); }
protected void submit_Click(object sender, EventArgs e) { string uName = this.uName.Text; string uPass = Membership.GeneratePassword(12, 1); string uEmail = this.uEmail.Text; int companyID = Convert.ToInt32( Request.QueryString["companyID"] ); AMSEntities ae = new AMSEntities(); using (TransactionScope t = new TransactionScope()) { /* Add to User .NET Membership */ //UserProfile + webpages_membership tables WebSecurity.CreateUserAndAccount(uName, uPass); /* Add User .NET Membership to User Admin Role */ Roles.AddUserToRole(uName, "User Admin"); /* Add to Users table */ User user = new User(); user.MembershipUserID = WebSecurity.GetUserId(uName); user.UserFirstName = this.fName.Text; user.UserLastName = this.lName.Text; user.UserEmail = uEmail; user.UserTitle = this.title.Text; user.UserDescription = this.description.Text; user.UserPhone = this.phone.Text; user.CompanyID = companyID; ae.Users.AddObject(user); ae.SaveChanges(); t.Complete(); } string subject = "Your Appointment Management System Account has been created"; string content = "Dear " + this.title.Text + " " + this.lName.Text + ","; content += "\n\n" + "Your username is \"" + uName + "\" and your system generated password is \"" + uPass + "\"."; content += "\n\n" + "Please change your password after logging in."; content += "\n\n" + "Regards,\n" + "The AMS Team"; Emailer.Send(uEmail, subject, content); /* Redirect to new page */ Server.Transfer("ViewCompanies.aspx", true); }
private void btnOK_Click(object sender, EventArgs e) { try { if (txtOldPwd.Text.Trim().Length == 0) { throw new Exception("请输入老密码"); } if (txtPwd.Text.Trim().Length == 0) { throw new Exception("请输入新密码"); } if (txtPwdConfirm.Text.Trim().Length == 0) { throw new Exception("请输入新密码确认"); } if (!txtOldPwd.Text.Equals(GlobalParams.oper.vcOperPwd)) { throw new Exception("输入的老密码不正确"); } if (!txtPwd.Text.Equals(txtPwdConfirm.Text)) { throw new Exception("输入的新密码和新密码确认不一致"); } if (txtOldPwd.Text.Equals(txtPwd.Text)) { throw new Exception("输入的新密码和老密码一样"); } using (AMSEntities amsContext = new AMSEntities()) { //tbOper oper = GlobalParams.oper; GlobalParams.oper.vcOperPwd = txtPwd.Text; tbOper oper = amsContext.tbOper.FirstOrDefault(o => o.vcOperID == GlobalParams.oper.vcOperID); oper.vcOperPwd = txtPwd.Text; amsContext.SaveChanges(); MessageBox.Show(this, "密码修改成功", "修改密码"); } } catch (Exception ex) { ErrorLog.Write(this, ex, "修改密码"); } }
private void deleteRoleToolStripMenuItem_Click(object sender, EventArgs e) { //删除角色 try { TreeNode tn = treeView1.SelectedNode; if (tn.Name == "OP001") { throw new Exception("管理员权限为系统权限,不能删除!"); } DialogResult dr = MessageBox.Show(this, "是否删除\"" + tn.Text + "\"角色", "删除角色", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { using (AMSEntities amsContext = new AMSEntities()) { //tbLimit limit = new tbLimit(); //limit.vcLimitCode = tn.Name; //limit.vcLimitName = tn.Text; tbLimit limit = amsContext.tbLimit.FirstOrDefault(l => l.vcLimitCode == tn.Name); amsContext.DeleteObject(limit); var opers = amsContext.tbOperLimit.Where(ol => ol.vcLimitCode == tn.Name); foreach (tbOperLimit operLimit in opers) { amsContext.DeleteObject(operLimit); } amsContext.SaveChanges(); SetRole(amsContext); MessageBox.Show(this, "角色删除成功", "删除角色"); } } } catch (Exception ex) { ErrorLog.Write(this, ex); } }
private void btnExOk_Click(object sender, EventArgs e) { try { if (dgvIgEx.Rows.Count == 0) { throw new Exception("没有任何积分兑换记录,请重新输入!"); } string strBillNo = txtBillNo.Text.Trim(); if (strBillNo == "") { throw new Exception("请先打印回执!"); } int AssID = int.Parse(txtAssID.Text.Trim()); string strCardID = txtCardID.Text.Trim(); int IgSum = int.Parse(txtIgSum.Text.Trim()); bool continueflg = true; using (AMSEntities amsContext = new AMSEntities()) { tbAssociatorCard asscard1 = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.iAssID == AssID && ac.vcAssCardID == strCardID); while (continueflg) { frmInputBox inbox = new frmInputBox("请输入会员卡密码:", "PWD"); inbox.ShowDialog(); if (GlobalParams.strInputBoxMes == "Cancel") { GlobalParams.strInputBoxMes = ""; return; } else { if (GlobalParams.strInputBoxMes == "") { MessageBox.Show("会员卡密码不能为空,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (asscard1 == null) { MessageBox.Show("会员信息有误,请重试!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (GlobalParams.strInputBoxMes != asscard1.vcAssPwd) { MessageBox.Show("输入的会员卡密码错误,请重试!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { continueflg = false; } } } } tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == AssID && ig.vcAssCardID == strCardID); if (intg1 == null) { throw new Exception("获取会员卡积分错误,请重试!"); } if (intg1.iIgValue < IgSum) { throw new Exception("当前积分余额不足,请重新读卡后重试!"); } long billNo = long.Parse(strBillNo); tbBillInvoice bill1 = amsContext.tbBillInvoice.FirstOrDefault(bl => bl.iBillNo == billNo); if (bill1 == null) { throw new Exception("帐单不存在,请重试!"); } long igserialNo = 0; using (AMSEntities amscontext2 = new AMSEntities()) { tbIgSerialNo igserial1 = new tbIgSerialNo(); igserial1.vcFill = "0"; amscontext2.AddTotbIgSerialNo(igserial1); amscontext2.SaveChanges(); igserialNo = igserial1.iSerialNo; } DateTime dtoperdate = DateTime.Now; intg1.iIgValue = intg1.iIgValue - IgSum; ObjectStateEntry ose = amsContext.ObjectStateManager.GetObjectStateEntry(intg1); DataTable dtIgList = (DataTable)dgvIgEx.DataSource; int lastig = int.Parse(ose.OriginalValues["iIgValue"].ToString()); for (int i = 0; i < dtIgList.Rows.Count; i++) { tbIntegralLog intglog1 = new tbIntegralLog(); intglog1.iIgSerial = igserialNo; intglog1.iNo = i + 1; intglog1.iAssID = intg1.iAssID; intglog1.vcAssCardID = intg1.vcAssCardID; intglog1.iIgLast = lastig; intglog1.dtIgDate = dtoperdate; intglog1.vcIgName = dtIgList.Rows[i]["积分兑换项目"].ToString(); intglog1.vcIgType = "IG002"; intglog1.iIgGet = -(int.Parse(dtIgList.Rows[i]["兑换分值"].ToString())); intglog1.iIgArrival = lastig + intglog1.iIgGet; intglog1.iLinkCons = null; intglog1.vcOperID = GlobalParams.oper.vcOperID; intglog1.vcComments = dtIgList.Rows[i]["备注"].ToString(); amsContext.AddTotbIntegralLog(intglog1); lastig = (int)intglog1.iIgArrival; } bill1.vcLinkSerial = igserialNo; bill1.vcEffFlag = "1"; tbBusiLog busilog1 = new tbBusiLog(); busilog1.vcAssName = txtAssName.Text.Trim(); busilog1.vcAssCardID = intg1.vcAssCardID; busilog1.vcLinkSerial = igserialNo; busilog1.vcOperType = "OT013"; busilog1.vcOperID = GlobalParams.oper.vcOperID; busilog1.vcOperName = GlobalParams.oper.vcOperName; busilog1.dtOperDate = dtoperdate; busilog1.iAssID = intg1.iAssID; amsContext.AddTotbBusiLog(busilog1); amsContext.SaveChanges(); btnExOk.Enabled = false; btnPrint.Enabled = false; btnAdd.Enabled = false; btnDel.Enabled = false; btnRead.Enabled = true; txtIgSum.Text = "0"; txtBillNo.Text = ""; txtAssID.Text = ""; txtCardID.Text = ""; txtAssName.Text = ""; txtCurCharge.Text = ""; txtCurIg.Text = ""; DataTable dtIgExList = new DataTable(); dtIgExList.Columns.Add("积分兑换项目"); dtIgExList.Columns.Add("兑换分值"); dtIgExList.Columns.Add("备注"); dgvIgEx.DataSource = dtIgExList; MessageBox.Show("本次积分兑换成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { ErrorLog.Write(this, ex, "积分兑换异常"); } }
public ActionResult Update(FormCollection collection) { int id = Int32.Parse(Session["LogedUserId"].ToString()); var leaveRequests = db.LeaveRequests.Include(c => c.Employee).Where(c => c.Employee.ManagerId == id); foreach (LeaveRequest leaveRequest in leaveRequests) { string status = (string)collection.Get("status" + leaveRequest.Id); Console.WriteLine("Status" + status); System.Diagnostics.Debug.WriteLine("Status :" + status); if (status != null) { if (status.Equals("No")) { leaveRequest.Status = "Disapproved"; } else if (status.Equals("Yes")) { leaveRequest.Status = "Approved"; for (DateTime d = leaveRequest.FromDate; d <= leaveRequest.ToDate; d = d.AddDays(1)) { Attendance att = new Attendance(); att.EmployeeId = leaveRequest.Employee_Id; if (leaveRequest.TypeOfLeave.Contains("Sick")) { Leave leave = db.Leaves.Where(l => l.EmployeeId == att.EmployeeId).FirstOrDefault(); if (leave.SickLeaves > 0) { att.Status = "SickLeave"; } leave.SickLeaves--; } else if (leaveRequest.TypeOfLeave.Contains("casual")) { Leave leave = db.Leaves.Where(l => l.EmployeeId == att.EmployeeId).FirstOrDefault(); if (leave.CasualLeaves > 0) { att.Status = "CasualLeave"; } leave.CasualLeaves--; } else if (leaveRequest.TypeOfLeave.Contains("Optional")) { Leave leave = db.Leaves.Where(l => l.EmployeeId == att.EmployeeId).FirstOrDefault(); if (leave.CasualLeaves > 0) { att.Status = "OptionalLeave"; } leave.OptionalHolidays--; } else { att.Status = "Absent"; } att.Date = d; db.Attendances.AddObject(att); } } } //AMSEntities newCtx = new AMSEntities(); //newCtx.LeaveRequests.Attach(leaveRequest); //newCtx.ObjectStateManager.ChangeObjectState(leaveRequest, EntityState.Modified); } db.SaveChanges(); return(RedirectToAction("Index")); }
public bool insert(UserTable obj) { dbContext.UserTables.Add(obj); return(dbContext.SaveChanges() > 0); }
private void btnRollBack_Click(object sender, EventArgs e) { try { DialogResult dreocon = MessageBox.Show("请确定要将此消费帐单返销吗?", "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dreocon == DialogResult.Yes) { long conserialNo = 0; long igserialNo = 0; using (AMSEntities amscontext2 = new AMSEntities()) { tbConsserialNo conserial1 = new tbConsserialNo(); conserial1.vcFill = "0"; amscontext2.AddTotbConsserialNo(conserial1); tbIgSerialNo igserial1 = new tbIgSerialNo(); igserial1.vcFill = "0"; amscontext2.AddTotbIgSerialNo(igserial1); amscontext2.SaveChanges(); conserialNo = conserial1.iSerialNo; igserialNo = igserial1.iSerialNo; } using (AMSEntities amsContext = new AMSEntities()) { DateTime dtoperdate = DateTime.Now; long longassid = long.Parse(txtAssID.Text.Trim()); tbAssociatorCard asscard1 = amsContext.tbAssociatorCard.FirstOrDefault(ac => ac.iAssID == longassid && ac.cCardState == "1"); if (asscard1 == null) { throw new Exception("会员信息不符,请检查是否此会员卡不是正常在用,请重试!"); } tbIntegral intg1 = amsContext.tbIntegral.FirstOrDefault(ig => ig.iAssID == asscard1.iAssID && ig.vcAssCardID == asscard1.vcAssCardID); if (intg1 == null) { throw new Exception("获取当前余额积分异常,请重试!"); } var dtMaxIgDate = (from item in amsContext.tbIntegralLog where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.vcIgType == "IG002" select item.dtIgDate).Max(); string maxConsSerial = ""; if (dtMaxIgDate != null) { maxConsSerial = (from item in amsContext.tbConsumption where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.dtConsDate > dtMaxIgDate && item.vcFlag == "0" select item.iConsSerial).Max().ToString(); } else { maxConsSerial = (from item in amsContext.tbConsumption where item.iAssID == asscard1.iAssID && item.vcAssCardID == asscard1.vcAssCardID && item.vcFlag == "0" select item.iConsSerial).Max().ToString(); } if (maxConsSerial == null || maxConsSerial == "") { throw new Exception("没有可返销的消费帐单记录,请重试!"); } long longcons = long.Parse(maxConsSerial); var conslist = from item in amsContext.tbConsumption where item.iConsSerial == longcons orderby item.iNO select item; if (conslist == null) { throw new Exception("没有可返销的消费帐单记录!"); } tbBillInvoice bill1 = amsContext.tbBillInvoice.FirstOrDefault(bl => bl.vcAssCardID == asscard1.vcAssCardID && bl.vcEffFlag == "1" && bl.vcLinkSerial == longcons); if (bill1 == null) { throw new Exception("没有可返销的消费帐单记录!"); } tbIntegralLog iglog1 = amsContext.tbIntegralLog.FirstOrDefault(igg => igg.iLinkCons == longcons); if (iglog1 == null) { throw new Exception("没有可返销的消费帐单记录!"); } if (bill1.iBillNo.ToString() != txtBillNo.Text.Trim() || maxConsSerial != txtConsSerial.Text.Trim()) { throw new Exception("数据异常,请重试!"); } intg1.nBalance = intg1.nBalance + (decimal)bill1.dTotalFee; intg1.iIgValue = (int)intg1.iIgValue - (int)bill1.dIgGet; ObjectStateEntry ose = amsContext.ObjectStateManager.GetObjectStateEntry(intg1); foreach (var item in conslist) { item.vcFlag = "1"; item.iLink = conserialNo; item.dtOperDate = dtoperdate; item.vcComments += "-由操作员:" + GlobalParams.oper.vcOperName + ",返销"; tbConsumption cons1 = new tbConsumption(); cons1.iConsSerial = conserialNo; cons1.iNO = item.iNO; cons1.iAssID = item.iAssID; cons1.vcAssCardID = item.vcAssCardID; cons1.vcGoodsCode = item.vcGoodsCode; cons1.nGoodsPrice = -item.nGoodsPrice; cons1.iConsCount = item.iConsCount; cons1.nLastBalance = decimal.Parse(ose.OriginalValues["nBalance"].ToString()); cons1.nConsCharge1 = -item.nConsCharge1; cons1.nConsRate = item.nConsRate; cons1.nConsCharge2 = -item.nConsCharge2; cons1.nBalance = decimal.Parse(ose.CurrentValues["nBalance"].ToString()); cons1.dtConsDate = dtoperdate; cons1.dtOperDate = dtoperdate; cons1.vcFlag = "9"; cons1.iLink = item.iConsSerial; cons1.vcOperID = GlobalParams.oper.vcOperID; cons1.vcClass = GlobalParams.strClass; cons1.vcComments = ""; amsContext.AddTotbConsumption(cons1); } iglog1.vcComments += "-本次积分已被返销"; tbIntegralLog ignew = new tbIntegralLog(); ignew.iIgSerial = igserialNo; ignew.iNo = 1; ignew.iAssID = iglog1.iAssID; ignew.vcAssCardID = iglog1.vcAssCardID; ignew.iIgLast = int.Parse(ose.OriginalValues["iIgValue"].ToString()); ignew.dtIgDate = dtoperdate; ignew.vcIgName = "0"; ignew.vcIgType = "IG003"; ignew.iIgGet = -(int)bill1.dIgGet; ignew.iIgArrival = int.Parse(ose.CurrentValues["iIgValue"].ToString()); ignew.iLinkCons = conserialNo; ignew.vcOperID = GlobalParams.oper.vcOperID; ignew.vcComments = ""; amsContext.AddTotbIntegralLog(ignew); tbBusiLog busilog1 = new tbBusiLog(); busilog1.vcAssName = txtAssName.Text.Trim(); busilog1.vcAssCardID = intg1.vcAssCardID; busilog1.vcLinkSerial = conserialNo; busilog1.vcOperType = "OT012"; busilog1.vcOperID = GlobalParams.oper.vcOperID; busilog1.vcOperName = GlobalParams.oper.vcOperName; busilog1.dtOperDate = dtoperdate; busilog1.iAssID = intg1.iAssID; amsContext.AddTotbBusiLog(busilog1); amsContext.SaveChanges(); txtCardID.Text = ""; txtAssName.Text = ""; txtBillNo.Text = ""; txtCurCharge.Text = ""; txtCurIG.Text = ""; txtConsFee.Text = ""; txtConsDate.Text = ""; txtAssID.Text = ""; txtConsSerial.Text = ""; btnRollBack.Enabled = false; DataTable dtConsList = new DataTable(); dtConsList.Columns.Add("消费项名称"); dtConsList.Columns.Add("单价"); dtConsList.Columns.Add("折扣"); dtConsList.Columns.Add("数量"); dtConsList.Columns.Add("单项合计"); dtConsList.Columns.Add("备注"); dtConsList.PrimaryKey = new DataColumn[] { dtConsList.Columns["消费项名称"], dtConsList.Columns["单价"], dtConsList.Columns["折扣"] }; dgvConsList.DataSource = dtConsList; MessageBox.Show("本次消费帐单返销成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCardID.Focus(); } } } catch (Exception ex) { ErrorLog.Write(this, ex, "返销异常"); this.Close(); } }
public virtual TEntity Insert(TEntity entity) { dbSet.Add(entity); context.SaveChanges(); return(entity); }
private void btnAdd_Click(object sender, EventArgs e) { try { if (txtOperID.Text.Trim().Length == 0) { throw new Exception("请输入操作员帐号"); } if (txtOperName.Text.Trim().Length == 0) { throw new Exception("请输入操作员名称"); } if (txtOperPwd.Text.Trim().Length == 0) { throw new Exception("请输入密码"); } if (txtOperPwdConfirm.Text.Trim().Length == 0) { throw new Exception("请输入密码确认"); } if (!txtOperPwd.Text.Equals(txtOperPwdConfirm.Text)) { throw new Exception("确认密码不一致"); } using (AMSEntities amsContext = new AMSEntities()) { switch (btnAdd.Text) { case "添加": tbOper eOper = amsContext.tbOper.FirstOrDefault(o => o.vcOperID == txtOperID.Text || o.vcOperName == txtOperName.Text); if (eOper != null) { throw new Exception("相同名称或者(帐号的操作员已存在"); } tbOper nOper = new tbOper(); nOper.vcLimit = cmbRole.SelectedValue.ToString(); nOper.vcOperID = txtOperID.Text; nOper.vcOperLevel = cmbOperLevel.SelectedValue.ToString(); //"OL001"; nOper.vcOperName = txtOperName.Text; nOper.vcOperPwd = txtOperPwd.Text; nOper.iFlag = 0; amsContext.AddTotbOper(nOper); amsContext.SaveChanges(); MessageBox.Show(this, "操作员添加成功", "添加操作员"); break; case "修改": int i = amsContext.tbOper.Count(o => o.vcOperName == txtOperName.Text); if (i > 1) { throw new Exception("相同名称的操作员已存在"); } tbOper oper = amsContext.tbOper.FirstOrDefault(o => o.vcOperID == txtOperID.Text); oper.vcLimit = cmbRole.SelectedValue.ToString(); oper.vcOperName = txtOperName.Text; oper.vcOperPwd = txtOperPwd.Text; oper.vcOperLevel = cmbOperLevel.SelectedValue.ToString(); amsContext.SaveChanges(); MessageBox.Show(this, "操作员修改成功", "修改操作员"); break; } } frmOper_Load(null, null); } catch (Exception ex) { ErrorLog.Write(this, ex, "操作员"); } }