protected void uiGridViewCompanies_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "EditCompany")
            {
                Companies objData = new Companies();
                objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));
                uiTextBoxEnName.Text = objData.EnName;
                uiTextBoxArName.Text = objData.ArName;
                uiTextBoxEnAddress.Text = objData.EnAddress;
                uiTextBoxArAddress.Text = objData.ArAddress;
                uiTextBoxTele.Text = objData.Tele;
                uiTextBoxFax.Text = objData.Fax;
                uiDropDownListCity.SelectedValue = objData.CityID.ToString();
                uiDropDownListCategory.SelectedValue = objData.CategoryID.ToString();
                if (!objData.IsColumnNull("SubCategoryID"))
                {
                    uiDropDownListSubCategory.SelectedValue = objData.SubCategoryID.ToString();
                }
                uiImageLogo.ImageUrl = objData.LogoPath;
                uiLinkButtonResetPassword.Enabled = true;
                uiTextBoxUserName.Text = objData.UserName;
                uiTextBoxPassword.TextMode = TextBoxMode.SingleLine;
                uiTextBoxPassword.Text = Membership.GetUser(objData.UserName).GetPassword();
                uiTextBoxPassword.Enabled = false;
                uiTextBoxUserName.Enabled = false;

                if (!objData.IsColumnNull("PackageTypeID"))
                {
                    uiDropDownListPackages.SelectedValue = objData.PackageTypeID.ToString();
                }
                //  load packjage
                CompanyEnabledOptions options = new CompanyEnabledOptions();
                options.GetCompanyEnabledOptionsByCompanyID(Convert.ToInt32(e.CommandArgument.ToString()));
                for (int i = 0; i < options.RowCount; i++)
                {
                    foreach (ListItem item in uiCheckBoxListPackageOptions.Items)
                    {
                        if (item.Value == options.PackageOptionID.ToString())
                        {
                            item.Selected = options.Enabled;
                            break;
                        }

                    }
                    options.MoveNext();
                }

                uiPanelViewCompanies.Visible = false;
                uiPanelEdit.Visible = true;
                CurrentCompany = objData;
            }
            else if (e.CommandName == "DeleteCompany")
            {

                Companies objData = new Companies();
                objData.LoadByPrimaryKey(Convert.ToInt32(e.CommandArgument.ToString()));

                if (Membership.GetUser(objData.UserName) != null)
                {
                    Membership.DeleteUser(objData.UserName);
                }

                CompanyEnabledOptions options = new CompanyEnabledOptions();
                options.GetCompanyEnabledOptionsByCompanyID(objData.CompanyID);
                options.DeleteAll();
                options.Save();

                Photos pics = new Photos();
                pics.GetPhotosByCompanyID(objData.CompanyID);
                pics.DeleteAll();
                pics.Save();

                BLL.Vedios videos = new BLL.Vedios();
                videos.GetVedioByCompanyID(objData.CompanyID);
                videos.DeleteAll();
                videos.Save();

                objData.MarkAsDeleted();
                objData.Save();

                BindData();
                uiPanelViewCompanies.Visible = true;
                uiPanelEdit.Visible = false;
            }
        }
        protected void uiButtonUpdate_Click(object sender, EventArgs e)
        {
            if (uiFileUpload.HasFile)
            {
                ArrayList notUploaded = new ArrayList();
                uiFileUpload.SaveAs(Server.MapPath("~/FileUploads/" + uiFileUpload.FileName));
                string connectionString = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0;HDR=NO;""", Server.MapPath("~/FileUploads/" + uiFileUpload.FileName));

                string strSQL = "SELECT * FROM [ورقة1$]";
                OleDbConnection excelConnection = new OleDbConnection(connectionString);
                excelConnection.Open();
                OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection);
                OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand);

                DataTable dTable = new DataTable();

                dataAdapter.Fill(dTable);
                Companies objData = new Companies();
                foreach (DataRow item in dTable.Rows)
                {

                    MembershipCreateStatus obj;
                    string Username = item[1].ToString().Replace(" ", "");
                    Username = Username.Replace("&", "");
                    string Password = "";
                    if (Username.Length > 10)
                    {
                        Password = Username.Substring(0,10);
                    }
                    else
                    {
                        Password = Username;
                    }

                    if (Password.Length < 6)
                    {
                        Password = Password + Password;
                    }
                    MembershipUser objUser = Membership.CreateUser(Username, Password, "*****@*****.**", null, null, true, out obj);
                    bool success = true;
                    switch (obj)
                    {
                        case MembershipCreateStatus.DuplicateUserName:
                            success = false;
                            break;
                        case MembershipCreateStatus.InvalidPassword:
                            success = false;
                            break;
                        case MembershipCreateStatus.ProviderError:
                        case MembershipCreateStatus.UserRejected:
                            success = false;
                            break;
                        default:
                            break;
                    }
                    try
                    {

                        if (!Roles.IsUserInRole(Username, "Company"))
                        {
                            Roles.AddUserToRole(Username, "Company");
                        }
                    }
                    catch (Exception ex)
                    {
                        uiLabelError.Text += "001";
                        uiLabelError.Visible = true;
                    }

                    if (success)
                    {
                        try
                        {

                            objData.AddNew();
                            objData.EnName = item[1].ToString();
                            objData.ArName = item[0].ToString();
                            objData.EnAddress = item[3].ToString();
                            objData.ArAddress = item[2].ToString();
                            objData.Rank = 0;
                            try
                            {
                                objData.Tele = item[4].ToString();
                            }
                            catch (Exception ex)
                            {
                            }
                            try
                            {
                                objData.Fax = item[5].ToString();
                            }
                            catch (Exception ex)
                            {
                            }

                            objData.CityID = Convert.ToInt32(uiDropDownListCity.SelectedValue);
                            objData.CategoryID = Convert.ToInt32(uiDropDownListCategory.SelectedValue);
                            if(!string.IsNullOrEmpty(uiDropDownListSubCategory.SelectedValue))
                                objData.SubCategoryID = Convert.ToInt32(uiDropDownListSubCategory.SelectedValue);
                            objData.UserName = Username;

                        }
                        catch (Exception ex)
                        {
                            uiLabelError.Visible = true;
                            Membership.DeleteUser(Username);
                            notUploaded.Add(item[1].ToString() + " - " + ex.Message);
                            objData.MarkAsDeleted();
                        }
                    }
                    else
                    {
                        notUploaded.Add(item[1].ToString() + " - " + obj.ToString());
                        continue;
                    }
                }
                objData.Save();

                if (notUploaded.Count < dTable.Rows.Count)
                    uiLabelmsg.Visible = true;

                uiGridViewLog.DataSource = notUploaded;
                uiGridViewLog.Columns[0].HeaderText = "These items faild to insert";
                uiGridViewLog.DataBind();
            }
        }