protected void RadGrid1_OnItemCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                GridDataItem item = (GridDataItem)e.Item;
                string id = item["colId"].Text;
                switch (e.CommandName)
                {
                    case "btnSelect":
                        Response.Redirect("CompanyInfo.aspx?id=" + id, true);
                        break;
                    case "btnDelete":
                        int delete = new Company().DeleteCompanyByCompanyId(int.Parse(id));
                        long addressid = GetAddressID(int.Parse(id));
                        int deleteAddress = new Addresses().DeleteAddressesByAddressId(addressid);
                        if (delete == 0)
                            Alert.Show("Data was not deleted");
                        else
                        {
                            this.LoadCompanyListTable();
                        }
                        break;

                }
            }
            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;
                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 long GetAddressID(int parse)
        {
            long p = 0;
            Addresses newAddress = new Addresses();
            List<Addresses> liAddress = newAddress.GetAllAddresses(_company.CompanyId);
            foreach (Addresses addressese in liAddress)
            {
                if (addressese.SourceType == "Company" && addressese.SourceId == parse)
                {
                    p = addressese.AddressId;
                    break;
                }

            }
            return p;
        }
        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 RadGrid1_OnItemCommand(object sender, GridCommandEventArgs e)
        {
            try
            {
                GridDataItem item = (GridDataItem) e.Item;
                string id = item["colId"].Text;
                switch (e.CommandName)
                {
                    case "btnSelect":
                    {
                        Response.Redirect("SupplierInfo.aspx?id="+id);
                        break;
                    }
                    case "btnDelete":
                    {
                        int del = new Supplier().DeleteSupplierBySupplierId(int.Parse(id));
                        long addId = GetAddressID(int.Parse(id));
                        int del2 = new Addresses().DeleteAddressesByAddressId(addId);
                        if (del2 == 0 && del == 0)
                        {
                            Alert.Show("Data is not deleted");
                        }
                        else
                        {
                            this.LoadSupplierTable();
                        }
                        break;
                    }
                }

            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company)Session["Company"];
            user = (Users)Session["user"];

            this.LoadCountryDropDownList();
            this.LoadDepartmentDropDownList();

            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                {
                    Response.Redirect("LogIn.aspx?refPage=index.aspx");
                }
                else
                {
                    Response.Redirect("LogIn.aspx?regPage=index.aspx"+str);
                }
            }
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string id = Request.QueryString["id"].ToString();
                    Employee tempEmployee= new Employee().GetEmployeeByEmployeeId(int.Parse(id),_company.CompanyId);
                    if (tempEmployee != null || tempEmployee.EmployeeId != 0)
                    {
                        List<string> countryList = Country.CountryList();
                        List<Addresses> addressList = new Addresses().GetAllAddresses(_company.CompanyId);
                        Designation designation =
                            new Designation().GetDesignationByDesignationId(tempEmployee.DesignationId,
                                _company.CompanyId);
                        Department department;
                        if (tempEmployee.DepartmentId != 0)
                        {
                            department = new Department().GetDepartmentByDepartmentId(tempEmployee.DepartmentId,
                                _company.CompanyId);
                            SetIndex(departmentDropDownList, department.DepartmentId.ToString());
                            LoadDesignationDropDownList(tempEmployee.DepartmentId);

                        }
                        else
                        {
                            department = new Department();
                            departmentDropDownList.SelectedIndex = -1;
                            LoadDesignationDropDownList(0);
                        }
                        SetIndex(designationDropDownList,tempEmployee.DesignationId.ToString());
                        lblId.Text = tempEmployee.EmployeeId.ToString();
                        txtEmployeeCode.Value = tempEmployee.EmployeeCode;
                        txtEmployeeName.Value = tempEmployee.EmployeeName;
                        JoinRadDatePicker.SelectedDate = DateTime.Parse(tempEmployee.JoinDate);
                        RadDatePicker1.SelectedDate = DateTime.Parse(tempEmployee.DOB);
                        chkIsActive.Checked = tempEmployee.IsActive;

                       //SetIndex(designationDropDownList,designation.DesignationId.ToString());
                        foreach (Addresses tAddress in addressList)
                        {
                            if (tAddress.SourceType == "Employee" && tAddress.SourceId == tempEmployee.EmployeeId)
                            {
                                addlblId.Text = tAddress.AddressId.ToString();
                                txtAddressLine1.Value = tAddress.AddressLine1;
                                txtAddressLine2.Value = tAddress.AddressLine2;
                                txtCity.Value = tAddress.City;
                                txtEmail.Value = tAddress.Email;
                                txtZipCode.Value = tAddress.ZipCode;
                                txtPhoneNo.Value = tAddress.Phone;
                                countryDropDownList.SelectedIndex = tAddress.CountryId;
                                break;

                            }

                        }
                    }

                }
            }
            if (Session["empMessage"] != null)
            {
                string message = Session["empMessage"].ToString();
                Session["empMessage"] = null;
                Alert.Show(message);
            }
        }
        private void LoadCompanyListTable()
        {
            try
            {
                Company objCompany = new Company();
                List<string> countryList = Country.CountryList();
                List<Company> objCompanyList= new Company().GetAllCompany();
                if (objCompanyList.Count == 0)
                {
                    objCompanyList.Add(new Company());
                }
                foreach (Company objCst in objCompanyList)
                {

                    Addresses address= new Addresses().GetAddressesBySourceTypeAndId("Company",objCst.CompanyId);

                            objCst.AddressId = address.AddressId;
                            objCst.AddressLine1 = address.AddressLine1;
                            objCst.AddressLine2 = address.AddressLine2;
                            objCst.AddressType = address.AddressType;
                            objCst.City = address.City;
                            objCst.ZipCode = address.ZipCode;
                            objCst.Phone = address.Phone;
                            objCst.Mobile = address.Mobile;
                            objCst.Email = address.Email;
                            objCst.Web = address.Web;
                            objCst.CountryName = countryList[address.CountryId];

                }
                RadGrid1.DataSource = objCompanyList;
                RadGrid1.Rebind();
            }
            catch (Exception ex)
            {
                Alert.Show(ex.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);
            }
        }
 private long GetAddressID(int parse)
 {
     Addresses newAddress = new Addresses();
     List<Addresses> liAddress = newAddress.GetAllAddresses(_company.CompanyId);
     return (from addressese in liAddress where addressese.SourceType == "Employee" && addressese.SourceId == parse select addressese.AddressId).FirstOrDefault();
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company) Session["Company"];
            this.LoadAllCompany();

            this.LoadCountryDropdown();

            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                    Response.Redirect("LogIn.aspx?refPage=default.aspx");
                else
                    Response.Redirect("LogIn.aspx?refPage=default.aspx?" + str);
            }
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string companyId = Request.QueryString["id"].ToString();
                    Company tempCompany= new Company().GetCompanyByCompanyId(int.Parse(companyId));
                    if (tempCompany != null || tempCompany.CompanyId != 0)
                    {
                        Addresses tempAddress = new Addresses();
                        List<Addresses> listAdddress = tempAddress.GetAllAddresses(_company.CompanyId);
                        foreach (Addresses addressese in listAdddress.Where(addressese => addressese.SourceId == tempCompany.CompanyId && addressese.SourceType == "Company"))
                        {
                            tempAddress = addressese;
                            break;
                        }
                        lblId.Text = tempCompany.CompanyId.ToString();
                        addlblId.Text = tempAddress.AddressId.ToString();
                        txtCompanyName.Value=tempCompany.CompanyName;

                        txtPhoneNo.Value=tempAddress.Phone;
                      txtEmail.Value=tempAddress.Email;
                        txtWeb.Value=tempAddress.Web;
                       txtLogoPath.Value=tempCompany.LogoPath;

                        // newCompany.UpdateBy = user.UserId;

                      chkIsActive.Checked=tempCompany.IsActive;

                        txtAddressLine1.Value=tempAddress.AddressLine1;
                        txtAddressLine2.Value=tempAddress.AddressLine2;
                        countryDropDownList.SelectedIndex=tempAddress.CountryId;
                        txtCity.Value=tempAddress.City;
                        txtZipCode.Value=tempAddress.ZipCode;

                    }
                }

            }
        }
Example #11
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //try
            //{
            if (txtCompanyName.Value == string.Empty)
            {
                Alert.Show("Please enter the company name.");
                txtCompanyName.Focus();
                return;
            }

            Company newCompany = new Company();

            newCompany.CompanyName = txtCompanyName.Value;

            newCompany.Address = txtAddress.Value;
            newCompany.Phone = txtPhoneNo.Value;
            newCompany.Email = txtEmail.Value;
            newCompany.Web = txtWeb.Value;
            newCompany.LogoPath = txtLogoPath.Value;

            // newCompany.UpdateBy = user.UserId;
            newCompany.UpdateBy = _user.UserId;
            newCompany.UpdateDate = DateTime.Now;
            newCompany.IsActive = chkIsActive.Checked;

            Addresses address = new Addresses();
            address.SourceType = "Company";
            address.SourceId = _user.CompanyId;
            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 = _user.CompanyId;

            int success = newCompany.InsertCompany();
            //address.InsertAddresses();
            if (success > 0)
            {
                Alert.Show("Saved Company Information Successfully!");
                this.LoadAllCompany();
                this.Clear();
                this.LoadCompanyTable();
            }
            else
            {
                Alert.Show("Error occured !");
            }
            //}
            //catch (Exception ex)
            //{
            //    Alert.Show(ex.Message);
            //}
        }
        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);
                }

            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company)Session["Company"];

            if (Session["savedCutomerMessage"] != null)
            {
                string msg = Session["savedCutomerMessage"].ToString();
                Alert.Show(msg);
                Session["savedCutomerMessage"] = null;
            }
            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                    Response.Redirect("LogIn.aspx?refPage=index.aspx");
                else
                    Response.Redirect("LogIn.aspx?refPage=index.aspx?" + str);
            }

            this.LoadCountryDropdown();
            this.LoadSalesPersonDropDown();

            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string customerID = Request.QueryString["id"].ToString();
                    Customer objCustomer = new Customer().GetCustomerByCustomerId(int.Parse(customerID), _company.CompanyId);
                    if (objCustomer != null || objCustomer.CustomerId != 0)
                    {
                        Addresses tempAddress = new Addresses();
                        List<Addresses> listAdddress = tempAddress.GetAllAddresses(_company.CompanyId);
                        foreach (Addresses addressese in listAdddress.Where(addressese => addressese.SourceId == objCustomer.CustomerId && addressese.SourceType == "Customer"))
                        {
                            tempAddress = addressese;
                            break;
                        }
                        addlblId.Text = tempAddress.AddressId.ToString();
                        lblId.Text = objCustomer.CustomerId.ToString();
                        txtCustomerName.Value = objCustomer.CustomerName;
                        txtCustomerCategory.Value = objCustomer.CustomerCategoryId.ToString();
                        SetIndex(salesPersonDropDownList, objCustomer.SalesPersonId.ToString());
                        countryDropDownList.SelectedIndex = tempAddress.CountryId;
                        chkIsActive.Checked = objCustomer.IsActive;
                        txtCreditLimit.Value = objCustomer.CreditLimit.ToString();
                        txtAddressLine1.Value = tempAddress.AddressLine1;
                        txtAddressLine2.Value = tempAddress.AddressLine2;
                        txtCity.Value = tempAddress.City;
                        txtZipCode.Value = tempAddress.ZipCode;
                        txtPhoneNo.Value = tempAddress.Phone;
                        txtMobile.Value = tempAddress.Mobile;
                        txtEmail.Value = tempAddress.Email;
                        txtWeb.Value = tempAddress.Web;
                    }
                }
            }
        }
        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);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            _company = (Company)Session["Company"];
            user = (Users)Session["user"];
            this.LoadCountryDropDownList();
            if (Session["savedSupplicerMessage"] != null)
            {
                string msg = Session["savedSupplicerMessage"].ToString();
                Alert.Show(msg);
                Session["savedSupplicerMessage"] = null;
            }
            if (!isValidSession())
            {
                string str = Request.QueryString.ToString();
                if (str == string.Empty)
                {
                    Response.Redirect("LogIn.aspx?refPage=index.aspx");
                }
                else
                {
                    Response.Redirect("LogIn.aspx?refPage=index.aspx?"+str);
                }
            }
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    string id = Request.QueryString["id"].ToString();
                    Supplier tempSupplier= new Supplier().GetSupplierBySupplierId(int.Parse(id),_company.CompanyId);
                    if (tempSupplier != null || tempSupplier.SupplierId != 0)
                    {
                        List<Addresses> addressList = new Addresses().GetAllAddresses(_company.CompanyId);
                        Addresses tempAddress = new Addresses();
                        foreach (Addresses address in addressList)
                        {
                            if (address.SourceType == "Supplier" && address.SourceId == int.Parse(id))
                            {
                                tempAddress = address;
                                break;
                            }
                        }
                        lblId.Text = id;
                        addlblId.Text = tempAddress.AddressId.ToString();
                        txtSupplierName.Value = tempSupplier.SupplierName;
                        txtAddressLine1.Value = tempAddress.AddressLine1;
                        txtAddressLine2.Value = tempAddress.AddressLine2;
                        txtCity.Value = tempAddress.City;
                        txtZipCode.Value = tempAddress.ZipCode;
                        txtEmail.Value = tempAddress.Email;
                        txtPhone.Value = tempAddress.Phone;
                        txtMobile.Value = tempAddress.Mobile;
                        txtWeb.Value = tempAddress.Web;
                        txtTotalCredit.Value = tempSupplier.TotalCredit.ToString();
                        txtTotalDebit.Value = tempSupplier.TotalDebit.ToString();
                        chkIsActive.Checked = tempSupplier.IsActive;
                        countryDropDownList.SelectedIndex = tempAddress.CountryId;
                    }

                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool chk = false;
                Employee aEmployee = new Employee();
                Addresses aAddresses=new Addresses();
                List<Employee> employeeListC =aEmployee.GetAllEmployee(_company.CompanyId);

                foreach (Employee anEmployee in employeeListC)
                {
                    if (anEmployee.EmployeeCode == txtEmployeeCode.Value)
                    {
                        Session["empMessage"] = "Employee Code is exist! Try Again";
                        chk = true;
                        break;
                    }
                }
                 if (chk == true)
                {
                    Response.Redirect(Request.RawUrl);
                }
                Employee tempEmployee = new Employee();
                int id;
                if (employeeListC.Count > 0)
                {
                    tempEmployee = (employeeListC[employeeListC.Count - 1]);
                      id= tempEmployee.EmployeeId + 1;
                }
                else
                {
                    id = 0;
                }

                aEmployee.EmployeeId = id;
                aEmployee.EmployeeCode = txtEmployeeCode.Value;
                aEmployee.EmployeeName = txtEmployeeName.Value;
                aEmployee.DOB = RadDatePicker1.SelectedDate.ToString();
                aEmployee.JoinDate = JoinRadDatePicker.SelectedDate.ToString();
                aEmployee.DesignationId = int.Parse(designationDropDownList.SelectedItem.ToString());
                aEmployee.DepartmentId = int.Parse(departmentDropDownList.SelectedItem.ToString());
                aAddresses.SourceId = id;
                aEmployee.Address = "Main Address";
                aAddresses.SourceType = "Employee";
                aAddresses.AddressLine1 = txtAddressLine1.Value;
                aAddresses.AddressLine2 = txtAddressLine2.Value;
                aAddresses.AddressType = "Main Address";
                aAddresses.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                aAddresses.City = txtCity.Value;
                aAddresses.ZipCode = txtZipCode.Value;
                aAddresses.Email = txtEmail.Value;
                aAddresses.CompanyId = _company.CompanyId;
                aEmployee.CompanyId = _company.CompanyId;
                aEmployee.IsActive = true;
                aEmployee.UpdateBy = user.UserId;
                aEmployee.UpdateDate = DateTime.Now;
                int chkEmployee = aEmployee.InsertEmployee();
                int chkAddress = aAddresses.InsertAddresses();
                if (chkAddress > 0 && chkEmployee > 0)
                {
                    Session["empMessage"] = "Saved Successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error occured while inserting employee information");
                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
            if (txtCompanyName.Value == string.Empty)
            {
                Alert.Show("Please enter the company name.");
                txtCompanyName.Focus();
                return;
            }

            Company newCompany = new Company();

            newCompany.CompanyName = txtCompanyName.Value;

            newCompany.Address = "";
            newCompany.Phone = "";
            newCompany.Email = "";
            newCompany.Web = "";
            newCompany.LogoPath = txtLogoPath.Value;

            // newCompany.UpdateBy = user.UserId;
            newCompany.UpdateBy = _user.UserId;
            newCompany.UpdateDate = DateTime.Now;
            newCompany.IsActive = chkIsActive.Checked;

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

            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 = _user.CompanyId;

                if (lblId.Text == "" || lblId.Text == "0")
                {
                    newCompany.CompanyId = new Company().GetMaxCompanyId() + 1;
                    address.SourceId = newCompany.CompanyId;
                    address.AddressId = new Addresses().GetMaxAddressId() + 1;
                    int success = newCompany.InsertCompany();
                    address.InsertAddresses();
                    if (success > 0)
                    {
                        Alert.Show("Saved Company Information Successfully!");
                        this.LoadAllCompany();
                        this.Clear();

                    }
                    else
                    {
                        Alert.Show("Error occured !");
                    }
                }
                else
                {
                    newCompany.CompanyId = int.Parse(lblId.Text);
                    address.SourceId = newCompany.CompanyId;
                    address.AddressId = long.Parse(addlblId.Text);
                    int chk1 = newCompany.UpdateCompany();
                    int chk2 = address.UpdateAddresses();

                    if (chk1 > 0||chk2>0)
                    {
                        Response.Redirect("CompanyList.aspx", true);
                    }
                }

            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Designation newDesignation = new Designation();

                bool chk = false;
                Employee aEmployee = new Employee();
                Addresses aAddresses=new Addresses();
                List<Employee> employeeListC =aEmployee.GetAllEmployee(_company.CompanyId);
                if (lblId.Text == "" || lblId.Text == "0")
                foreach (Employee anEmployee in employeeListC)
                {
                    if (anEmployee.EmployeeCode == txtEmployeeCode.Value)
                    {
                        Session["empMessage"] = "Employee Code is exist! Try Again";
                        chk = true;
                        break;
                    }
                }
                 if (chk == true)
                {
                    Response.Redirect(Request.RawUrl);
                }
                Employee tempEmployee = new Employee();

                aEmployee.EmployeeCode = txtEmployeeCode.Value;
                aEmployee.EmployeeName = txtEmployeeName.Value;
                aEmployee.DOB = RadDatePicker1.SelectedDate.ToString();
                aEmployee.JoinDate = JoinRadDatePicker.SelectedDate.ToString();

                aEmployee.DepartmentId = int.Parse(departmentDropDownList.SelectedIndex>-1?departmentDropDownList.SelectedItem.Value:"0");
                aEmployee.DesignationId = int.Parse(designationDropDownList.SelectedItem.Value);
                aEmployee.Address = "Main Address";
                aAddresses.SourceType = "Employee";
                aAddresses.AddressLine1 = txtAddressLine1.Value;
                aAddresses.AddressLine2 = txtAddressLine2.Value;
                aAddresses.AddressType = "Main Address";
                aAddresses.CountryId = int.Parse(countryDropDownList.SelectedIndex.ToString());
                aAddresses.City = txtCity.Value;
                aAddresses.ZipCode = txtZipCode.Value;
                aAddresses.Email = txtEmail.Value;
                aAddresses.Web = "";
                aAddresses.Phone = txtPhoneNo.Value;
                aAddresses.Mobile = txtMobile.Value;
                aAddresses.CompanyId = _company.CompanyId;
                aEmployee.CompanyId = _company.CompanyId;
                aEmployee.IsActive = true;
                aEmployee.UpdateBy = user.UserId;
                aEmployee.UpdateDate = DateTime.Now;
                if (lblId.Text == "" || lblId.Text == "0")
                {
                    aEmployee.EmployeeId = new Employee().GetMaxEmployeeId() + 1;
                    aAddresses.SourceId = aEmployee.EmployeeId;
                    aAddresses.AddressId = new Addresses().GetMaxAddressId() + 1;

                    int chkEmployee = aEmployee.InsertEmployee();
                    int chkAddress = aAddresses.InsertAddresses();
                    if (chkAddress > 0 && chkEmployee > 0)
                    {
                        Session["empMessage"] = "Saved Successfully";
                        Response.Redirect(Request.RawUrl);

                    }
                    else
                    {
                        Alert.Show("Error occured while inserting employee information");
                    }
                }
                else
                {
                    aEmployee.EmployeeId = int.Parse(lblId.Text);
                    aAddresses.SourceId = aEmployee.EmployeeId;
                    aAddresses.AddressId = long.Parse(addlblId.Text);
                   int chk3= aEmployee.UpdateEmployee();
                    int chk1=aAddresses.UpdateAddresses();
                    if(chk3>0&&chk1>0)
                        Response.Redirect("EmployeeList.aspx",true);

                }

            }
            catch (Exception exp)
            {
                Alert.Show(exp.Message);
            }
        }
        private void LoadEmployeeListTable()
        {
            try
            {
                Addresses tempAddres = new Addresses();
                Designation tempDesignation = new Designation();
                Department tempDepartment = new Department();
                Employee objEmployee = new Employee();
                List<Employee> objEmployeeList = objEmployee.GetAllEmployee(_company.CompanyId);
                foreach (Employee employee in objEmployeeList)
                {

                    List<Addresses> objAddressList = tempAddres.GetAllAddresses(_company.CompanyId);
                    Designation aDesignation = tempDesignation.GetDesignationByDesignationId(employee.DesignationId,_company.CompanyId);
                    Department aDepartment = tempDepartment.GetDepartmentByDepartmentId(employee.DepartmentId,
                        _company.CompanyId);
                    employee.DepartmentName = aDepartment.DepartmentName;
                    employee.DesignationName = aDesignation.Designation;
                    employee.DOB = DateTime.Parse(employee.DOB).ToShortDateString();
                    employee.JoinDate = DateTime.Parse(employee.JoinDate).ToShortDateString();
                    List<string> countrList = Country.CountryList();

                    foreach (Addresses anAddresses in objAddressList)
                    {
                        if (anAddresses.SourceType == "Employee" && anAddresses.SourceId == employee.EmployeeId)
                        {
                            employee.AddressLine1 = anAddresses.AddressLine1;
                            employee.AddressLine2 = anAddresses.AddressLine2;
                            employee.City = anAddresses.City;
                            employee.ZipCode = anAddresses.ZipCode;
                            employee.Phone = anAddresses.Phone;
                            employee.Mobile = anAddresses.Mobile;
                            employee.Email = anAddresses.Email;
                            employee.CountryName = countrList[anAddresses.CountryId];
                            break;

                        }

                    }
                    RadGrid1.DataSource = objEmployeeList;
                    RadGrid1.Rebind();

                }
            }
            catch (Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        protected void btnShippingInformationSave_Click(object sender, EventArgs e)
        {
            try
            {

                Addresses shippingAddress = new Addresses();
                List<Addresses> addressList = shippingAddress.GetAllAddresses(_company.CompanyId);
                Addresses tempAddress = addressList[addressList.Count - 1];
                long id = tempAddress.AddressId + 1;
                shippingAddress.AddressId = id;

                shippingAddress.SourceId = user.UserId;
                shippingAddress.SourceType = "Company";
                shippingAddress.AddressType = "Shipping Address";
                shippingAddress.AddressLine1 = txtShippingaddressLine1.Value;
                shippingAddress.AddressLine2 = txtShippingaddressLine2.Value;
                shippingAddress.City = txtShippingCity.Value;
                shippingAddress.ZipCode = txtShippingZipCode.Value;
                shippingAddress.CountryId = int.Parse(shippingCountryDropDownList.SelectedIndex.ToString());
                shippingAddress.Phone = txtShippingPhone.Value;
                shippingAddress.Mobile = txtShippingMobile.Value;
                shippingAddress.Email = txtShippingEmail.Value;
                shippingAddress.Web = txtShippingWeb.Value;
                shippingAddress.CompanyId = _company.CompanyId;
                int save = shippingAddress.InsertAddresses();
                if (save > 0)
                {
                    Session["savedAddressMessage"] = "Address saved successfully";
                    Response.Redirect(Request.RawUrl);

                }
                else
                {
                    Alert.Show("Error Occured while inserting a new user");
                }
            }
            catch (Exception exp)
            {

                Alert.Show(exp.Message);
            }
        }
        private void LoadCustomerTable()
        {
            try
            {
                Customer objCustomer = new Customer();
                objCustomerList = objCustomer.GetAllCustomer(_company.CompanyId);
                if (objCustomerList.Count == 0)
                {
                    objCustomerList.Add(new Customer());
                }
                foreach (Customer objCst in objCustomerList)
                {
                    List<string> countryList = Country.CountryList();
                    List<Addresses> addressList =new Addresses().GetAllAddresses(_company.CompanyId);
                    foreach (Addresses address in addressList)
                    {
                        if (address.SourceType == "Customer" && address.SourceId == objCst.CustomerId)
                        {
                            objCst.AddressId = address.AddressId;
                            objCst.AddressLine1 = address.AddressLine1;
                            objCst.AddressLine2 = address.AddressLine2;
                            objCst.AddressType = address.AddressType;
                            objCst.City = address.City;
                            objCst.ZipCode = address.ZipCode;
                            objCst.Phone = address.Phone;
                            objCst.Mobile = address.Mobile;
                            objCst.Email = address.Email;
                            objCst.Web = address.Web;
                            objCst.CountryName = countryList[address.CountryId];

                            break;
                        }

                    }

                }
                RadGrid1.DataSource = objCustomerList;
                RadGrid1.Rebind();

            }
            catch (Exception ex)
            {

                Alert.Show(ex.Message);

            }
        }