protected void btnSave_Click(object sender, EventArgs e) { try { if (btnDelete.Enabled == false) { List<Machine> listMac = new List<Machine>(); listMac = Machine.GetAll().Where(l => l.Name.Trim().ToLower() == txtMachineName.Text.Trim().ToLower()).ToList(); if (listMac.Count > 0) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblMachineName.Text)) + "\");"); return; } Machine mac = new Machine(); mac.No = txtNo.Text; mac.Name = txtMachineName.Text; mac.CompanyId = int.Parse(GetCompany()); mac.FactoryId = int.Parse(cbxfactory.SelectedItem.Value); mac.isDeleted = false; mac.CreateAccount = mac.ModifiedAccount = this.User.Identity.Name; mac.Insert(); } else { Machine mac = new Machine(); mac.MachineId = int.Parse(hiddenMacID.Value); mac = mac.GetByPrimaryKey(); if (mac.Name.Trim() != txtMachineName.Text.Trim()) { List<Machine> listMac = new List<Machine>(); listMac = Machine.GetAll().Where(l => l.Name.Trim().ToLower() == txtMachineName.Text.Trim().ToLower()).ToList(); if (listMac.Count > 0) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblMachineName.Text)) + "\");"); return; } } mac.ModifiedAccount = this.User.Identity.Name; mac.No = txtNo.Text; mac.Name = txtMachineName.Text; mac.FactoryId = int.Parse(cbxfactory.SelectedItem.Value); mac.CompanyId = int.Parse(GetCompany()); mac.Update(); } panelEdit.Visible = false; panelMain.Visible = true; Search(); } catch (Exception ex) { RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");"); logger.Error("Erorr btnSave_click", ex); } }