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 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 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();
 }
        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 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 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;

                    }
                }

            }
        }