コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }