protected void btnSave_Click(object sender, EventArgs e)
        {
            Customer objCustomer = new Customer();

            List<Customer> myList = objCustomer.GetAllCustomer(_company.CompanyId);

            objCustomer.CustomerId = myList.Count;
            objCustomer.CustomerName = txtCustomerName.Value;
            objCustomer.CustomerCategoryId =int.Parse(txtCustomerCategory.Value);
            objCustomer.SalesPersonId = int.Parse(salesPersonDropDownList.SelectedItem.Value);
            objCustomer.IsActive = chkIsActive.Checked;
            objCustomer.CompanyId = _company.CompanyId;
            objCustomer.CreditLimit = int.Parse(txtCreditLimit.Value);
            objCustomer.UpdateBy = _user.UserId;
            objCustomer.UpdateDate=DateTime.Now;

            Addresses address = new Addresses();
            List<Addresses> addresseses = address.GetAllAddresses(_company.CompanyId);
            address.AddressId = addresseses.Count;
            address.SourceType = "Customer";
            address.SourceId = _user.UserId;
            address.AddressType = "Main Address";
            address.AddressLine1 = txtAddressLine1.Value;
            address.AddressLine2 = txtAddressLine2.Value;
            address.CountryId = countryDropDownList.SelectedIndex;
            address.City = txtCity.Value;
            address.ZipCode = txtZipCode.Value;
            address.Phone = txtPhoneNo.Value;
            address.Mobile = txtPhoneNo.Value;
            address.Email = txtEmail.Value;
            address.Web = txtWeb.Value;
            address.CompanyId = _company.CompanyId;

            int chk1 = objCustomer.InsertCustomer();
            int chk2=address.InsertAddresses();
            if (chk1 > 0 && chk2 > 0)
                {
                    Session["savedCutomerMessage"] = "Saved Successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error occured while inserting customer information");
                }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Customer objCustomer = new Customer();

            objCustomer.CustomerName = txtCustomerName.Value;
            objCustomer.CustomerCategoryId = int.Parse(txtCustomerCategory.Value);
            objCustomer.SalesPersonId = int.Parse(salesPersonDropDownList.SelectedItem.Value);
            objCustomer.IsActive = chkIsActive.Checked;
            objCustomer.CompanyId = _company.CompanyId;
            objCustomer.CreditLimit = int.Parse(txtCreditLimit.Value);
            objCustomer.UpdateBy = _user.UserId;
            objCustomer.UpdateDate = DateTime.Now;

            Addresses address = new Addresses();

            address.SourceType = "Customer";

            address.AddressType = "Main Address";
            address.AddressLine1 = txtAddressLine1.Value;
            address.AddressLine2 = txtAddressLine2.Value;
            address.CountryId = countryDropDownList.SelectedIndex;
            address.City = txtCity.Value;
            address.ZipCode = txtZipCode.Value;
            address.Phone = txtPhoneNo.Value;
            address.Mobile = txtMobile.Value;
            address.Email = txtEmail.Value;
            address.Web = txtWeb.Value;
            address.CompanyId = _company.CompanyId;
            if ((lblId.Text == "" || lblId.Text == "0") && (addlblId.Text == "" || addlblId.Text == "0"))
            {
                objCustomer.CustomerId = new Customer().GetMaxCustomerID() + 1;
                address.SourceId = objCustomer.CustomerId;
                address.AddressId = new Addresses().GetMaxAddressId() + 1;
                int chk1 = objCustomer.InsertCustomer();
                int chk2 = address.InsertAddresses();
                if (chk1 > 0 && chk2 > 0)
                {

                    Session["savedCutomerMessage"] = "Saved Successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error occured while inserting customer information");
                }
            }
            else
            {
                address.AddressId =long.Parse( addlblId.Text);
                objCustomer.CustomerId = long.Parse(lblId.Text);
                int check = address.UpdateAddresses();
                check = objCustomer.UpdateCustomer();

                if (check > 0)
                {
                    Response.Redirect("CustomerList.aspx", true);
                }

            }
        }