示例#1
0
        private async void Btn_add_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (sender != null)
                {
                    SectionData.StartAwait(grid_main);
                }
                //add
                if (MainWindow.groupObject.HasPermissionAction(basicsPermission, MainWindow.groupObjects, "add") || SectionData.isAdminPermision())
                {
                    //chk empty name
                    SectionData.validateEmptyTextBox(tb_name, p_errorName, tt_errorName, "trEmptyNameToolTip");
                    //chk not exist
                    string txt     = tb_name.Text;
                    bool   isExist = medalsQuery.Any(i => i.name == tb_name.Text);

                    if (isExist)
                    {
                        p_errorName.Visibility = Visibility.Visible;
                        tt_errorName.Content   = MainWindow.resourcemanager.GetString("trDublicateMedal");
                        tb_name.Background     = (Brush)bc.ConvertFrom("#15FF0000");
                    }

                    if ((!tb_name.Text.Equals("")) && !isExist)
                    {
                        int cashPoint = 0, invoiceCount = 0;
                        if (!tb_cashPointsRequired.Text.Equals(""))
                        {
                            cashPoint = Convert.ToInt32(tb_cashPointsRequired.Text);
                        }
                        if (!tb_invoiceCountPointsRequired.Text.Equals(""))
                        {
                            invoiceCount = Convert.ToInt32(tb_invoiceCountPointsRequired.Text);
                        }

                        Medal medal = new Medal();

                        medal.name  = tb_name.Text;
                        medal.notes = tb_notes.Text;
                        //medal.symbol = path_symbol.Data.ToString();
                        medal.CashPointsRequired         = cashPoint;
                        medal.invoiceCountPointsRequired = invoiceCount;
                        medal.createUserId = MainWindow.userID;
                        medal.isActive     = 0;

                        string s = await medalModel.Save(medal);

                        if (!s.Equals("0"))
                        {
                            Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopAdd"), animation: ToasterAnimation.FadeIn);
                            Btn_clear_Click(null, null);
                        }
                        else
                        {
                            Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn);
                        }

                        await RefreshMedalsList();

                        Tb_search_TextChanged(null, null);
                    }
                }
                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);
            }
        }