public DBAccess() { conn = ConnectionManager.GetConnection(); }
//Add loyalty card customer private void btn_loy_add_Click(object sender, EventArgs e) { CustomerObject co = new CustomerObject(); SqlConnection con = ConnectionManager.GetConnection(); if (con.State.ToString() == "Closed") { con.Open(); } if (CustomerLoyaltyCardValidation()) { try { SqlCommand cmd = con.CreateCommand(); string nic = "select NIC from Customer where NIC = '" + txt_loy_nic.Text + "'"; cmd.CommandText = nic; SqlDataReader rd = cmd.ExecuteReader(); rd.Read(); bool result1 = rd.HasRows; if (!result1) { MessageBox.Show("This customer is not registered customer cannot issue a loyalty card"); } else { if (CustomerLoyaltyCardValidation()) { CustomerObject objCustomer = new CustomerObject(); objCustomer.Nic = txt_loy_nic.Text; objCustomer.CardType = cmb_loy_cardtype.SelectedItem.ToString(); objCustomer.CardNo = lbl_loymem_cardno.Text; // objCustomer.CardPoints = Convert.ToInt32(txtb_loy_cardpoints.Text); objCustomer.CardPoints = 0; //show the confirmation dialog box DialogResult dr; dr = MessageBox.Show("Do you want to save the record", "Confirm", MessageBoxButtons.YesNo); if (dr.ToString() == "Yes") { try { MegaCoolMethods mcm = new MegaCoolMethods(); bool result = mcm.AddLoyaltyCustomer(objCustomer); if (result) { MessageBox.Show("Successfully Saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_cus_tabcontroller.SelectedTab = tab_customermanagement; } else { MessageBox.Show("Unable to Save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (ApplicationException appEx) { MessageBox.Show(appEx.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (SqlException ex) { if (ex.Number == 2627) { MessageBox.Show("This loyalty customer is alreay exist, please add new customer "); //Violation of primary key. Handle Exception } } } else { MessageBox.Show("Record is not saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } } catch (SqlException ex) { throw ex; } } CustomerLotaltyCardFillGrid(); Clear(); CustomerFillGrid(); }
private void btnAddEmployee_Click(object sender, EventArgs e) { if (txtCus.Text == "" || comboBoxR_Type.Text == "" || txtDetails.Text == "" || comboSupervisor.Text == "") { MessageBox.Show("Please fill the all required feilds"); } else { RepairObject objRepair = new RepairObject(); CustomerObject objCustomer = new CustomerObject(); EmployeeObject objEmployee = new EmployeeObject(); objCustomer.Nic = txtCus.Text; objRepair.JobStartDate = dtpStart.Value; objRepair.JobEndDate = dtpEnd.Value; objRepair.rType = comboBoxR_Type.Text; objRepair.Details = txtDetails.Text; objEmployee.empid = Convert.ToInt32(comboSupervisor.SelectedValue); bool checker1 = false; bool checker2 = false; if (objRepair.JobStartDate >= DateTime.Today) { checker1 = true; } if (objRepair.JobEndDate >= DateTime.Today) { checker2 = true; } if (checker1 == false || checker2 == false) { MessageBox.Show("You cant enter this date"); } else { string nic = txtCus.Text; if ((nic.Count(char.IsDigit) == 9) && nic.EndsWith("v", StringComparison.OrdinalIgnoreCase)) { DialogResult dr; dr = MessageBox.Show("Do you want to save the record", "Confirm", MessageBoxButtons.YesNo); if (dr.ToString() == "Yes") { try { MegaCoolMethods mcm = new MegaCoolMethods(); bool result = mcm.AddNewRepairJob(objRepair, objCustomer, objEmployee); if (result) { MessageBox.Show("Successfully Saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); RepairFillGrid(); avCusFillGrid(); SqlConnection con = ConnectionManager.GetConnection(); con.Open(); string qu = "SELECT TOP 1 JobID FROM Repair_Job ORDER BY JobID DESC"; SqlCommand newcmd = con.CreateCommand(); newcmd.CommandText = qu; SqlDataReader reader = newcmd.ExecuteReader(); reader.Read(); int y = reader.GetInt32(0); txtJobID.Text = Convert.ToString(y); tabControl1.SelectedTab = tabPage2; } else { MessageBox.Show("Unable to Save", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (ApplicationException appEx) { MessageBox.Show(appEx.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } catch (Exception ex) { throw ex; } } else { MessageBox.Show("Record is not saved", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Error in NIC"); } } } }