void btnOK_Click(object sender, RoutedEventArgs e) { try { if (txtUserNameID.Text != "" && pwdPasssword.Password != "" && txtEmail.Text != "") { lblValidate.Content = string.Empty; string emailStr = txtEmail.Text; int indexAt = emailStr.IndexOf('@'); strPassword = encodestring(pwdPasssword.Password); string substremail = emailStr.Substring(indexAt + 1); int indexDot = substremail.IndexOf('.'); indexDot = indexDot + indexAt + 1; int lengthEmail = emailStr.Length; if (indexAt >= 1 && indexDot >= 3 && (indexDot - indexAt) >= 2 && lengthEmail >= 5) { if (strPassword.Length < 6) { lblValidate.Content = "6 Characters for Password"; } else if (!validate_text()) { lblValidate.Content = "Only Characters(a-z) allow"; } else { ClsUser objUser = new ClsUser(); objUser.ID = -1; objUser.DisplayName = txtUserNameID.Text.Trim(); objUser.RoleID = 2; objUser.FName = txtUserNameID.Text.Trim(); objUser.LName = ""; objUser.EMail = txtEmail.Text; objUser.PassWord = strPassword; objUser.IsActive = true; objUser.CreatedBy = 1; objUser.ModifiedBy = 1; objUser.RatePerHour = 0; objUser.OverTimeRate = 0; objUser.DoubleRatePerHour = 0; objUser.DoubleOverTimeRate = 0; lblValidate.Content = "Registering...."; while (VMuktiAPI.VMuktiInfo.MainConnectionString == string.Empty) { lblValidate.Content = "Try After Some Time."; } int retID = objUser.Save(); if (retID == 0) { lblValidate.Content = "Already Registered."; VMuktiAPI.VMuktiHelper.CallEvent("BandwidthUsage", null, null); } else { lblValidate.Content = "User Created Successfully."; txtUserNameID.Text = ""; pwdPasssword.Password = ""; strPassword = ""; txtEmail.Text = ""; for (int i = 0; i < cnvMain.Children.Count; i++) { if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Label") { if (((Label)cnvMain.Children[i]).Name == "lbemail") { cnvMain.Children.RemoveAt(i); } } if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.TextBox") { if (((TextBox)cnvMain.Children[i]).Name == "txtEmail") { cnvMain.Children.RemoveAt(i); } } if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Button") { if (((Button)cnvMain.Children[i]).Name == "btnok") { cnvMain.Children.RemoveAt(i); } } if (((UIElement)cnvMain.Children[i]).GetType().ToString() == "System.Windows.Controls.Button") { if (((Button)cnvMain.Children[i]).Name == "btncan") { cnvMain.Children.RemoveAt(i); } } } btnSignUp.Visibility = Visibility.Visible; btnLogIn.Visibility = Visibility.Visible; #region ALPA VMukti.Business.ClsUser.AddRecord(); #endregion } } } else { lblValidate.Content = "Please Enter a valid Email ID"; } } else { lblValidate.Content = "Feilds cant left blank"; } } catch (Exception ex) { VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "BtnOK_Click()", "Controls\\CtlLogin.xaml.cs"); } }
//To save new Record private void btnGroupSave_Click(object sender, System.Windows.RoutedEventArgs e) { try { //Validations for group #region GroupName Validation if (txtName.Text.Trim() == "") { MessageBox.Show("Group Name Can't be left Blank ", "-> Please Enter a Name", MessageBoxButton.OK, MessageBoxImage.Information); txtName.Focus(); txtName.Text = txtName.Text.Trim(); return; } #endregion string strUsers = ""; for (int i = 0; i < lstSelectedAgents.Items.Count; i++) { if (i == 0) { strUsers = ((ListBoxItem)lstSelectedAgents.Items[i]).Tag.ToString(); } else { strUsers = strUsers + "," + ((ListBoxItem)lstSelectedAgents.Items[i]).Tag.ToString(); } } int GetId = 0; ClsGroup c = new ClsGroup(); if (varState == 0) { c.ID = -1; } else { c.ID = varID; } c.GroupName = txtName.Text.Trim(); c.Description = txtDescription.Text.Trim(); c.IsActive = (bool)chkIsActive.IsChecked; c.CreatedBy = VMuktiAPI.VMuktiInfo.CurrentPeer.ID; //Function to save new record int gID = c.Save(); if (gID == 0) { MessageBox.Show("User Group With Same Name is Not Allowed", "-> User Group", MessageBoxButton.OK, MessageBoxImage.Information); } else { if (varState != 0) { ClsUser u1 = new ClsUser(); u1.ID = gID; u1.Delete(); } for (int i = 0; i < lstSelectedAgents.Items.Count; i++) { ClsUser u = new ClsUser(); u.ID = int.Parse(((ListBoxItem)lstSelectedAgents.Items[i]).Tag.ToString()); //u.AgentName = ((ListBoxItem)lstSelectedAgents.Items[i]).Content.ToString(); u.GroupId = gID; //Function to Save record in usergroup u.Save(); } System.Windows.MessageBox.Show("Record Saved Successfully!!"); FncClearAll(); //set data in grid funSetGrid(); //set data in listboxes funSetComboboxes(); } } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "btnGroupSave_Click", "ctlUserGroup.xaml.cs"); } }
private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e) { try { #region DataValidations //Display Name Validation if (txtDisplayName.Text.Trim() == "") { MessageBox.Show("User Name Cann't be left Blank ", "->Please Enter a Display Name", MessageBoxButton.OK, MessageBoxImage.Information); txtDisplayName.Focus(); txtDisplayName.Text = txtDisplayName.Text.Trim(); return; } //RoleAssigned Validation if (cmbRoleAssigned.Text.Trim() == "") { MessageBox.Show("Role Cann't be left Blank", "Select one of the items for RoleAssigned", MessageBoxButton.OK, MessageBoxImage.Information); cmbRoleAssigned.Focus(); return; } //FirstName Validation if (txtFirstName.Text.Trim() == "") { MessageBox.Show("First Name Cann't be left Blank", "-> Please Enter First Name", MessageBoxButton.OK, MessageBoxImage.Information); txtFirstName.Focus(); txtFirstName.Text = txtFirstName.Text.Trim(); return; } //Email Validation if (txtEmail.Text.Trim() == "") { MessageBox.Show("Email Address cann't be left Blank", "-> Please Enter Email Address", MessageBoxButton.OK, MessageBoxImage.Information); txtEmail.Text = txtEmail.Text.Trim(); txtEmail.Focus(); return; } // Email Valid? string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$"; System.Text.RegularExpressions.Match match = Regex.Match(txtEmail.Text.Trim(), pattern, RegexOptions.IgnoreCase); if (match.Success) { } else { MessageBox.Show("Email Address Is Not Valid", "-> Please Enter Valid Email Address", MessageBoxButton.OK, MessageBoxImage.Information); txtEmail.Focus(); return; } // //Password Validation if (txtPassWord.Password.Trim().Length < 6) { MessageBox.Show("Password must be minimum SIX characters", "-> Please Enter Valid Password", MessageBoxButton.OK, MessageBoxImage.Information); txtPassWord.Password = ""; txtPassWord.Focus(); return; } //Float Value Validation //float a = float.Parse(txtRatePerHour.Text); if (txtRatePerHour.Text.Trim() == "") { txtRatePerHour.Text = "0.0"; } if (txtDoubleOverTimeRate.Text.Trim() == "") { txtDoubleOverTimeRate.Text = "0.0"; } if (txtOverTimeRate.Text.Trim() == "") { txtOverTimeRate.Text = "0.0"; } if (txtDoubleTimeRate.Text.Trim() == "") { txtDoubleTimeRate.Text = "0.0"; } #endregion ClsUser objUser = new ClsUser(); if (varState == 0) { objUser.ID = -1; } else { objUser.ID = varID; } objUser.DisplayName = txtDisplayName.Text.Trim(); objUser.RoleID = Convert.ToInt32(((ListBoxItem)cmbRoleAssigned.SelectedItem).Tag); objUser.FName = txtFirstName.Text.Trim(); objUser.LName = txtLastName.Text.Trim(); objUser.EMail = txtEmail.Text.Trim(); objUser.PassWord = encodestring(txtPassWord.Password.Trim()); if (chkIsActive.IsChecked == true) { objUser.IsActive = true; } else { objUser.IsActive = false; } objUser.CreatedBy = VMuktiAPI.VMuktiInfo.CurrentPeer.ID; objUser.ModifiedBy = VMuktiAPI.VMuktiInfo.CurrentPeer.ID; objUser.RatePerHour = float.Parse(txtRatePerHour.Text.Trim()); objUser.OverTimeRate = float.Parse(txtOverTimeRate.Text.Trim()); objUser.DoubleRatePerHour = float.Parse(txtDoubleTimeRate.Text.Trim()); objUser.DoubleOverTimeRate = float.Parse(txtDoubleOverTimeRate.Text.Trim()); int retID = objUser.Save(); if (retID == 0) { MessageBox.Show("User With Same Name is Not Allowed", "-> User", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Record Saved Successfully!!"); funClearTextBoxes(); funSetGrid(); funSetCombo(); } } catch (Exception ex) { VMuktiHelper.ExceptionHandler(ex, "btnSave_Click", "CtlUserInfo.xaml.cs"); } }