public void Show()
        {
            try
            {
                suplierTableBody.InnerHtml = "";
                string htmlContent = "";
                List<Supplier> departmentList = new List<Supplier>();
                Supplier aDepartment = new Supplier();
                departmentList = aDepartment.GetAllSupplier(_company.CompanyId);
                foreach (Supplier aDepo in departmentList)
                {

                    htmlContent += "<tr>";

                    htmlContent += String.Format(@"<th>{0}</th><th>{1}</th><th>{2}</th><th>{3}</th><th>{4}</th></tr>", aDepo.SupplierName, aDepo.IsActive, aDepo.UpdateDate, aDepo.TotalDebit, aDepo.TotalCredit);
                    htmlContent += "</tr>";
                }
                suplierTableBody.InnerHtml += htmlContent;

            }
            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;
                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);
            }
        }
        private void LoadSupplierTable()
        {
            try
            {
                Supplier newSupplier= new Supplier();
                objSupplierList = newSupplier.GetAllSupplier(_company.CompanyId);
                List<string> countryList = Country.CountryList();
                List<Addresses> addresses=new Addresses().GetAllAddresses(_company.CompanyId);
                foreach (Supplier supplier in objSupplierList)
                {

                    foreach (Addresses aAddress in addresses)
                    {
                        if (aAddress.SourceType == "Supplier" && aAddress.SourceId == supplier.SupplierId)
                        {
                            supplier.AddressLine1 = aAddress.AddressLine1;
                            supplier.AddressLine2 = aAddress.AddressLine2;
                            supplier.City = aAddress.City;
                            supplier.ZipCode = aAddress.ZipCode;
                            supplier.Phone = aAddress.Phone;
                            supplier.Email = aAddress.Email;
                            supplier.Web = aAddress.Web;
                            supplier.Mobile = aAddress.Mobile;
                            supplier.CountryName = countryList[aAddress.CountryId];
                        }
                    }
                }
                RadGrid1.DataSource = objSupplierList;
                RadGrid1.Rebind();

            }
            catch (Exception ex)
            {
                Alert.Show(ex.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);
            }
        }