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