Ejemplo n.º 1
0
        private async void Btn_update_Click(object sender, RoutedEventArgs e)
        {//update
            try
            {
                HelpClass.StartAwait(grid_main);
                if (package.packageId > 0)
                {
                    if (HelpClass.validate(requiredControlList, this))
                    {
                        bool isExist = await HelpClass.isCodeExist(tb_code.Text, "", "Packages", package.packageId);

                        if (!isExist)
                        {
                            package.packageCode = tb_code.Text.Trim();
                            package.packageName = tb_packageName.Text;
                            package.details     = tb_details.Text;
                            package.programId   = (int)cb_program.SelectedValue;
                            package.verId       = (int)cb_version.SelectedValue;

                            if (tgl_branch.IsChecked == true)
                            {
                                package.branchCount = -1;
                            }
                            else
                            {
                                if (tb_branchCount.Text.Equals("0"))
                                {
                                    package.branchCount = int.Parse("1");
                                }
                                else
                                {
                                    package.branchCount = int.Parse(tb_branchCount.Text);
                                }
                            }
                            if (tgl_store.IsChecked == true)
                            {
                                package.storeCount = -1;
                            }
                            else
                            {
                                if (tb_storeCount.Text.Equals("0"))
                                {
                                    package.storeCount = int.Parse("1");
                                }
                                else
                                {
                                    package.storeCount = int.Parse(tb_storeCount.Text);
                                }
                            }
                            if (tgl_pos.IsChecked == true)
                            {
                                package.posCount = -1;
                            }
                            else
                            {
                                if (tb_posCount.Text.Equals("0"))
                                {
                                    package.posCount = int.Parse("1");
                                }
                                else
                                {
                                    package.posCount = int.Parse(tb_posCount.Text);
                                }
                            }
                            if (tgl_user.IsChecked == true)
                            {
                                package.userCount = -1;
                            }
                            else
                            {
                                if (tb_userCount.Text.Equals("0"))
                                {
                                    package.userCount = int.Parse("1");
                                }
                                else
                                {
                                    package.userCount = int.Parse(tb_userCount.Text);
                                }
                            }
                            if (tgl_vendor.IsChecked == true)
                            {
                                package.vendorCount = -1;
                            }
                            else
                            {
                                if (tb_vendorCount.Text.Equals("0"))
                                {
                                    package.vendorCount = int.Parse("1");
                                }
                                else
                                {
                                    package.vendorCount = int.Parse(tb_vendorCount.Text);
                                }
                            }
                            if (tgl_customer.IsChecked == true)
                            {
                                package.customerCount = -1;
                            }
                            else
                            {
                                if (tb_customerCount.Text.Equals("0"))
                                {
                                    package.customerCount = int.Parse("1");
                                }
                                else
                                {
                                    package.customerCount = int.Parse(tb_customerCount.Text);
                                }
                            }
                            if (tgl_item.IsChecked == true)
                            {
                                package.itemCount = -1;
                            }
                            else
                            {
                                if (tb_itemCount.Text.Equals("0"))
                                {
                                    package.itemCount = int.Parse("1");
                                }
                                else
                                {
                                    package.itemCount = int.Parse(tb_itemCount.Text);
                                }
                            }
                            if (tgl_saleInv.IsChecked == true)
                            {
                                package.salesInvCount = -1;
                            }
                            else
                            {
                                if (tb_salesInvCount.Text.Equals("0"))
                                {
                                    package.salesInvCount = int.Parse("1");
                                }
                                else
                                {
                                    package.salesInvCount = int.Parse(tb_salesInvCount.Text);
                                }
                            }

                            package.notes        = tb_notes.Text;
                            package.isActive     = 1;
                            package.createUserId = MainWindow.userLogin.userId;
                            package.updateUserId = MainWindow.userLogin.userId;

                            int s = await package.Save(package);

                            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);
                                resetRequiredControlList();
                                await RefreshPackagesList();
                                await Search();
                            }
                        }
                        else
                        {
                            HelpClass.SetValidate(p_error_code, "trDuplicateCodeToolTip");
                        }
                    }
                }
                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);
            }
        }