protected void uiButtonSearch_Click(object sender, EventArgs e)
 {
     SubCategories objData = new SubCategories();
     objData.GetAllSubCategoriesByCategory(Convert.ToInt32(uiDropDownListAllCategories.SelectedValue));
     uiGridViewSubCategories.DataSource = objData.DefaultView;
     uiGridViewSubCategories.DataBind();
 }
 protected void uiDropDownListCategory_SelectedIndexChanged(object sender, EventArgs e)
 {
     SubCategories objSubCategories = new SubCategories();
     objSubCategories.GetAllSubCategoriesByCategory(Convert.ToInt32(uiDropDownListCategory.SelectedValue));
     uiDropDownListSubCategory.DataSource = objSubCategories.DefaultView;
     uiDropDownListSubCategory.DataTextField = "ArName";
     uiDropDownListSubCategory.DataValueField = "SubCategoryID";
     uiDropDownListSubCategory.DataBind();
     uiDropDownListSubCategory.Items.Insert(0, new ListItem("إختر قطاع العمل الفرعى", "0"));
 }
        private void LoadSubcatsForShipping(int catid)
        {
            PagedDataSource dt = new PagedDataSource();
            SubCategories objData = new SubCategories();
            objData.GetSubCategoriesForShipping(catid);

            dt.DataSource = objData.DefaultView;
            dt.AllowPaging = true;
            dt.PageSize = 10;
            dt.CurrentPageIndex = PageIndex;
            if (objData.RowCount > 0 && dt != null)
            {
                uiDataListSubCats.DataSource = dt;
                uiDataListSubCats.DataBind();
                uiLinkButtonPrev.Enabled = !dt.IsFirstPage;
                uiLinkButtonNext.Enabled = !dt.IsLastPage;
                uiLabelPages.Text = "صفحة " + (PageIndex + 1).ToString() + " من " + dt.PageCount.ToString() + " صفحات";
                uiPanelNoResults.Visible = false;
                uiPanelCategories.Visible = true;
                uiPanelResults.Visible = false;
            }
            else
            {
                uiPanelCategories.Visible = false;
                uiPanelNoResults.Visible = true;
                uiPanelResults.Visible = false;
            }
        }
        private void LoadCompanies(int catid, int subcatid)
        {
            PagedDataSource dt = new PagedDataSource();
            Companies objData = new Companies();
            objData.SearchCompanies("", 0, catid, subcatid);
            Categories cat = new Categories();
            cat.LoadByPrimaryKey(catid);
            SubCategories subcat = new SubCategories();
            subcat.LoadByPrimaryKey(subcatid);

            dt.DataSource = objData.DefaultView;
            dt.AllowPaging = true;
            dt.PageSize = 10;
            dt.CurrentPageIndex = PageIndex;
            if (objData.RowCount > 0 && dt != null)
            {
                if (cat.RowCount > 0)
                    uiLabelTitle.Text = " - " + cat.ArName;
                if (subcat.RowCount > 0)
                    uiLabelTitle.Text += " -> " + subcat.ArName;

                uiRepeaterResults.DataSource = dt;
                uiRepeaterResults.DataBind();
                uiLinkButtonPrev.Enabled = !dt.IsFirstPage;
                uiLinkButtonNext.Enabled = !dt.IsLastPage;
                uiLabelPages.Text = "صفحة " + (PageIndex + 1).ToString() + " من " + dt.PageCount.ToString() + " صفحات";
                uiPanelNoResults.Visible = false;
                uiPanelResults.Visible = true;
                uiPanelCategories.Visible = false;
            }
            else
            {
                uiPanelNoResults.Visible = true;
                uiPanelResults.Visible = false;
                uiPanelCategories.Visible = false;
            }
        }
        private void LoadDDLs()
        {
            Cities objCities = new Cities();
            objCities.LoadAll();
            uiDropDownListCity.DataSource = objCities.DefaultView;
            uiDropDownListCity.DataTextField = "ArName";
            uiDropDownListCity.DataValueField = "CityID";
            uiDropDownListCity.DataBind();

            Categories objCats = new Categories();
            objCats.LoadAll();
            uiDropDownListCategory.DataSource = objCats.DefaultView;
            uiDropDownListCategory.DataTextField = "ArName";
            uiDropDownListCategory.DataValueField = "CategoryID";
            uiDropDownListCategory.DataBind();

            SubCategories objSubCat = new SubCategories();
            objSubCat.LoadAll();
            uiDropDownListSubCategory.DataSource = objSubCat.DefaultView;
            uiDropDownListSubCategory.DataTextField = "ArName";
            uiDropDownListSubCategory.DataValueField = "SubCategoryID";
            uiDropDownListSubCategory.DataBind();

            Packages objPackages = new Packages();
            objPackages.LoadAll();
            uiDropDownListPackages.DataSource = objPackages.DefaultView;
            uiDropDownListPackages.DataTextField = "EnName";
            uiDropDownListPackages.DataValueField = "PackageID";
            uiDropDownListPackages.DataBind();

            uiDropDownListCategoryFilter.DataSource = objCats.DefaultView;
            uiDropDownListCategoryFilter.DataTextField = "ArName";
            uiDropDownListCategoryFilter.DataValueField = "CategoryID";
            uiDropDownListCategoryFilter.DataBind();
            uiDropDownListCategoryFilter.Items.Insert(0, new ListItem("Select Category", "0"));
        }
        protected void uiRepeaterDir_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView row = (DataRowView)e.Item.DataItem;
                int catid = Convert.ToInt32(row["CategoryID"].ToString());

                SubCategories sub = new SubCategories();
                sub.GetAllSubCategoriesByCategory(catid);

                Literal subs = (Literal)e.Item.FindControl("uiLiteralSub");

                if (sub.RowCount > 0)
                {
                    subs.Text = "<ul>";
                    for (int i = 0; i < sub.RowCount; i++)
                    {
                        subs.Text += "<li><a href=\"/Directory.aspx?cid=" + catid.ToString() + "&scid=" + sub.SubCategoryID.ToString() + "\" >" + sub.ArName + "</a></li>";
                        sub.MoveNext();
                    }
                    subs.Text += "</ul>";
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int compId = 0;
                if (Request.QueryString["cid"] != null)
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["cid"].ToString()))
                    {
                        try
                        {
                            compId = Convert.ToInt32(Request.QueryString["cid"].ToString());
                        }
                        catch (Exception ex)
                        {
                            compId = 0;
                        }
                    }
                }

                if (compId == 0)
                {
                    Response.Redirect("~/Default.aspx");
                }
                else
                {
                    Companies current = new Companies();
                    current.LoadByPrimaryKey(compId);

                    uiLabelCompanyName.Text = current.EnName;
                    Categories cat = new Categories();
                    cat.LoadByPrimaryKey(current.CategoryID);
                    SubCategories subcat = new SubCategories();
                    subcat.LoadByPrimaryKey(current.SubCategoryID);

                    string path = "";
                    if(cat.RowCount > 0 )
                        path += cat.EnName;
                    if (subcat.RowCount > 0)
                        path += " -> " + subcat.EnName;

                    Master.Page.Title += "Global Logistics" + " -> " + path + " -> " + current.EnName;
                    uiLabelPath.Text = path + " ->";

                    CompanyEnabledOptions options = new CompanyEnabledOptions();
                    options.GetCompanyEnabledOptionsByCompanyID(compId);

                    for (int i = 0; i < options.RowCount; i++)
                    {
                        switch (options.PackageOptionID)
                        {

                            case 7:
                                if (options.Enabled)
                                {
                                    LIWebsite.Attributes.Add("style", "display:block");
                                    uiHyperLinkWebsite.Text = current.WebSite;
                                    uiHyperLinkWebsite.NavigateUrl = current.WebSite;
                                    CompanyTabs_12.Attributes.Add("style", "display:block");
                                }
                                else
                                {
                                    LIWebsite.Attributes.Add("style", "display:none");
                                    CompanyTabs_12.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 8:
                                if (options.Enabled)
                                {
                                    LIBranch.Attributes.Add("style", "display:block");
                                    CompanyTabs_2.Attributes.Add("style", "display:block");
                                    uiLiteralBranches.Text = Server.HtmlDecode(current.EnBranches);
                                }
                                else
                                {
                                    CompanyTabs_2.Attributes.Add("style", "display:none");
                                    LIBranch.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 9:
                                if (options.Enabled)
                                {
                                    LIMap.Attributes.Add("style", "display:block");
                                    CompanyTabs_3.Attributes.Add("style", "display:block");
                                    uiLiteralMap.Text = Server.HtmlDecode(current.MapPath);
                                }
                                else
                                {
                                    LIMap.Attributes.Add("style", "display:none");
                                    CompanyTabs_3.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 10:
                                if (options.Enabled)
                                {
                                    CompanyTabs_1.Attributes.Add("style", "display:block");
                                    LIAbout.Attributes.Add("style", "display:block");
                                    uiLiteralAbout.Text = Server.HtmlDecode(current.EnAbout);
                                }
                                else
                                {
                                    LIAbout.Attributes.Add("style", "display:none");
                                    CompanyTabs_1.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 11:
                                if (options.Enabled)
                                {
                                    CompanyTabs_5.Attributes.Add("style", "display:block");
                                    LIOffers.Attributes.Add("style", "display:block");
                                    Services offers = new Services();
                                    offers.GetServicesByCompanyIDAndTypeID(current.CompanyID, 1);
                                    if (offers.RowCount > 0)
                                    {
                                        uiRepeaterOffers.DataSource = offers.DefaultView;
                                        uiRepeaterOffers.DataBind();
                                    }
                                    else
                                    {
                                        uiLiteralOffers.Text = "No Offers found.";
                                    }

                                }
                                else
                                {
                                    LIOffers.Attributes.Add("style", "display:none");
                                    CompanyTabs_5.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 12:
                                if (options.Enabled)
                                {
                                    CompanyTabs_6.Attributes.Add("style", "display:block");
                                    LIRequests.Attributes.Add("style", "display:block");
                                    Services requests = new Services();
                                    requests.GetServicesByCompanyIDAndTypeID(current.CompanyID, 6);
                                    if (requests.RowCount > 0)
                                    {
                                        uiRepeaterRequests.DataSource = requests.DefaultView;
                                        uiRepeaterRequests.DataBind();
                                    }
                                    else
                                    {
                                        uiLiteralRequests.Text = "No requests found.";
                                    }
                                }
                                else
                                {
                                    LIRequests.Attributes.Add("style", "display:none");
                                    CompanyTabs_6.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 13:
                                if (options.Enabled)
                                {
                                    CompanyTabs_7.Attributes.Add("style", "display:block");
                                    LIJobs.Attributes.Add("style", "display:block");
                                    Services jobs = new Services();
                                    jobs.GetServicesByCompanyIDAndTypeID(current.CompanyID, 3);
                                    if (jobs.RowCount > 0)
                                    {
                                        uiRepeaterJobs.DataSource = jobs.DefaultView;
                                        uiRepeaterJobs.DataBind();
                                    }
                                    else
                                    {
                                        uiLiteralJobs.Text = "No jobs found.";
                                    }
                                }
                                else
                                {
                                    LIJobs.Attributes.Add("style", "display:none");
                                    CompanyTabs_7.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 14:
                                if (options.Enabled)
                                {
                                    CompanyTabs_4.Attributes.Add("style", "display:block");
                                    LIServices.Attributes.Add("style", "display:block");
                                    Services services = new Services();
                                    services.GetServicesByCompanyIDAndTypeID(current.CompanyID, 7);
                                    if (services.RowCount > 0)
                                    {
                                        uiRepeaterService.DataSource = services.DefaultView;
                                        uiRepeaterService.DataBind();
                                    }
                                    else
                                    {
                                        uiLiteralServices.Text = "No services found.";
                                    }
                                }
                                else
                                {
                                    LIServices.Attributes.Add("style", "display:none");
                                    CompanyTabs_4.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 15:
                                if (options.Enabled)
                                {
                                    LIContacts.Attributes.Add("style", "display:block");
                                    CompanyTabs_11.Attributes.Add("style", "display:block");
                                    uiLiteralContacts.Text = Server.HtmlDecode(current.EnContact);
                                }
                                else
                                {
                                    LIContacts.Attributes.Add("style", "display:none");
                                    CompanyTabs_11.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 17:
                                if (options.Enabled)
                                {
                                    LIPic.Attributes.Add("style", "display:block");
                                    CompanyTabs_8.Attributes.Add("style", "display:block");
                                    Photos pics = new Photos();
                                    pics.GetPhotosByCompanyID(current.CompanyID);
                                    uiDataListPhotos.DataSource = pics.DefaultView;
                                    uiDataListPhotos.DataBind();
                                }
                                else
                                {
                                    LIPic.Attributes.Add("style", "display:none");
                                    CompanyTabs_8.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 16:
                                if (options.Enabled)
                                {
                                    LIVideos.Attributes.Add("style", "display:block");
                                    CompanyTabs_9.Attributes.Add("style", "display:block");
                                    BLL.Vedios Videos = new BLL.Vedios();
                                    Videos.GetVedioByCompanyID(current.CompanyID);
                                    uiDataListVideos.DataSource = Videos.DefaultView;
                                    uiDataListVideos.DataBind();
                                }
                                else
                                {
                                    LIVideos.Attributes.Add("style", "display:none");
                                    CompanyTabs_9.Attributes.Add("style", "display:none");
                                }
                                break;
                            case 19:
                                if (options.Enabled)
                                {
                                    LISchedule.Attributes.Add("style", "display:block");
                                    CompanyTabs_10.Attributes.Add("style", "display:block");
                                    if (!string.IsNullOrEmpty(current.SchedulePath))
                                        uiLiteralSchedule.Text = "<a href='" + current.SchedulePath + "' >Click here to download schedule</a>";
                                    else
                                        uiLiteralSchedule.Text = "No schedule found.";
                                }
                                else
                                {
                                    LISchedule.Attributes.Add("style", "display:none");
                                    CompanyTabs_10.Attributes.Add("style", "display:none");
                                }
                                break;
                            default:
                                break;
                        }

                        options.MoveNext();
                    }
                }
            }
        }
        private void LoadDDLs()
        {
            Cities objCities = new Cities();
            objCities.LoadAll();
            uiDropDownListCity.DataSource = objCities.DefaultView;
            uiDropDownListCity.DataTextField = "ArName";
            uiDropDownListCity.DataValueField = "CityID";
            uiDropDownListCity.DataBind();

            Categories objCats = new Categories();
            objCats.LoadAll();
            uiDropDownListCategory.DataSource = objCats.DefaultView;
            uiDropDownListCategory.DataTextField = "ArName";
            uiDropDownListCategory.DataValueField = "CategoryID";
            uiDropDownListCategory.DataBind();
            uiDropDownListCategory.SelectedIndex = 0;

            SubCategories objSubCat = new SubCategories();
            objSubCat.GetAllSubCategoriesByCategory(Convert.ToInt32(uiDropDownListCategory.SelectedValue));
            uiDropDownListSubCategory.DataSource = objSubCat.DefaultView;
            uiDropDownListSubCategory.DataTextField = "ArName";
            uiDropDownListSubCategory.DataValueField = "SubCategoryID";
            uiDropDownListSubCategory.DataBind();
        }
 protected void uiDropDownListCategory_SelectedIndexChanged(object sender, EventArgs e)
 {
     SubCategories objSubCat = new SubCategories();
     objSubCat.GetAllSubCategoriesByCategory(Convert.ToInt32(uiDropDownListCategory.SelectedValue));
     uiDropDownListSubCategory.DataSource = objSubCat.DefaultView;
     uiDropDownListSubCategory.DataTextField = "ArName";
     uiDropDownListSubCategory.DataValueField = "SubCategoryID";
     uiDropDownListSubCategory.DataBind();
 }
 protected void uiGridViewSubCategories_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "EditSubCategory")
     {
         SubCategories objData = new SubCategories();
         objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
         uiTextBoxEnName.Text = objData.EnName;
         uiTextBoxArName.Text = objData.ArName;
         uiTextBoxEnDesc.Text = objData.EnDescription;
         uiTextBoxArDesc.Text = objData.ArDescription;
         uiDropDownListAllCategories.SelectedValue = objData.CategoryID.ToString();
         uiPanelViewSubCategories.Visible = false;
         uiPanelEdit.Visible = true;
         CurrentSubCategory = objData;
         uiPanelViewSubCategories.Visible = false;
         uiPanelEdit.Visible = true;
     }
     else if (e.CommandName == "DeleteSubCategory")
     {
         SubCategories objData = new SubCategories();
         objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
         objData.MarkAsDeleted();
         objData.Save();
         CurrentSubCategory = null;
         BindData();
     }
 }
 private void BindData()
 {
     SubCategories objData = new SubCategories();
     objData.GetAllSubCategoriesByCategory(Convert.ToInt32(uiDropDownListAllCategories.SelectedValue));
     uiGridViewSubCategories.DataSource = objData.DefaultView;
     uiGridViewSubCategories.DataBind();
 }
 private void AddNewRecord()
 {
     SubCategories objData = new SubCategories();
     objData.AddNew();
     objData.EnName = uiTextBoxEnName.Text;
     objData.ArName = uiTextBoxArName.Text;
     objData.EnDescription = uiTextBoxEnDesc.Text;
     objData.ArDescription = uiTextBoxArDesc.Text;
     objData.CategoryID = Convert.ToInt32(uiDropDownListAllCategories.SelectedValue);
     string filepath = "";
     if (uiFileUploadLogoPath.HasFile)
     {
         uiFileUploadLogoPath.SaveAs(Server.MapPath("~/FileUploads/Categories" + "/" + uiFileUploadLogoPath.FileName));
         filepath = "/Fileuploads/Categories" + "/" + uiFileUploadLogoPath.FileName;
     }
     if (!string.IsNullOrEmpty(filepath))
     {
         objData.IconPath = filepath;
     }
     objData.Save();
 }
        private void BindData()
        {
            int catid = 0;
            if (Request.QueryString["cid"] != null)
            {
                try
                {
                    catid = Convert.ToInt32(Request.QueryString["cid"].ToString());
                }
                catch (Exception ex)
                {
                    catid = 0;
                }
            }

            int subcatid = 0;
            if (Request.QueryString["scid"] != null)
            {
                try
                {
                    subcatid = Convert.ToInt32(Request.QueryString["scid"].ToString());
                }
                catch (Exception ex)
                {
                    subcatid = 0;
                }
            }

            string searchfor = "";
            if (Request.QueryString["f"] != null)
            {
                try
                {
                    searchfor = Request.QueryString["f"].ToString();
                }
                catch (Exception ex)
                {
                    searchfor = "";
                }
            }

            PagedDataSource dt = new PagedDataSource();
            Companies objData = new Companies();
            if (!string.IsNullOrEmpty(searchfor) && searchfor == "sh")
                objData.SearchCompaniesForShipping(subcatid);
            else if (!string.IsNullOrEmpty(searchfor) && searchfor == "off")
            {
                objData.SearchCompaniesForOffers(catid, subcatid);
            }
            else
            {
                objData.SearchCompanies("", 0, catid, subcatid);
            }

            Categories cat = new Categories();
            cat.LoadByPrimaryKey(catid);
            SubCategories subcat = new SubCategories();
            subcat.LoadByPrimaryKey(subcatid);
            dt.DataSource = objData.DefaultView;
            dt.AllowPaging = true;
            dt.PageSize = 10;
            dt.CurrentPageIndex = PageIndex;
            if (objData.RowCount > 0 && dt != null)
            {
                if(cat.RowCount > 0 )
                    uiLabelTitle.Text = " - " + cat.EnName;
                if (subcat.RowCount > 0)
                    uiLabelTitle.Text += " -> " + subcat.EnName;

                uiRepeaterResults.DataSource = dt;
                uiRepeaterResults.DataBind();
                uiLinkButtonPrev.Enabled = !dt.IsFirstPage;
                uiLinkButtonNext.Enabled = !dt.IsLastPage;
                uiLabelPages.Text = "Page " + (PageIndex + 1).ToString() + " of " + dt.PageCount.ToString() + " Pages";
                uiPanelNoResults.Visible = false;
                uiPanelResults.Visible = true;
            }
            else
            {
                uiPanelNoResults.Visible = true;
                uiPanelResults.Visible = false;
            }
        }
        private void LoadSubcats(int catid)
        {
            PagedDataSource dt = new PagedDataSource();
            SubCategories objData = new SubCategories();
            objData.GetAllSubCategoriesByCategory(catid);
            Categories cat = new Categories();
            cat.LoadByPrimaryKey(catid);

            dt.DataSource = objData.DefaultView;
            dt.AllowPaging = true;
            dt.PageSize = 10;
            dt.CurrentPageIndex = PageIndex;
            if (objData.RowCount > 0 && dt != null)
            {
                if (cat.RowCount > 0)
                    uiLabelTitle.Text = " - " + cat.ArName;

                uiDataListSubCats.DataSource = dt;
                uiDataListSubCats.DataBind();
                uiLinkButtonPrev.Enabled = !dt.IsFirstPage;
                uiLinkButtonNext.Enabled = !dt.IsLastPage;
                uiLabelPages.Text = "Page " + (PageIndex + 1).ToString() + " of " + dt.PageCount.ToString() + " Pages";
                uiPanelNoResults.Visible = false;
                uiPanelCategories.Visible = true;
                uiPanelResults.Visible = false;
            }
            else
            {
                uiPanelCategories.Visible = false;
                uiPanelNoResults.Visible = true;
                uiPanelResults.Visible = false;
            }
        }