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 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);
            }
        }
示例#3
0
        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);
            }
        }