Esempio n. 1
0
        private void customerListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CustomerListfrm customerListForm = new CustomerListfrm();

            customerListForm.UserID = UserID;
            customerListForm.Show();
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (checkValidation())
            {
                if (isEdit)
                {
                    int editBookCode = 0; int editPageNo = 0; int editLineNo = 0; int editLineCount = 0;
                    int editMeterCount = 0;
                    editBookCode = Convert.ToInt32(cboBookCode.Text);
                    editLineNo   = Convert.ToInt32(txtLineNo.Text);
                    editPageNo   = Convert.ToInt32(txtPageNo.Text);

                    int      editCustomerCodeCount = 0, editNRCCount = 0;
                    Customer updateCustomer = (from c in mbmsEntities.Customers where c.CustomerID == customerID select c).FirstOrDefault();
                    if (txtCustomerCode.Text != updateCustomer.CustomerCode)
                    {
                        editCustomerCodeCount = (from c in mbmsEntities.Customers where c.CustomerCode == txtCustomerCode.Text && c.Active == true select c).ToList().Count;
                    }
                    if (txtNRC.Text != updateCustomer.NRC)
                    {
                        editNRCCount = (from c in mbmsEntities.Customers where c.NRC == txtNRC.Text && c.Active == true select c).ToList().Count;
                    }
                    if (editLineNo != updateCustomer.LineNo)
                    {
                        editLineCount = (from c in mbmsEntities.Customers where (c.Ledger.BookCode == editBookCode && c.LineNo == editLineNo && c.PageNo == editPageNo) && c.Active == true select c).ToList().Count;
                    }
                    if (cboMeterNo.SelectedText != updateCustomer.Meter.MeterNo)
                    {
                        editMeterCount = (from c in mbmsEntities.Customers where c.Meter.MeterNo == cboMeterNo.SelectedText && c.Active == true select c).ToList().Count;
                    }

                    if (editCustomerCodeCount > 0)
                    {
                        tooltip.SetToolTip(txtCustomerCode, "Error");
                        tooltip.Show("Customer Code is already exist!", txtCustomerCode);
                        return;
                    }
                    if (editNRCCount > 0)
                    {
                        tooltip.SetToolTip(txtNRC, "Error");
                        tooltip.Show("NRC is already exist!", txtNRC);
                        return;
                    }
                    if (editLineCount > 0)
                    {
                        tooltip.SetToolTip(txtLineNo, "Error");
                        tooltip.Show("Line No is already used!", txtLineNo);
                        return;
                    }
                    if (editMeterCount > 0)
                    {
                        tooltip.SetToolTip(cboMeterNo, "Error");
                        tooltip.Show("Meter Serial No is already used!", cboMeterNo);
                        return;
                    }
                    string oldMeterNo = updateCustomer.Meter.MeterNo;
                    updateCustomer.CustomerCode         = txtCustomerCode.Text;
                    updateCustomer.CustomerNameInEng    = txtCustomerNameEng.Text;
                    updateCustomer.CustomerNameInMM     = txtCustomerNameMM.Text;
                    updateCustomer.CustomerAddressInEng = txtAddressEng.Text;
                    updateCustomer.CustomerAddressInMM  = txtAddressMM.Text;
                    updateCustomer.NRC              = txtNRC.Text;
                    updateCustomer.PhoneNo          = txtPhone.Text;
                    updateCustomer.Post             = txtPost.Text;
                    updateCustomer.PageNo           = Convert.ToInt32(txtPageNo.Text);
                    updateCustomer.LineNo           = Convert.ToInt32(txtLineNo.Text);
                    updateCustomer.LedgerID         = cboBookCode.SelectedValue.ToString();
                    updateCustomer.QuarterID        = cboQuarterName.SelectedValue.ToString();
                    updateCustomer.TownshipID       = cboTownshipName.SelectedValue.ToString();
                    updateCustomer.BillCode7LayerID = cboBillCodeNo.SelectedValue.ToString();
                    updateCustomer.MeterID          = cboMeterNo.SelectedValue.ToString();
                    updateCustomer.SMDNo            = txtSMDSerial.Text;
                    updateCustomer.UpdatedUserID    = UserID;
                    updateCustomer.UpdatedDate      = DateTime.Now;
                    customerController.UpdateCustomer(updateCustomer);
                    //updating the meter history information
                    if (!cboMeterNo.Text.Equals(oldMeterNo) && meterHistory != null)
                    {
                        meterHistory.MeterID = updateCustomer.MeterID;
                        meterservice.UpdateMeterHistory(meterHistory);
                    }
                    MessageBox.Show("Successfully Updated Customer!", "Update");
                    Clear();
                    CustomerListfrm customerListForm = new CustomerListfrm();
                    customerListForm.Show();
                    this.Close();
                }
                else
                {
                    int customerCodeCount = 0, nrcCount = 0;
                    customerCodeCount = (from c in mbmsEntities.Customers where c.CustomerCode == txtCustomerCode.Text && c.Active == true select c).ToList().Count;
                    nrcCount          = (from c in mbmsEntities.Customers where c.NRC == txtNRC.Text && c.Active == true select c).ToList().Count;
                    int bookCode = 0; int pageNo = 0; int lineNo = 0; int lineCount = 0;
                    bookCode = Convert.ToInt32(cboBookCode.Text);
                    lineNo   = Convert.ToInt32(txtLineNo.Text);
                    pageNo   = Convert.ToInt32(txtPageNo.Text);

                    lineCount = (from c in mbmsEntities.Customers where (c.Ledger.BookCode == bookCode && c.PageNo == pageNo && c.LineNo == lineNo) && c.Active == true select c).ToList().Count;


                    if (customerCodeCount > 0)
                    {
                        tooltip.SetToolTip(txtCustomerCode, "Error");
                        tooltip.Show("Customer Code is already exist!", txtCustomerCode);
                        return;
                    }
                    if (nrcCount > 0)
                    {
                        tooltip.SetToolTip(txtNRC, "Error");
                        tooltip.Show("Customer NRC is already exist!", txtNRC);
                        return;
                    }
                    if (lineCount > 0)
                    {
                        tooltip.SetToolTip(txtLineNo, "Error");
                        tooltip.Show("Line No is already used!", txtLineNo);
                        return;
                    }
                    string meterId         = cboMeterNo.SelectedValue.ToString();
                    bool   IsMeterIDExists = iCustomerServices.GetCustomerByMeterID(meterId);
                    if (IsMeterIDExists)
                    {
                        MessageBox.Show("Customer's Meter No already exists in the system for>" + txtCustomerCode.Text, "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    bool IsSMDSerialExist = mbmsEntities.Customers.Any(x => x.SMDNo == txtSMDSerial.Text);
                    if (IsSMDSerialExist)
                    {
                        tooltip.SetToolTip(txtSMDSerial, "Error");
                        tooltip.Show("Customer SMD Serial No is already exist!", txtSMDSerial);
                        return;
                    }
                    Customer customer = new Customer();
                    customer.CustomerID           = Guid.NewGuid().ToString();
                    customer.CustomerCode         = txtCustomerCode.Text;
                    customer.CustomerNameInEng    = txtCustomerNameEng.Text;
                    customer.CustomerNameInMM     = txtCustomerNameMM.Text;
                    customer.CustomerAddressInEng = txtAddressEng.Text;
                    customer.CustomerAddressInMM  = txtAddressMM.Text;
                    customer.NRC              = txtNRC.Text;
                    customer.PhoneNo          = txtPhone.Text;
                    customer.Post             = txtPost.Text;
                    customer.PageNo           = Convert.ToInt32(txtPageNo.Text);
                    customer.LineNo           = Convert.ToInt32(txtLineNo.Text);
                    customer.LedgerID         = cboBookCode.SelectedValue.ToString();
                    customer.QuarterID        = cboQuarterName.SelectedValue.ToString();
                    customer.TownshipID       = cboTownshipName.SelectedValue.ToString();
                    customer.BillCode7LayerID = cboBillCodeNo.SelectedValue.ToString();
                    customer.MeterID          = cboMeterNo.SelectedValue.ToString();
                    customer.SMDNo            = txtSMDSerial.Text;
                    customer.Active           = true;
                    customer.CreatedUserID    = UserID;
                    customer.CreatedDate      = DateTime.Now;
                    customerController.Save(customer);
                    MessageBox.Show("Successfully registered Customer! Please check it in 'Customer List'.", "Save Success");
                    Clear();
                }
            }
        }