protected void lbtnNextStep_Click(object sender, EventArgs e) { try { string sss = Session["SetupASPNETID"].ToString(); Guid setASPNETID = Guid.Parse(Session["SetupASPNETID"].ToString()); int setAccId = Int32.Parse(Session["SetupAcountId"].ToString()); DictionaryModel.Account account = entities.Accounts.FirstOrDefault(acc => acc.ASPNETID == setASPNETID); if (hdnEditPersonalInformation.Value == "") //New Account { account.FirstName = txtFirstName.Text.Trim(); account.LastName = txtLastName.Text.Trim(); account.Country = Int32.Parse((ddlCountry.SelectedValue != "0") ? ddlCountry.SelectedValue :"27"); entities.SaveChanges(); if (StepCompleted != null) { NewAccountStepCompletedEventArgs args = new NewAccountStepCompletedEventArgs(NewAccountWizardSteps.PersonalInformation); args.ASPNETID = setASPNETID; args.CurrentAccountId = setAccId; args.CurrentCountryId = account.Country.Value; StepCompleted.Invoke(this, args); } } else // Edit Account { account.FirstName = txtFirstName.Text.Trim(); account.LastName = txtLastName.Text.Trim(); account.Country = Int32.Parse((ddlCountry.SelectedValue != "0") ? ddlCountry.SelectedValue : "27"); entities.SaveChanges(); if (StepCompleted != null) { NewAccountStepCompletedEventArgs args = new NewAccountStepCompletedEventArgs(NewAccountWizardSteps.PersonalInformation); args.ASPNETID = setASPNETID; args.CurrentAccountId = SetupAccountId; args.CurrentCountryId = account.Country.Value; StepCompleted.Invoke(this, args); } } } catch { lblError.Text = "Възникна проблем, моля опитайте по-късно."; } }
protected void GridViewAllWords_RowCommand(object sender, GridViewCommandEventArgs e) { int wordId; if (Int32.TryParse(e.CommandArgument.ToString(), out wordId)) { if (e.CommandName == "EditWord") { pnlExistingsWords.Visible = false; pnlEditWord.Visible = true; if (ddlLanguage.SelectedValue == "1") { DictionaryModel.English_Bulgarian word = entities.English_Bulgarian.FirstOrDefault(w => w.Id == wordId); txtWord.Text = word.Word; txtТranscription.Text = word.Тranscription == null ? string.Empty : word.Тranscription.Replace("]", "").Replace("[", ""); txtDescription.Text = word.Description; hdnCurrentWordId.Value = wordId.ToString(); } else if (ddlLanguage.SelectedValue == "2") { DictionaryModel.Bulgarian_English word = entities.Bulgarian_English.FirstOrDefault(w => w.Id == wordId); txtWord.Text = word.Word; txtТranscription.Text = word.Тranscription == null ? string.Empty : word.Тranscription.Replace("]", "").Replace("[", ""); txtDescription.Text = word.Description; hdnCurrentWordId.Value = wordId.ToString(); } } else if (e.CommandName == "DeleteWord") { if (ddlLanguage.SelectedValue == "1") { DictionaryModel.English_Bulgarian word = entities.English_Bulgarian.FirstOrDefault(w => w.Id == wordId); entities.DeleteObject(word); } else if (ddlLanguage.SelectedValue == "2") { DictionaryModel.Bulgarian_English word = entities.Bulgarian_English.FirstOrDefault(w => w.Id == wordId); entities.DeleteObject(word); } entities.SaveChanges(); DataBindGridViewAllWords(); lblResult.Text = "Думата е изтрита успешно."; } } }
protected void lbtnSaveChangePicture_Click(object sender, EventArgs e) { if (fuSource.HasFile) { int currentUserId = (Page as BasePage).CurrentAccountId; DictionaryModel.Account account = entities.Accounts.FirstOrDefault(acc => acc.Id == currentUserId); string fileExt = System.IO.Path.GetExtension(fuSource.PostedFile.FileName); if ((fuSource.PostedFile.ContentLength > 0) && (fuSource.PostedFile.ContentLength < 10000000)) { string currentTime = DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", ""); string fileName = fuSource.PostedFile.FileName; string fileDirectory = Server.MapPath("~/Files/FileUpload"); string SaveLocation = fileDirectory + "\\" + currentTime + fileName; //string displayedImgThumb = Server.MapPath("~/Files/FileUpload") + "/Thumb/"; if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } try { fuSource.PostedFile.SaveAs(SaveLocation); //System.Drawing.Image myimg = System.Drawing.Image.FromFile(SaveLocation); //myimg = myimg.GetThumbnailImage(100, 100, null, IntPtr.Zero); //myimg.Save(displayedImgThumb + SaveLocation, myimg.RawFormat); account.Picture = currentTime + fileName; entities.SaveChanges(); Response.Redirect("~/AccountInformation.aspx"); } catch (Exception ex) { lblResultMessage.Text = "Error: " + ex.Message; } } else { lblResultMessage.Text = "Файла е прекалено голям."; } } }
protected void GridViewExistingUsers_ItemCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Sorting") { LinkButton btn = e.CommandSource as LinkButton; if (btn.CommandArgument != SortingColumn) { SortingDirection = "sortingasc"; } else { SortingDirection = SortingDirection == "sortingasc" ? "sortingdesc" : "sortingasc"; } SortingColumn = btn.CommandArgument; DataBindUsers(); } else if (e.CommandName == "BlockUser" || e.CommandName == "UnBlockUser") { Guid currentUserASPNETID = Guid.Parse(e.CommandArgument.ToString()); DictionaryModel.aspnet_Membership currentUser = entities.aspnet_Membership.FirstOrDefault(user => user.UserId == currentUserASPNETID); if (currentUser != null) { if (currentUser.IsApproved) { currentUser.IsApproved = false; } else { currentUser.IsApproved = true; } entities.SaveChanges(); DataBindUsers(); } } }
protected void lbtnNextStep_Click(object sender, EventArgs e) { try { bool password = txtPassword.Text == txtConfirmPassword.Text; bool answer = txtAnswer.Text == txtConfirmAnswer.Text; if (!password) { lblError.Text = "Въведените пароли не съвпадат."; return; } if (password && answer) { if (hdnEditAccountSecutiry.Value == "") //New Account { DictionaryModel.Account account = new DictionaryModel.Account(); MembershipCreateStatus status; MembershipUser user = Membership.CreateUser(DateTime.Now.ToString("ddhhmmssfff"), txtPassword.Text, txtEmail.Text.Trim().ToLower(), txtQuestion.Text.Trim(), txtAnswer.Text.Trim(), chkApproved.Checked, out status); if (status != MembershipCreateStatus.Success) { switch (status) { case MembershipCreateStatus.DuplicateEmail: lblError.Text = "Въведеният Email адрес е зает."; break; case MembershipCreateStatus.DuplicateProviderUserKey: lblError.Text = "Дублиращ се потребителски код."; break; case MembershipCreateStatus.DuplicateUserName: lblError.Text = "Въведеното потребителско име е заето."; break; case MembershipCreateStatus.InvalidAnswer: lblError.Text = "Въведохте невалиден отговор на тайният въпрос."; break; case MembershipCreateStatus.InvalidEmail: lblError.Text = "Въведохте невалиден Email адрес."; break; case MembershipCreateStatus.InvalidPassword: lblError.Text = "Въведохте невалидна парола."; break; case MembershipCreateStatus.InvalidProviderUserKey: lblError.Text = "Невалиден потретбителски код."; break; case MembershipCreateStatus.InvalidQuestion: lblError.Text = "Веведохте невалиден таен въпрос."; break; case MembershipCreateStatus.InvalidUserName: lblError.Text = "Въведохте невалидно потребителско име."; break; case MembershipCreateStatus.ProviderError: lblError.Text = "Възникна грешка, моля опитайте отново."; break; case MembershipCreateStatus.UserRejected: lblError.Text = "Вашият профил е спрян."; break; default: break; } return; } user.IsApproved = chkApproved.Checked; user.Comment = txtReminder.Text; Membership.UpdateUser(user); Roles.AddUserToRole(user.UserName, "User"); account.ASPNETID = (Guid)user.ProviderUserKey; account.FirstName = string.Empty; account.LastName = string.Empty; entities.Accounts.AddObject(account); entities.SaveChanges(); if (StepCompleted != null) { NewAccountStepCompletedEventArgs args = new NewAccountStepCompletedEventArgs(NewAccountWizardSteps.AccountSecurity); Session["SetupASPNETID"] = args.ASPNETID = account.ASPNETID; Session["SetupAcountId"] = args.CurrentAccountId = account.Id; StepCompleted.Invoke(this, args); //HideEditAddControls(); } } else //Edit Account { MembershipUser user = Membership.GetUser(SetupASPNETID); user.ChangePasswordQuestionAndAnswer(txtPassword.Text, txtQuestion.Text, txtAnswer.Text); user.Comment = txtReminder.Text; user.IsApproved = chkApproved.Checked; Membership.UpdateUser(user); hdnEditAccountSecutiry.Value = null; HideEditAddControls(); if (StepCompleted != null) { NewAccountStepCompletedEventArgs args = new NewAccountStepCompletedEventArgs(NewAccountWizardSteps.AccountSecurity); args.ASPNETID = (Guid)user.ProviderUserKey; StepCompleted.Invoke(this, args); } } } else { lblError.Text = "Въведените отговори на тайният въпрос не съвпадат."; } } catch (Exception ex) { lblError.Text = ex.Message;// "Възникна проблем, моля опитайте по-късно."; } }
protected void lbtnFinishStep_Click(object sender, EventArgs e) { try { Guid setASPNETID = (Guid)Session["SetupASPNETID"]; int setAccId = Int32.Parse(Session["SetupAcountId"].ToString()); DictionaryModel.Account account = entities.Accounts.FirstOrDefault(acc => acc.ASPNETID == setASPNETID); if (ddlArea.SelectedValue != "0") { account.Area = Int32.Parse(ddlArea.SelectedValue); if (ddlCity.SelectedValue != "0") { account.City = Int32.Parse(ddlCity.SelectedValue); if (ddlVillage.SelectedValue != "0") { account.Village = Int32.Parse(ddlVillage.SelectedValue); } } } int phone; if (Int32.TryParse(txtPhone.Text, out phone)) { account.Phone = phone; } account.Address = txtAddress.Text; account.Notes = txtNotes.Text; if (fuSource.HasFile) { string fileExt = System.IO.Path.GetExtension(fuSource.PostedFile.FileName); if (fileExt == ".jpg" || fileExt == ".jpeg" || fileExt == ".png" || fileExt == ".bmp") { if ((fuSource.PostedFile.ContentLength > 0) && (fuSource.PostedFile.ContentLength < 10000000)) { string currentTime = DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", ""); string fileName = fuSource.PostedFile.FileName; string fileDirectory = Server.MapPath("~/Files/FileUpload"); string SaveLocation = fileDirectory + "\\" + currentTime + fileName; //string displayedImgThumb = Server.MapPath("~/Files/FileUpload") + "/Thumb/"; if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory); } try { fuSource.PostedFile.SaveAs(SaveLocation); //System.Drawing.Image myimg = System.Drawing.Image.FromFile(SaveLocation); //myimg = myimg.GetThumbnailImage(100, 100, null, IntPtr.Zero); //myimg.Save(displayedImgThumb + SaveLocation, myimg.RawFormat); account.Picture = currentTime + fileName; } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } } else { lblError.Text = "Файла е прекалено голям."; } } } entities.SaveChanges(); if (StepCompleted != null) { NewAccountStepCompletedEventArgs args = new NewAccountStepCompletedEventArgs(NewAccountWizardSteps.AdditionalInformation); args.ASPNETID = setASPNETID; args.CurrentAccountId = setAccId; StepCompleted.Invoke(this, args); } } catch { lblError.Text = "Възникна проблем, моля опитайте по-късно."; } }