Ejemplo n.º 1
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            var done = true;

            if (CheckForSameItem())
            {
                return;
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var addBoxItem = panelChild as AddBoxUC;
                if (string.IsNullOrWhiteSpace(addBoxItem.TxtTitle.SearchText) && addBoxItem.BtnNewRecord.Visibility == Visibility.Hidden)
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "عنوان نمیتواند خالی باشد",
                        Caption         = "مقادیر عنوان را وارد کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var addBoxItem = panelChild as AddBoxUC;
                if (string.IsNullOrWhiteSpace(addBoxItem.TxtUserQty.Text) && addBoxItem.BtnNewRecord.Visibility == Visibility.Hidden)
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "مقدار نمیتواند خالی باشد",
                        Caption         = "مقدار را وارد کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var addBoxItem = panelChild as AddBoxUC;
                if (string.IsNullOrWhiteSpace(addBoxItem.ComboBoxUnitQty.Text) && addBoxItem.ComboBoxUnitQty.Visibility == Visibility.Visible)
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "واحد مقدار نمیتواند خالی باشد",
                        Caption         = "واحد مقدار را انتخاب کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var addBoxItem = panelChild as AddBoxUC;
                if (string.IsNullOrWhiteSpace(addBoxItem.TxtPrice.Text) && addBoxItem.TxtPrice.IsEnabled == true && addBoxItem.TxtPrice.Visibility == Visibility.Visible)
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "قیمت نمیتواند خالی باشد",
                        Caption         = "مقادیر قیمت را وارد کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var addBoxItem = panelChild as AddBoxUC;
                if (addBoxItem.TxtTitle.SelectedItem != null)
                {
                    var selectedWarningWindow = new RemoveWindow()
                    {
                        WindowTitle = "کالا موجود است",
                        Caption     = "نام کالا موجود است.\nمقدار مورد نظر به کالای موجود افزوده میشود.",
                        Btn1        = "ادامه",
                        Btn2        = "انصراف"
                    };
                    selectedWarningWindow.ShowDialog();
                    if (selectedWarningWindow.Accept)
                    {
                        break;
                    }
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var addBoxItem = panelChild as AddBoxUC;
                if (addBoxItem.BtnNewRecord.Visibility == Visibility.Visible)
                {
                    break;
                }
                var byPpl = false;
                if (addBoxItem.RadioButtonByPpl.IsChecked == true)
                {
                    addBoxItem.TxtPrice.Text = "0";
                    byPpl = true;
                }

                if (addBoxItem.TxtTitle.SelectedItem == null)
                {
                    var cata = _catalogItems.Single(c =>
                                                    c.CatalogId == Convert.ToInt32(addBoxItem.ComboBoxUnitQty.SelectedValue.ToString()));
                    if (!ProductTable.InsertIntoProductTable(new Product()
                    {
                        ProductName = addBoxItem.TxtTitle.SearchText,
                        ProductCount = double.Parse(addBoxItem.TxtUserQty.Text),
                        ProductUnitPrice = int.Parse(addBoxItem.TxtPrice.Text),
                        ProductPopularSupport = byPpl,
                        ProductDescription = addBoxItem.TxtDescription.Text,
                        Catalog = cata
                    }))
                    {
                        done = false;
                    }
                }
                else
                {
                    var newCount = double.Parse(addBoxItem.TxtUserQty.Text.Replace(" ", string.Empty)) + double.Parse(addBoxItem.LblQty.Content.ToString());
                    if (!ProductTable.UpdateQty(int.Parse(addBoxItem.LblId.ToString()), newCount))
                    {
                        done = false;
                    }
                }
            }
            if (!done)
            {
                return;
            }
            var windowWarning = new RemoveWindow()
            {
                WindowTitle     = "موفقیت آمیز",
                Caption         = "عملیات با موفقیت انجام شد.",
                InformationIcon = true,
                OneBtn          = true,
                Btn2            = "باشه"
            };

            windowWarning.ShowDialog();
            ResetNameTextBoxFocus();
        }
Ejemplo n.º 2
0
        private void BtnInventoryRequest_Click(object sender, RoutedEventArgs e)
        {
            var needRequestDocument = false;

            if (CheckForSameItem())
            {
                return;
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var searchItem = panelChild as SearchBoxUC;
                if (searchItem.LblStatus.Content.ToString() == "نیاز به خرید")
                {
                    needRequestDocument = true;
                    break;
                }
            }
            if (!needRequestDocument)
            {
                var windowRemove = new RemoveWindow
                {
                    WindowTitle     = "اقلام لیست در انبار موجود است",
                    Caption         = "کسری موجودی برای درخواست خرید نیست.",
                    InformationIcon = true,
                    OneBtn          = true,
                    Btn2            = "باشه"
                };
                windowRemove.ShowDialog();
                return;
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var searchItem = panelChild as SearchBoxUC;
                if (searchItem.BtnNewRecord.Visibility == Visibility.Visible)
                {
                    break;
                }
                if (string.IsNullOrWhiteSpace(searchItem.SearchBox.SearchText))
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "عنوان نمیتواند خالی باشد",
                        Caption         = "مقادیر عنوان را وارد کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var searchItem = panelChild as SearchBoxUC;
                if (searchItem.BtnNewRecord.Visibility == Visibility.Visible)
                {
                    break;
                }
                if (string.IsNullOrWhiteSpace(searchItem.TxtUserQty.Text))
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "مقدار نمیتواند خالی باشد",
                        Caption         = "مقدار را وارد کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            foreach (var panelChild in PanelProductRecord.Children)
            {
                var searchItem = panelChild as SearchBoxUC;
                if (searchItem.BtnNewRecord.Visibility == Visibility.Visible)
                {
                    break;
                }
                if (!string.IsNullOrWhiteSpace(searchItem.LblQtyWithUnit.Content.ToString()))
                {
                    continue;
                }
                if (searchItem.ComboBoxUnitQty.SelectedValue == null)
                {
                    var windowRemove = new RemoveWindow
                    {
                        WindowTitle     = "مقدار نمیتواند خالی باشد",
                        Caption         = "مقدار را وارد کنید.",
                        InformationIcon = true,
                        OneBtn          = true,
                        Btn2            = "باشه"
                    };
                    windowRemove.ShowDialog();
                    return;
                }
            }
            var windowWarning = new RemoveWindow
            {
                WindowTitle = "ایجاد درخواست خرید",
                Caption     = "با ایجاد درخواست خرید مقادیر به موجودی افزوده میشوند.\nادامه میدهید؟",
                Btn1        = "ادامه",
                Btn2        = "انصراف"
            };

            windowWarning.ShowDialog();
            if (windowWarning.Accept)
            {
                int        dataIndex = 0;
                int        gapItem   = 0;
                String[][] data      = new string[PanelProductRecord.Children.Count][];
                foreach (var panelChild in PanelProductRecord.Children)
                {
                    var searchBoxItem = panelChild as SearchBoxUC;


                    if (searchBoxItem.LblStatus.Content.ToString() == "نیاز به خرید")
                    {
                        var qty    = searchBoxItem.TxtUserQty.Text.Replace("  ", String.Empty);
                        var produc = searchBoxItem.SearchBox.SelectedItem as Product;
                        if (searchBoxItem.SearchBox.SelectedItem != null)
                        {
                            qty = " " + produc.Catalog.CatalogValue + ((produc.ProductCount - double.Parse(searchBoxItem.TxtUserQty.Text.Replace(" ", String.Empty))) * -1);
                        }
                        else
                        {
                            qty = " " + searchBoxItem.ComboBoxUnitQty.Text + qty;
                        }
                        data[dataIndex] = new[] { "", searchBoxItem.SearchBox.SearchText, qty, (dataIndex + 1).ToString() };
                        dataIndex++;
                        if (searchBoxItem.SearchBox.SelectedItem != null)
                        {
                            ProductTable.UpdateProductTabel(new Product()
                            {
                                ProductId             = produc.ProductId,
                                ProductName           = produc.ProductName,
                                ProductUnitPrice      = produc.ProductUnitPrice,
                                ProductCount          = double.Parse(searchBoxItem.TxtUserQty.Text.Replace(" ", String.Empty)),
                                ProductPopularSupport = produc.ProductPopularSupport,
                                ProductDescription    = produc.ProductDescription
                            });
                        }
                        else
                        {
                            ProductTable.InsertIntoProductTable(new Product()
                            {
                                ProductName           = searchBoxItem.SearchBox.SearchText,
                                ProductCount          = double.Parse(searchBoxItem.TxtUserQty.Text.Replace(" ", string.Empty)),
                                Catalog               = CatalogTable.SelectFromCatalogTable().Single(c => c.CatalogId == int.Parse(searchBoxItem.ComboBoxUnitQty.SelectedValue.ToString())),
                                ProductUnitPrice      = 0,
                                ProductData           = persianDate,
                                ProductPopularSupport = false,
                                ProductDescription    = ""
                            });
                        }
                    }
                    else
                    {
                        gapItem++;
                    }
                }
                PrintDocuments.RequestDocument(data, gapItem);
                ConfirmInventory();
            }
        }