private async Task chkUser() { string password = Md5Encription.MD5Hash("Inc-m" + pb_password.Password); User user = await userModel.getUserById(userID); if ((tb_userName.Text.Trim().Equals(user.username)) && (password.Trim().Equals(user.password))) { isOk = true; } else { isOk = false; } if (isOk) { this.Close(); } else { SectionData.showPasswordValidate(pb_password, p_errorPassword, tt_errorPassword, "trErrorPasswordToolTip"); p_showPassword.Visibility = Visibility.Collapsed; } }
private async void Btn_update_Click(object sender, RoutedEventArgs e) {//update try { HelpClass.StartAwait(grid_main); if (user.userId > 0) { //chk duplicate userName bool duplicateUserName = false; duplicateUserName = await chkIfUserNameIsExists(tb_name.Text, user.userId); if (HelpClass.validate(requiredControlList, this) && duplicateUserName && HelpClass.IsValidEmail(this)) { user.name = tb_name.Text; user.lastName = tb_lastName.Text; user.countryId = Convert.ToInt32(cb_country.SelectedValue); user.accountName = tb_accountName.Text; //user.password = Md5Encription.MD5Hash("Inc-m" + pb_password.Password); ; user.email = tb_email.Text; user.mobile = cb_areaMobile.Text + "-" + tb_mobile.Text;; if (!tb_phone.Text.Equals("")) { user.phone = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text; } if (!tb_fax.Text.Equals("")) { user.fax = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text; } if (cb_agentLevel.SelectedValue != null) { user.agentLevel = cb_agentLevel.SelectedValue.ToString(); } user.address = tb_address.Text; user.notes = tb_notes.Text; user.createUserId = MainWindow.userLogin.userId; user.updateUserId = MainWindow.userLogin.userId; int s = await user.Save(user); if (s <= 0) { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } else { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopUpdate"), animation: ToasterAnimation.FadeIn); await RefreshUsersList(); await Search(); if (isImgPressed) { int userId = s; string b = await user.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + userId.ToString()), userId); user.image = b; isImgPressed = false; if (!b.Equals("")) { await getImg(); } else { HelpClass.clearImg(btn_image); } } } } } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trSelectItemFirst"), animation: ToasterAnimation.FadeIn); } HelpClass.EndAwait(grid_main); } catch (Exception ex) { HelpClass.EndAwait(grid_main); HelpClass.ExceptionMessage(ex, this); } }
private async void Btn_add_Click(object sender, RoutedEventArgs e) {//add try { HelpClass.StartAwait(grid_main); //chk duplicate userName bool duplicateUserName = false; duplicateUserName = await chkIfUserNameIsExists(tb_name.Text, 0); //chk password length bool passLength = false; passLength = chkPasswordLength(pb_password.Password); user = new Users(); if (HelpClass.validate(requiredControlList, this) && duplicateUserName && passLength && HelpClass.IsValidEmail(this)) { //tb_code.Text = await user.generateCodeNumber("ag"); tb_code.Text = await HelpClass.generateRandomString(3, "ag", "Users", 0); user.code = tb_code.Text; user.name = tb_name.Text; user.lastName = tb_lastName.Text; user.countryId = Convert.ToInt32(cb_country.SelectedValue); user.accountName = tb_accountName.Text; user.password = Md5Encription.MD5Hash("Inc-m" + pb_password.Password);; user.email = tb_email.Text; user.mobile = cb_areaMobile.Text + "-" + tb_mobile.Text;; if (!tb_phone.Text.Equals("")) { user.phone = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text; } if (!tb_fax.Text.Equals("")) { user.fax = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text; } if (cb_agentLevel.SelectedValue != null) { user.agentLevel = cb_agentLevel.SelectedValue.ToString(); } user.type = "ag"; user.address = tb_address.Text; user.notes = tb_notes.Text; user.isActive = 1; user.createUserId = MainWindow.userLogin.userId; user.updateUserId = MainWindow.userLogin.userId; int s = await user.Save(user); if (s <= 0) { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } else { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopAdd"), animation: ToasterAnimation.FadeIn); if (isImgPressed) { int userId = s; string b = await user.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + userId.ToString()), userId); user.image = b; isImgPressed = false; } Clear(); await RefreshUsersList(); await Search(); } } HelpClass.EndAwait(grid_main); } catch (Exception ex) { HelpClass.EndAwait(grid_main); HelpClass.ExceptionMessage(ex, this); } }
private async void Btn_save_Click(object sender, RoutedEventArgs e) {//save try { if (sender != null) { SectionData.StartAwait(grid_main); } //chk empty name SectionData.validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "trEmptyNameToolTip"); //chk empty mobile SectionData.validateEmptyTextBox(tb_mobile, p_errorMobile, tt_errorMobile, "trEmptyMobileToolTip"); //validate email SectionData.validateEmail(tb_email, p_errorEmail, tt_errorEmail); string phoneStr = ""; if (!tb_phone.Text.Equals("")) { phoneStr = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text; } string faxStr = ""; if (!tb_fax.Text.Equals("")) { faxStr = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text; } bool emailError = false; if (!tb_email.Text.Equals("")) { if (!ValidatorExtensions.IsValid(tb_email.Text)) { emailError = true; } } //decimal maxDeserveValue = 0; if ((!tb_name.Text.Equals("")) && (!tb_mobile.Text.Equals(""))) { if (emailError) { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trErrorEmailToolTip"), animation: ToasterAnimation.FadeIn); } else { //SectionData.genRandomCode(type); if (agent.agentId == 0) { tb_code.Text = await agentModel.generateCodeNumber(type); agent.type = type; agent.accType = ""; agent.balance = 0; agent.isActive = 1; } if (type == "c") { agent.isLimited = (bool)tgl_hasCredit.IsChecked; decimal maxDeserveValue = 0; if (!tb_upperLimit.Text.Equals("")) { maxDeserveValue = decimal.Parse(tb_upperLimit.Text); } agent.maxDeserve = maxDeserveValue; } else { agent.maxDeserve = 0; agent.isLimited = false; } agent.name = tb_name.Text; agent.code = tb_code.Text; agent.company = tb_company.Text; agent.address = tb_address.Text; agent.email = tb_email.Text; agent.phone = phoneStr; agent.mobile = cb_areaMobile.Text + "-" + tb_mobile.Text; agent.image = ""; agent.createUserId = MainWindow.userID; agent.updateUserId = MainWindow.userID; agent.notes = tb_notes.Text; agent.fax = faxStr; int s = await agentModel.save(agent); if (s > 0) { //Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopSave"), animation: ToasterAnimation.FadeIn); isOk = true; this.Close(); } //else //Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); if (isImgPressed) { int agentId = s; string b = await agentModel.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + agentId.ToString()), agentId); agent.image = b; isImgPressed = false; //if (b.Equals("")) //Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trThereWasAnErrorLoadingTheImage"), animation: ToasterAnimation.FadeIn); } } } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } SectionData.ExceptionMessage(ex, this); } }
private async void Btn_save_Click(object sender, RoutedEventArgs e) {//save try { if (sender != null) { SectionData.StartAwait(grid_main); } bool wrongOldPasswordLength = false, wrongNewPasswordLength = false, wrongConfirmPasswordLength = false; //chk empty old password if (pb_oldPassword.Password.Equals("")) { SectionData.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trEmptyPasswordToolTip"); } else { //chk password length wrongOldPasswordLength = chkPasswordLength(pb_oldPassword.Password); if (wrongOldPasswordLength) { SectionData.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trErrorPasswordLengthToolTip"); } else { SectionData.clearPasswordValidate(pb_oldPassword, p_errorOldPassword); } } //chk empty new password if (pb_newPassword.Password.Equals("")) { SectionData.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trEmptyPasswordToolTip"); } else { //chk password length wrongNewPasswordLength = chkPasswordLength(pb_newPassword.Password); if (wrongNewPasswordLength) { SectionData.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trErrorPasswordLengthToolTip"); } else { SectionData.clearPasswordValidate(pb_newPassword, p_errorNewPassword); } } //chk empty confirm password if (pb_confirmPassword.Password.Equals("")) { SectionData.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trEmptyPasswordToolTip"); } else { //chk password length wrongConfirmPasswordLength = chkPasswordLength(pb_confirmPassword.Password); if (wrongConfirmPasswordLength) { SectionData.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trErrorPasswordLengthToolTip"); } else { SectionData.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword); } } if ((!pb_oldPassword.Password.Equals("")) && (!wrongOldPasswordLength) && (!pb_newPassword.Password.Equals("")) && (!wrongNewPasswordLength) && (!pb_confirmPassword.Password.Equals("")) && (!wrongConfirmPasswordLength)) { //get password for logined user string loginPassword = MainWindow.userLogin.password; string enteredPassword = Md5Encription.MD5Hash("Inc-m" + pb_oldPassword.Password); if (!loginPassword.Equals(enteredPassword)) { SectionData.showPasswordValidate(pb_oldPassword, p_errorOldPassword, tt_errorOldPassword, "trWrongPassword"); } else { SectionData.clearPasswordValidate(pb_oldPassword, p_errorOldPassword); bool isNewEqualConfirmed = true; if (pb_newPassword.Password.Equals(pb_confirmPassword.Password)) { isNewEqualConfirmed = true; } else { isNewEqualConfirmed = false; } if (!isNewEqualConfirmed) { SectionData.showPasswordValidate(pb_newPassword, p_errorNewPassword, tt_errorNewPassword, "trErrorNewPasswordNotEqualConfirmed"); SectionData.showPasswordValidate(pb_confirmPassword, p_errorConfirmPassword, tt_errorConfirmPassword, "trErrorNewPasswordNotEqualConfirmed"); } else { SectionData.clearPasswordValidate(pb_newPassword, p_errorNewPassword); SectionData.clearPasswordValidate(pb_confirmPassword, p_errorConfirmPassword); //change password string newPassword = Md5Encription.MD5Hash("Inc-m" + pb_newPassword.Password); MainWindow.userLogin.password = newPassword; int s = await userModel.save(MainWindow.userLogin); if (s > 0) { userID = s; if (!Properties.Settings.Default.password.Equals("")) { Properties.Settings.Default.password = pb_newPassword.Password; Properties.Settings.Default.Save(); } Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopPasswordChanged"), animation: ToasterAnimation.FadeIn); this.Close(); } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } } } } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } SectionData.ExceptionMessage(ex, this); } }
private async void btnLogIn_Click(object sender, RoutedEventArgs e) {//log in try { if (!logInProcessing) { logInProcessing = true; HelpClass.StartAwait(grid_main); HelpClass.clearValidate(p_errorUserName); HelpClass.clearValidate(p_errorPassword); string password = Md5Encription.MD5Hash("Inc-m" + txtPassword.Password); string userName = txtUserName.Text; user = await userModel.Getloginuser(userName, password); if (user.accountName == null) { //user does not exist HelpClass.SetValidate(p_errorUserName, "trUserNotFound"); } else { if (user.userId == 0) { //wrong password HelpClass.SetValidate(p_errorPassword, "trWrongPassword"); } else { //correct //send user info to main window MainWindow.userID = user.userId; MainWindow.userLogin = user; #region check if menu is open //try //{ // string m = await SectionData.getUserMenuIsOpen(user.userId); // if (!m.Equals("-1")) // MainWindow.menuIsOpen = m; // else // MainWindow.menuIsOpen = "close"; // menuIsOpen = MainWindow.menuIsOpen; //} //catch //{ // MainWindow.menuIsOpen = "close"; // menuIsOpen = MainWindow.menuIsOpen; //} #endregion //make user online user.isOnline = 1; int s = await userModel.Save(user); #region remember me if (cbxRemmemberMe.IsChecked.Value) { Properties.Settings.Default.userName = txtUserName.Text; Properties.Settings.Default.password = txtPassword.Password; Properties.Settings.Default.Lang = MainWindow.lang; //Properties.Settings.Default.menuIsOpen = menuIsOpen; } else { Properties.Settings.Default.userName = ""; Properties.Settings.Default.password = ""; Properties.Settings.Default.Lang = ""; //Properties.Settings.Default.menuIsOpen = ""; } Properties.Settings.Default.Save(); #endregion MainWindow.Region.countryId = 1; MainWindow main = new MainWindow(); main.Show(); this.Close(); } } HelpClass.EndAwait(grid_main); logInProcessing = false; } } catch (Exception ex) { HelpClass.EndAwait(grid_main); logInProcessing = false; HelpClass.ExceptionMessage(ex, this); } }
private async void Btn_add_Click(object sender, RoutedEventArgs e) {//add try { HelpClass.StartAwait(grid_main); customer = new Customers(); if (HelpClass.validate(requiredControlList, this) && HelpClass.IsValidEmail(this)) { //tb_custCode.Text = await customer.generateCodeNumber("cu"); tb_custCode.Text = await HelpClass.generateRandomString(5, "", "Customers", 0); customer.custCode = tb_custCode.Text; customer.custname = tb_custname.Text; customer.lastName = tb_lastName.Text; customer.countryId = Convert.ToInt32(cb_country.SelectedValue); customer.email = tb_email.Text; customer.mobile = cb_areaMobile.Text + "-" + tb_mobile.Text; if (!tb_phone.Text.Equals("")) { customer.phone = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text; } if (!tb_fax.Text.Equals("")) { customer.fax = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text; } if (cb_custlevel.SelectedValue != null) { customer.custlevel = cb_custlevel.SelectedValue.ToString(); } customer.company = tb_company.Text.Trim(); customer.address = tb_address.Text; customer.notes = tb_notes.Text; customer.isActive = 1; customer.createUserId = MainWindow.userLogin.userId; customer.updateUserId = MainWindow.userLogin.userId; customer.balance = 0; int s = await customer.Save(customer); if (s <= 0) { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } else { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopAdd"), animation: ToasterAnimation.FadeIn); if (isImgPressed) { int customerId = s; string b = await customer.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + customerId.ToString()), customerId); customer.image = b; isImgPressed = false; } Clear(); await RefreshCustomersList(); await Search(); } } HelpClass.EndAwait(grid_main); } catch (Exception ex) { HelpClass.EndAwait(grid_main); HelpClass.ExceptionMessage(ex, this); } }
private async void Btn_save_Click(object sender, RoutedEventArgs e) {//save try { if (sender != null) { SectionData.StartAwait(grid_changePassword); } bool wrongPasswordLength = false; //chk empty user SectionData.validateEmptyComboBox(cb_user, p_errorUser, tt_errorUser, "trEmptyUser"); //chk empty password if (pb_password.Password.Equals("")) { SectionData.showPasswordValidate(pb_password, p_errorPassword, tt_errorPassword, "trEmptyPasswordToolTip"); } else { //chk password length wrongPasswordLength = chkPasswordLength(pb_password.Password); if (wrongPasswordLength) { SectionData.showPasswordValidate(pb_password, p_errorPassword, tt_errorPassword, "trErrorPasswordLengthToolTip"); } else { SectionData.clearPasswordValidate(pb_password, p_errorPassword); } } if ((!cb_user.Text.Equals("")) && (!pb_password.Password.Equals("")) && (!wrongPasswordLength)) { if (user != null) { string password = Md5Encription.MD5Hash("Inc-m" + pb_password.Password); user.password = password; int s = await userModel.save(user); if (s > 0) { if (Properties.Settings.Default.password != string.Empty && user.userId == MainWindow.userLogin.userId) { Properties.Settings.Default.password = pb_password.Password; Properties.Settings.Default.Save(); } Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopPasswordChanged"), animation: ToasterAnimation.FadeIn); await Task.Delay(2000); this.Close(); userID = s; } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } } } if (sender != null) { SectionData.EndAwait(grid_changePassword); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_changePassword); } SectionData.ExceptionMessage(ex, this); } }
private async void Btn_next_Click(object sender, RoutedEventArgs e) { isValid = true; // uc_serverConfig if (pageIndex == 0) { var supsublist = list.Take(2); foreach (var item in supsublist) { if (item.key.Equals("serverUri")) { // if (string.IsNullOrWhiteSpace(uc_serverConfig.Instance.serverUri)) if (string.IsNullOrWhiteSpace(serverConfigInstance.serverUri)) { item.value = ""; isValid = false; break; } else { item.value = serverConfigInstance.serverUri; bool validUrl = setupConfiguration.validateUrl(item.value); if (!validUrl) { Toaster.ShowWarning(Window.GetWindow(this), message: wd_setupFirstPos.resourcemanager.GetString("trErrorWrongUrl"), animation: ToasterAnimation.FadeIn); isValid = false; break; } else { Global.APIUri = serverConfigInstance.serverUri + "/api/"; int installationNum = await setupConfiguration.getInstallationNum(); if (installationNum == 2) { wd_setupOtherPos logInOther = new wd_setupOtherPos(); //uc_serverConfig.Instance grid_main.Children.Clear(); logInOther.Show(); this.Close(); return; } } } } else if (item.key.Equals("activationkey")) { if (string.IsNullOrWhiteSpace(serverConfigInstance.activationkey)) { item.value = ""; isValid = false; break; } else { item.value = serverConfigInstance.activationkey; } } } } else if (pageIndex == 1) { var supsublist = list.Skip(2).Take(6); foreach (var item in supsublist) { if (item.key.Equals("countryId")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.countryId)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.countryId; countryId = int.Parse(item.value); } } else if (item.key.Equals("userName")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.userName)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.userName; } } else if (item.key.Equals("userPassword")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.userPassword)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.userPassword; bool wrongPasswordLength = SectionData.chkPasswordLength(item.value); if (wrongPasswordLength) { Toaster.ShowWarning(Window.GetWindow(this), message: wd_setupFirstPos.resourcemanager.GetString("trErrorPasswordLengthToolTip"), animation: ToasterAnimation.FadeIn); isValid = false; break; } } } else if (item.key.Equals("branchName")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.branchName)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.branchName; } } else if (item.key.Equals("branchCode")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.branchCode)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.branchCode; } } else if (item.key.Equals("branchMobile")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.branchMobile)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.branchMobile; } } else if (item.key.Equals("posName")) { if (string.IsNullOrWhiteSpace(posGeneralInstance.posName)) { item.value = ""; isValid = false; break; } else { item.value = posGeneralInstance.posName; } } } } else if (pageIndex == 2) { var supsublist = list.Skip(8).Take(6); foreach (var item in supsublist) { if (item.key.Equals("companyName")) { if (string.IsNullOrWhiteSpace(comInfoInstance.companyName)) { item.value = ""; isValid = false; break; } else { item.value = comInfoInstance.companyName; } } else if (item.key.Equals("address")) { if (string.IsNullOrWhiteSpace(comInfoInstance.address)) { item.value = ""; } else { item.value = comInfoInstance.address; } } else if (item.key.Equals("email")) { if (string.IsNullOrWhiteSpace(comInfoInstance.email)) { item.value = ""; } else { item.value = comInfoInstance.email; } } else if (item.key.Equals("mobile")) { if (string.IsNullOrWhiteSpace(comInfoInstance.mobile)) { item.value = ""; isValid = false; break; } else { item.value = comInfoInstance.mobile; } } else if (item.key.Equals("phone")) { if (string.IsNullOrWhiteSpace(comInfoInstance.phone)) { item.value = ""; } else { item.value = comInfoInstance.phone; } } else if (item.key.Equals("fax")) { if (string.IsNullOrWhiteSpace(comInfoInstance.fax)) { item.value = ""; } else { item.value = comInfoInstance.fax; } } } } if (isValid) { if (pageIndex == 2) { //server INFO string url = serverConfigInstance.serverUri; string activationkey = serverConfigInstance.activationkey; // user INFO string userName = posGeneralInstance.userName; string password = Md5Encription.MD5Hash("Inc-m" + posGeneralInstance.userPassword); // branch INFO string branchName = posGeneralInstance.branchName; string branchCode = posGeneralInstance.branchCode; string branchMobile = posGeneralInstance.branchMobile; // pos INFO string posName = posGeneralInstance.posName; string motherCode = setupConfiguration.GetMotherBoardID(); string hardCode = setupConfiguration.GetHDDSerialNo(); string deviceCode = motherCode + "-" + hardCode; // company INFO string imageFileName = string.IsNullOrWhiteSpace(imgFileName) ? "" : Md5Encription.MD5Hash("Inc-m" + imgFileName); List <SetValues> company = new List <SetValues>(); company.Add(new SetValues { name = "com_name", value = comInfoInstance.companyName }); company.Add(new SetValues { name = "com_address", value = string.IsNullOrWhiteSpace(comInfoInstance.address) ? "" : comInfoInstance.address }); company.Add(new SetValues { name = "com_email", value = string.IsNullOrWhiteSpace(comInfoInstance.email) ? "" : comInfoInstance.email }); company.Add(new SetValues { name = "com_mobile", value = comInfoInstance.mobile }); company.Add(new SetValues { name = "com_phone", value = string.IsNullOrWhiteSpace(comInfoInstance.phone) ? "" : comInfoInstance.phone }); company.Add(new SetValues { name = "com_fax", value = string.IsNullOrWhiteSpace(comInfoInstance.fax) ? "" : comInfoInstance.fax }); company.Add(new SetValues { name = "com_logo", value = imageFileName }); Global.APIUri = url + "/api/"; int res = await setupConfiguration.setConfiguration(activationkey, deviceCode, countryId, userName, password, branchName, branchCode, branchMobile, posName, company); if (res == -2 || res == -3) // invalid or resrved activation key { serverConfigInstance.activationkey = ""; pageIndex = 0; CallPage(0); Toaster.ShowWarning(Window.GetWindow(this), message: wd_setupFirstPos.resourcemanager.GetString("trErrorWrongActivation"), animation: ToasterAnimation.FadeIn); return; } else if (res > 0) { #region upload image if (imageFileName != "") { await setVLogo.uploadImage(imgFileName, imageFileName, 0); } #endregion Properties.Settings.Default.APIUri = Global.APIUri; Properties.Settings.Default.posId = res.ToString(); Properties.Settings.Default.Save(); Properties.Settings.Default.Reload(); System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); config.AppSettings.Settings.Add("posId", res.ToString()); config.Save(ConfigurationSaveMode.Modified); // Force a reload of a changed section. ConfigurationManager.RefreshSection("appSettings"); this.Close(); return; } } if (pageIndex < 2) { pageIndex++; CallPage(pageIndex, (sender as Button).Tag.ToString()); } } else { Toaster.ShowWarning(Window.GetWindow(this), message: "Should fill form first", animation: ToasterAnimation.FadeIn); } }
private async void Btn_save_Click(object sender, RoutedEventArgs e) {//save try { if (sender != null) { HelpClass.StartAwait(grid_main); } #region validate if (HelpClass.validate(requiredControlList, this) && HelpClass.IsValidEmail(this)) { //save name if (!tb_name.Text.Equals("")) { setVName.value = tb_name.Text; setVName.isSystem = 1; setVName.isDefault = 1; setVName.settingId = nameId; // string sName = await valueModel.Save(setVName); int sName = await valueModel.Save(setVName); if (!sName.Equals(0)) { FillCombo.companyName = tb_name.Text; } } //save address if (!tb_address.Text.Equals("")) { setVAddress.value = tb_address.Text; setVAddress.isSystem = 1; setVAddress.isDefault = 1; setVAddress.settingId = addressId; int sAddress = await valueModel.Save(setVAddress); // string sAddress = await valueModel.Save(setVAddress); if (!sAddress.Equals(0)) { FillCombo.Address = tb_address.Text; } } //save email if ((!tb_email.Text.Equals(""))) { setVEmail.value = tb_email.Text; setVEmail.isSystem = 1; setVEmail.settingId = emailId; setVEmail.isDefault = 1; // string sEmail = await valueModel.Save(setVEmail); int sEmail = await valueModel.Save(setVEmail); if (!sEmail.Equals(0)) { FillCombo.Email = tb_email.Text; } } //save mobile if (!tb_mobile.Text.Equals("")) { setVMobile.value = cb_areaMobile.Text + "-" + tb_mobile.Text; setVMobile.isSystem = 1; setVMobile.isDefault = 1; setVMobile.settingId = mobileId; int sMobile = await valueModel.Save(setVMobile); if (!sMobile.Equals(0)) { FillCombo.Mobile = cb_areaMobile.Text + tb_mobile.Text; } } //save phone //if (!tb_phone.Text.Equals("")) //{ setVPhone.value = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text; setVPhone.isSystem = 1; setVPhone.isDefault = 1; setVPhone.settingId = phoneId; int sPhone = await valueModel.Save(setVPhone); if (!sPhone.Equals(0)) { FillCombo.Phone = cb_areaPhone.Text + cb_areaPhoneLocal.Text + tb_phone.Text; } //} //save fax setVFax.value = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text; setVFax.isSystem = 1; setVFax.isDefault = 1; setVFax.settingId = faxId; int sFax = await valueModel.Save(setVFax); if (!sFax.Equals(0)) { FillCombo.Fax = cb_areaFax.Text + cb_areaFaxLocal.Text + tb_fax.Text; } // save logo // image // string sLogo = ""; int sLogo = 0; if (isImgPressed) { isImgPressed = false; setVLogo.value = sLogo.ToString(); setVLogo.isSystem = 1; setVLogo.isDefault = 1; setVLogo.settingId = logoId; sLogo = await valueModel.Save(setVLogo); if (!sLogo.Equals(0)) { FillCombo.logoImage = setVLogo.value; string b = await setVLogo.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + sLogo), sLogo); setVLogo.value = b; FillCombo.logoImage = b; sLogo = await valueModel.Save(setVLogo); await valueModel.getImg(setVLogo.value); } } #endregion if (!isFirstTime) { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopSave"), animation: ToasterAnimation.FadeIn); await Task.Delay(1500); } await FillCombo.loading_getDefaultSystemInfo(); this.Close(); } if (sender != null) { HelpClass.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { HelpClass.EndAwait(grid_main); } HelpClass.ExceptionMessage(ex, this); } }
private async void btnLogIn_Click(object sender, RoutedEventArgs e) {//login try { if (!logInProcessing) { logInProcessing = true; if (sender != null) { SectionData.StartAwait(grid_main); } //awaitSaveBtn(true); clearValidate(txtUserName, p_errorUserName); clearPasswordValidate(txtPassword, p_errorPassword); string password = Md5Encription.MD5Hash("Inc-m" + txtPassword.Password); string userName = txtUserName.Text; //check if user is exist // users = await userModel.GetUsersActive(); //////// int canLogin = await userModel.checkLoginAvalability(MainWindow.posID.Value, userName, password); if (canLogin == 1) { user = await userModel.Getloginuser(userName, password); if (user.username == null) { //user not found showTextBoxValidate(txtUserName, p_errorUserName, tt_errorUserName, "trUserNotFound"); } else { if (user.userId == 0) { //rong password showPasswordValidate(txtPassword, p_errorPassword, tt_errorPassword, "trWrongPassword"); } else { //correct //send user info to main window MainWindow.userID = user.userId; MainWindow.userLogin = user; if (await userModel.CanLogIn(user.userId, MainWindow.posID.Value) == 0 && !SectionData.isAdminPermision()) { //can't login to branch showTextBoxValidate(txtUserName, p_errorUserName, tt_errorUserName, "trDontPermissionLoginBranch"); showPasswordValidate(txtPassword, p_errorPassword, tt_errorPassword, "trDontPermissionLoginBranch"); } else { try { MainWindow.lang = await getUserLanguage(user.userId); lang = MainWindow.lang; } catch { MainWindow.lang = "en"; lang = MainWindow.lang; } try { string m = await SectionData.getUserMenuIsOpen(user.userId); if (!m.Equals("-1")) { MainWindow.menuIsOpen = m; } else { MainWindow.menuIsOpen = "close"; } menuIsOpen = MainWindow.menuIsOpen; } catch { MainWindow.menuIsOpen = "close"; menuIsOpen = MainWindow.menuIsOpen; } //make user online user.isOnline = 1; // user.isActive = 1; //checkother string str1 = await userLogsModel.checkOtherUser((int)MainWindow.userID); int s = await userModel.save(user); //create lognin record UsersLogs userLog = new UsersLogs(); userLog.posId = MainWindow.posID; Pos posmodel = new Pos(); posmodel = await posmodel.getById((int)MainWindow.posID); MainWindow.branchID = posmodel.branchId; Branch branchModel = new Branch(); MainWindow.loginBranch = await branchModel.getBranchById((int)MainWindow.branchID); userLog.userId = user.userId; int str = await userLogsModel.Save(userLog); if (!str.Equals(0)) { MainWindow.userLogInID = str; } //remember me if (cbxRemmemberMe.IsChecked.Value) { Properties.Settings.Default.userName = txtUserName.Text; //Properties.Settings.Default.password = txtPassword.Password; Properties.Settings.Default.Lang = lang; Properties.Settings.Default.menuIsOpen = menuIsOpen; } else { Properties.Settings.Default.userName = ""; Properties.Settings.Default.password = ""; Properties.Settings.Default.Lang = ""; Properties.Settings.Default.menuIsOpen = ""; } Properties.Settings.Default.Save(); //Window.GetWindow(this).Opacity = 1; //open main window and close this window MainWindow main = new MainWindow(); main.Show(); this.Close(); } } } } else if (canLogin == -1) //program is expired { tb_msg.Text = resourcemanager.GetString("trPackageIsExpired"); } else if (canLogin == -2) //device code is not correct { tb_msg.Text = resourcemanager.GetString("trPreventLogIn"); } else if (canLogin == -3) //serial is not active { tb_msg.Text = resourcemanager.GetString("trPackageIsNotActive"); } else if (canLogin == -4) //serial is not active { tb_msg.Text = resourcemanager.GetString("trServerNotCompatible"); } else if (canLogin == -5) //login date is before last login date { tb_msg.Text = resourcemanager.GetString("trDateNotCompatible"); } if (sender != null) { SectionData.EndAwait(grid_main); } logInProcessing = false; } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } logInProcessing = false; SectionData.ExceptionMessage(ex, this); } }
private async void Btn_save_Click(object sender, RoutedEventArgs e) {//save try { if (sender != null) { SectionData.StartAwait(grid_main); } #region validate bool emailError = false; if (!isFirstTime) { //chk empty name SectionData.validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "trEmptyNameToolTip"); //validate email SectionData.validateEmail(tb_email, p_errorEmail, tt_errorEmail); if (!tb_email.Text.Equals("")) { if (!ValidatorExtensions.IsValid(tb_email.Text)) { emailError = true; } } //chk empty mobile SectionData.validateEmptyTextBox(tb_mobile, p_errorMobile, tt_errorMobile, "trEmptyMobileToolTip"); } else { //chk empty name validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "Name cann't be empty"); //validate email validateEmail(tb_email, p_errorEmail, tt_errorEmail); if (!tb_email.Text.Equals("")) { if (!ValidatorExtensions.IsValid(tb_email.Text)) { emailError = true; } } //chk empty mobile validateEmptyTextBox(tb_mobile, p_errorMobile, tt_errorMobile, "Mobile number cann't be empty"); } #endregion #region save if ((!tb_name.Text.Equals("")) && (!tb_mobile.Text.Equals("")) && !emailError) { //save name if (!tb_name.Text.Equals("")) { setVName.value = tb_name.Text; setVName.isSystem = 1; setVName.isDefault = 1; setVName.settingId = nameId; // string sName = await valueModel.Save(setVName); int sName = await valueModel.Save(setVName); if (!sName.Equals(0)) { MainWindow.companyName = tb_name.Text; } } //save address if (!tb_address.Text.Equals("")) { setVAddress.value = tb_address.Text; setVAddress.isSystem = 1; setVAddress.isDefault = 1; setVAddress.settingId = addressId; int sAddress = await valueModel.Save(setVAddress); // string sAddress = await valueModel.Save(setVAddress); if (!sAddress.Equals(0)) { MainWindow.Address = tb_address.Text; } } //save email if ((!tb_email.Text.Equals("")) && (!emailError)) { setVEmail.value = tb_email.Text; setVEmail.isSystem = 1; setVEmail.settingId = emailId; setVEmail.isDefault = 1; // string sEmail = await valueModel.Save(setVEmail); int sEmail = await valueModel.Save(setVEmail); if (!sEmail.Equals(0)) { MainWindow.Email = tb_email.Text; } } //save mobile if (!tb_mobile.Text.Equals("")) { setVMobile.value = cb_areaMobile.Text + "-" + tb_mobile.Text; setVMobile.isSystem = 1; setVMobile.isDefault = 1; setVMobile.settingId = mobileId; int sMobile = await valueModel.Save(setVMobile); if (!sMobile.Equals(0)) { MainWindow.Mobile = cb_areaMobile.Text + tb_mobile.Text; } } //save phone if (!tb_phone.Text.Equals("")) { setVPhone.value = cb_areaPhone.Text + "-" + cb_areaPhoneLocal.Text + "-" + tb_phone.Text; setVPhone.isSystem = 1; setVPhone.isDefault = 1; setVPhone.settingId = phoneId; int sPhone = await valueModel.Save(setVPhone); if (!sPhone.Equals(0)) { MainWindow.Phone = cb_areaPhone.Text + cb_areaPhoneLocal.Text + tb_phone.Text; } } //save fax if (!tb_fax.Text.Equals("")) { setVFax.value = cb_areaFax.Text + "-" + cb_areaFaxLocal.Text + "-" + tb_fax.Text; setVFax.isSystem = 1; setVFax.isDefault = 1; setVFax.settingId = faxId; int sFax = await valueModel.Save(setVFax); if (!sFax.Equals(0)) { MainWindow.Fax = cb_areaFax.Text + cb_areaFaxLocal.Text + tb_fax.Text; } } // save logo // image // string sLogo = ""; int sLogo = 0; if (isImgPressed) { isImgPressed = false; setVLogo.value = sLogo.ToString(); setVLogo.isSystem = 1; setVLogo.isDefault = 1; setVLogo.settingId = logoId; sLogo = await valueModel.Save(setVLogo); if (!sLogo.Equals(0)) { MainWindow.logoImage = setVLogo.value; string b = await setVLogo.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + sLogo), sLogo); setVLogo.value = b; MainWindow.logoImage = b; sLogo = await valueModel.Save(setVLogo); await valueModel.getImg(setVLogo.value); } } #endregion if (!isFirstTime) { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopSave"), animation: ToasterAnimation.FadeIn); await Task.Delay(1500); } this.Close(); } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } SectionData.ExceptionMessage(ex, this); } }
private async void Btn_update_Click(object sender, RoutedEventArgs e) {//update try { if (sender != null) { SectionData.StartAwait(grid_main); } if (MainWindow.groupObject.HasPermissionAction(basicsPermission, MainWindow.groupObjects, "update") || SectionData.isAdminPermision()) { if (card.cardId > 0) { //chk empty name SectionData.validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "trEmptyNameToolTip"); if ((!tb_name.Text.Equals(""))) { bool isCardExist = await chkDuplicateCard(); if (isCardExist) { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopCardExist"), animation: ToasterAnimation.FadeIn); p_errorName.Visibility = Visibility.Visible; tt_errorName.Content = MainWindow.resourcemanager.GetString("trPopCardExist"); tb_name.Background = (Brush)bc.ConvertFrom("#15FF0000"); } else { card.name = tb_name.Text; card.hasProcessNum = tgl_hasProcessNum.IsChecked; card.notes = tb_notes.Text; card.createUserId = MainWindow.userID; card.updateUserId = MainWindow.userID; //card.isActive = active; int s = await cardModel.save(card); //if (s.Equals("true")) if (s > 0) { Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopUpdate"), animation: ToasterAnimation.FadeIn); if (isImgPressed) { int cardId = s; string b = await cardModel.uploadImage(imgFileName, Md5Encription.MD5Hash("Inc-m" + cardId.ToString()), cardId); card.image = b; isImgPressed = false; if (!b.Equals("")) { getImg(); } else { SectionData.clearImg(img_card); } } } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn); } await RefreshCardsList(); Tb_search_TextChanged(null, null); } } } else { Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trSelectItemFirst"), animation: ToasterAnimation.FadeIn); } } else { Toaster.ShowInfo(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trdontHavePermission"), animation: ToasterAnimation.FadeIn); } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (Exception ex) { if (sender != null) { SectionData.EndAwait(grid_main); } SectionData.ExceptionMessage(ex, this); } }