protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool chk = false;
                Supplier aSupply = new Supplier();
                List<Supplier> aSuppierList = aSupply.GetAllSupplier(_company.CompanyId);
                long id;
                if (aSuppierList.Count > 0)
                {
                    aSupply = aSuppierList[aSuppierList.Count - 1];
                    id = aSupply.SupplierId + 1;
                }

                else
                    id = 1;

                Supplier newSupply = new Supplier();
                newSupply.SupplierId = id;
                newSupply.SupplierName = txtSupplierName.Value;
                newSupply.IsActive = true;
                newSupply.CompanyId = _company.CompanyId;
                newSupply.UpdateBy = user.UserId;
                newSupply.UpdateDate = DateTime.Now;
                newSupply.TotalDebit = int.Parse(txtTotalDebit.Value);
                newSupply.TotalCredit = int.Parse(txtTotalCredit.Value);
                newSupply.Balance = newSupply.TotalCredit - newSupply.TotalDebit;
                Addresses aAddresses = new Addresses();
                aAddresses.SourceType = "Supplier";
                aAddresses.SourceId = id;
                aAddresses.AddressType = "Main Address";
                aAddresses.AddressLine1 = txtAddressLine1.Value;
                aAddresses.AddressLine2 = txtAddressLine2.Value;
                aAddresses.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                aAddresses.City = txtCity.Value;
                aAddresses.ZipCode = txtZipCode.Value;

                aAddresses.CompanyId = _company.CompanyId;
                int chk1 = newSupply.InsertSupplier();
                int chk2 = aAddresses.InsertAddresses();
                if (chk1 > 0 && chk2 > 0)
                {
                    Session["savedSupplicerMessage"] = "Saved Successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error occured while inserting supplier information,please check the input data again. Don't use special character in Debit or Credit Section . Use the amount number there.");
                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool chk = false;
                Supplier aSupply = new Supplier();
                List<Supplier> aSuppierList = aSupply.GetAllSupplier(_company.CompanyId);
                long id;

                Supplier newSupply = new Supplier();

                newSupply.SupplierName = txtSupplierName.Value;
                newSupply.IsActive = true;
                newSupply.CompanyId = _company.CompanyId;
                newSupply.UpdateBy = user.UserId;
                newSupply.UpdateDate = DateTime.Now;
                newSupply.TotalDebit = decimal.Parse(txtTotalDebit.Value);
                newSupply.TotalCredit = decimal.Parse(txtTotalCredit.Value);

                Addresses address = new Addresses();
                address.SourceType = "Supplier";

                address.AddressType = "Main Address";
                address.AddressLine1 = txtAddressLine1.Value;
                address.AddressLine2 = txtAddressLine2.Value;
                address.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                address.City = txtCity.Value;
                address.Email = txtEmail.Value;
                address.Phone = txtPhone.Value;
                address.Web = txtWeb.Value;
                address.Mobile = txtMobile.Value;

                address.ZipCode = txtZipCode.Value;

                address.CompanyId = _company.CompanyId;
                if (lblId.Text == "" || lblId.Text == "0")
                {
                    newSupply.SupplierId = new Supplier().GetMaxSupplierID() + 1;
                    address.SourceId = newSupply.SupplierId;
                    address.AddressId = new Addresses().GetMaxAddressId() + 1;
                    int chk1 = newSupply.InsertSupplier();
                    int chk2 = address.InsertAddresses();
                    if (chk1 > 0 && chk2 > 0)
                    {
                        Session["savedSupplicerMessage"] = "Saved Successfully";
                        Response.Redirect(Request.RawUrl);

                    }
                    else
                    {
                        Alert.Show("Error occured while inserting supplier information,please check the input data again. Don't use special character in Debit or Credit Section . Use the amount number there.");
                    }
                }
                else
                {
                    address.AddressId = long.Parse(addlblId.Text);
                    newSupply.SupplierId = int.Parse(lblId.Text);
                    address.SourceId = newSupply.SupplierId;
                    int chk1 = newSupply.UpdateSupplier();
                    int chk2 = address.UpdateAddresses();
                    if(chk1>0&&chk2>0)
                        Response.Redirect("SupplierList.aspx");

                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }