Exemplo n.º 1
0
        protected void uiLinkButtonAdd_Click(object sender, EventArgs e)
        {
            Companies currentCompany = new Companies();
            currentCompany.GetCompanyByUserName(Page.User.Identity.Name);
            if (uiFileUpload.HasFile)
            {
                DirectoryInfo Dir = new DirectoryInfo(Server.MapPath("~/FileUploads/Companies/" + currentCompany.CompanyID.ToString()));
                if (!Dir.Exists)
                    Dir.Create();

                uiFileUpload.SaveAs(Server.MapPath("~/FileUploads/Companies/" + currentCompany.CompanyID.ToString() + "/" + uiFileUpload.FileName));
                currentCompany.SchedulePath = "/FileUploads/Companies/" + currentCompany.CompanyID.ToString() + "/" + uiFileUpload.FileName;
                currentCompany.Save();
                uiLabelmsg.Visible = true;
            }
        }
Exemplo n.º 2
0
        protected void uiButtonUpdate_Click(object sender, EventArgs e)
        {
            string filepath = "";
            if (uiFileUploadLogoPath.HasFile)
            {
                uiFileUploadLogoPath.SaveAs(Server.MapPath("~/FileUploads/Companies" + "/" + uiFileUploadLogoPath.FileName));
                filepath = "/Fileuploads/Companies" + "/" + uiFileUploadLogoPath.FileName;
            }

            if (CurrentCompany != null)
            {
                Companies objData = CurrentCompany;
                string temp = objData.LogoPath;
                objData.EnName = uiTextBoxEnName.Text;
                objData.ArName = uiTextBoxArName.Text;
                objData.EnAddress = uiTextBoxEnAddress.Text;
                objData.ArAddress = uiTextBoxArAddress.Text;
                objData.Tele = uiTextBoxTele.Text;
                objData.Fax = uiTextBoxFax.Text;
                try
                {
                    objData.Rank = Convert.ToInt32(uiTextBoxRank.Text);
                }
                catch (Exception ee)
                {
                    objData.Rank = 0;
                }
                objData.CityID = Convert.ToInt32(uiDropDownListCity.SelectedValue);
                objData.CategoryID = Convert.ToInt32(uiDropDownListCategory.SelectedValue);
                if (!string.IsNullOrEmpty(uiDropDownListSubCategory.SelectedValue))
                {
                    objData.SubCategoryID = Convert.ToInt32(uiDropDownListSubCategory.SelectedValue);
                }
                objData.PackageTypeID = Convert.ToInt32(uiDropDownListPackages.SelectedValue);
                if (!string.IsNullOrEmpty(filepath))
                {
                    objData.LogoPath = filepath;
                }
                objData.Save();

                CompanyEnabledOptions option = new CompanyEnabledOptions();
                option.GetCompanyEnabledOptionsByCompanyID(objData.CompanyID);
                foreach (ListItem item in uiCheckBoxListPackageOptions.Items)
                {
                    bool found = false;
                    for (int i = 0; i < option.RowCount; i++)
                    {
                        if (item.Value == option.PackageOptionID.ToString())
                        {
                            option.Enabled = item.Selected;
                            found = true;
                        }
                        if (found)
                        { break; }
                    }
                    if (!found)
                    {
                        option.AddNew();
                        option.CompanyID = objData.CompanyID;
                        option.PackageOptionID = Convert.ToInt32(item.Value);
                        option.Enabled = item.Selected;

                    }
                    option.MoveNext();
                }
                option.Save();

            }
            else
            {
                MembershipCreateStatus obj;
                MembershipUser objUser = Membership.CreateUser(uiTextBoxUserName.Text, uiTextBoxPassword.Text, "*****@*****.**", null, null, true, out obj);
                bool success = true;
                switch (obj)
                {
                    case MembershipCreateStatus.DuplicateUserName:
                        uiLabelError.Text = "duplicate username";
                        uiLabelError.Visible = true;
                        success = false;
                        break;
                    case MembershipCreateStatus.InvalidPassword:
                        uiLabelError.Text = "invalid password. password must be (6) characters or more.";
                        uiLabelError.Visible = true;
                        success = false;
                        break;
                    case MembershipCreateStatus.ProviderError:
                    case MembershipCreateStatus.UserRejected:
                        uiLabelError.Text = "an error occurred. please try again.";
                        uiLabelError.Visible = true;
                        success = false;
                        break;
                    default:
                        break;
                }
                if (!Roles.IsUserInRole(uiTextBoxUserName.Text, "Company"))
                {
                    Roles.AddUserToRole(uiTextBoxUserName.Text, "Company");
                }

                if (success)
                {
                    Companies objData = new Companies();
                    objData.AddNew();
                    objData.EnName = uiTextBoxEnName.Text;
                    objData.ArName = uiTextBoxArName.Text;
                    objData.EnAddress = uiTextBoxEnAddress.Text;
                    objData.ArAddress = uiTextBoxArAddress.Text;
                    objData.Tele = uiTextBoxTele.Text;
                    objData.Fax = uiTextBoxFax.Text;
                    objData.CityID = Convert.ToInt32(uiDropDownListCity.SelectedValue);
                    objData.CategoryID = Convert.ToInt32(uiDropDownListCategory.SelectedValue);
                    if (!string.IsNullOrEmpty(uiDropDownListSubCategory.SelectedValue))
                    {
                        objData.SubCategoryID = Convert.ToInt32(uiDropDownListSubCategory.SelectedValue);
                    }
                    objData.LogoPath = filepath;
                    objData.UserName = uiTextBoxUserName.Text;
                    objData.PackageTypeID = Convert.ToInt32(uiDropDownListPackages.SelectedValue);
                    try
                    {
                        objData.Rank = Convert.ToInt32(uiTextBoxRank.Text);
                    }
                    catch (Exception ee)
                    {
                        objData.Rank = 0;
                    }
                    objData.Save();
                    CompanyEnabledOptions option = new CompanyEnabledOptions();
                    foreach (ListItem item in uiCheckBoxListPackageOptions.Items)
                    {

                        option.AddNew();
                        option.PackageOptionID = Convert.ToInt32(item.Value);
                        option.CompanyID = objData.CompanyID;
                        option.Enabled = item.Selected;

                    }
                    option.Save();
                }
                else
                {
                    return;
                }

            }

            uiPanelEdit.Visible = false;
            uiPanelViewCompanies.Visible = true;
            BindData();
            Clearfields();

            CurrentCompany = null;
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 5
0
        protected void uiButtonUpdate_Click(object sender, EventArgs e)
        {
            Companies currentCompany = new Companies();
            currentCompany.GetCompanyByUserName(Page.User.Identity.Name);
            CompanyEnabledOptions options = new CompanyEnabledOptions();
            options.GetCompanyEnabledOptionsByCompanyID(currentCompany.CompanyID);

            currentCompany.EnName = uiTextBoxEnName.Text ;
            currentCompany.ArName = uiTextBoxArName.Text ;
            currentCompany.EnAddress = uiTextBoxEnAddress.Text;
            currentCompany.ArAddress = uiTextBoxArAddress.Text;
            currentCompany.Tele = uiTextBoxTele.Text ;
            currentCompany.Fax = uiTextBoxFax.Text;

            for (int i = 0; i < options.RowCount; i++)
            {
                switch (options.PackageOptionID)
                {
                    case 1:
                        if (options.Enabled)
                        {
                            if (uiFileUploadLogoPath.HasFile)
                            {
                                uiFileUploadLogoPath.SaveAs(Server.MapPath("~/FileUploads/Companies" + "/" + uiFileUploadLogoPath.FileName));
                                currentCompany.LogoPath = "/FileUploads/Companies" + "/" + uiFileUploadLogoPath.FileName;
                            }
                        }
                        break;
                    case 7:
                        if (options.Enabled)
                            currentCompany.WebSite = uiTextBoxWebSite.Text;
                        break;
                    case 8:
                        if (options.Enabled)
                        {
                            currentCompany.EnBranches = Server.HtmlEncode(uiFCKeditorEnBranches.Value);
                            currentCompany.ArBranches  = Server.HtmlEncode(uiFCKeditorArBranches.Value);
                        }
                        break;
                    case 9:
                        if (options.Enabled)
                            currentCompany.MapPath = Server.HtmlEncode(uiTextBoxMapURL.Text);
                        break;
                    case 10:
                        if (options.Enabled)
                        {
                            currentCompany.EnAbout = Server.HtmlEncode(uiFCKeditorEnAbout.Value);
                            currentCompany.ArAbout = Server.HtmlEncode(uiFCKeditorArAbout.Value);
                        }
                        break;
                    case 15:
                        if (options.Enabled)
                        {
                            currentCompany.EnContact = Server.HtmlEncode(uiFCKeditorEnContacts.Value);
                            currentCompany.ArContact = Server.HtmlEncode(uiFCKeditorArContacts.Value);
                        }
                        break;
                    default:
                        break;
                }

                options.MoveNext();
            }

            currentCompany.Save();
        }