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