private void SetBuyerSource()
        {
            Bid     bid     = dgvBid.SelectedItem as Bid;
            Binding binding = new Binding();

            if (bid == null)
            {
                binding.Source = null;
            }
            else
            {
                List <Buyer> buyerList = new List <Buyer>();
                Buyer        buyer     = BuyerViewModel.instance().getById(bid.Id_buyer);
                if (buyer != null)
                {
                    buyerList.Add(buyer);
                    binding.Source = buyerList;
                }
                else
                {
                    binding.Source = null;
                }
            }
            dgvBuyer.SetBinding(DataGrid.ItemsSourceProperty, binding);
        }
Beispiel #2
0
        private bool loadModels()
        {
            CRMSettingViewModel.instance();

            ComplectationItemViewModel.instance();

            EquipmentViewModel.instance();
            ModificationViewModel.instance();
            SellerViewModel.instance();
            BuyerViewModel.instance();
            BidStatusViewModel.instance();
            PaymentStatusViewModel.instance();
            MessageTemplatesViewModel.instance();

            RoleViewModel.instance();
            ManagerViewModel.instance();

            BidViewModel.instance();



            //EquipmentBidViewModel.instance();
            //ComplectationViewModel.instance();

            //ComplectationItemViewModel.instance();

            return(true);
        }
Beispiel #3
0
        //Статистика по клиентам
        private void BuyerStatistic()
        {
            Dictionary <int, int> buyerDict
                = new Dictionary <int, int>();

            for (int i = 0; i < archiveBid.Count; i++)
            {
                if (!buyerDict.ContainsKey(archiveBid[i].Id_buyer))
                {
                    buyerDict.Add(archiveBid[i].Id_buyer, 1);
                }
                else
                {
                    buyerDict[archiveBid[i].Id_buyer]++;
                }
            }
            if (buyerDict.Count == 0)
            {
                return;
            }

            ReportRow rowH = new ReportRow();

            rowH.Add(new ReportCell("Статистика по клиентам:"));
            Rows.Add(rowH);

            ReportRow rowT = new ReportRow();

            rowT.Add(new ReportCell("Покупатель")
            {
                BorderColor = System.Drawing.Color.Black, ColumnSpan = 1
            });
            rowT.Add(null);
            rowT.Add(new ReportCell("Кол-во заявок")
            {
                ColumnSpan = 1, BorderColor = System.Drawing.Color.Black
            });
            Rows.Add(rowT);

            foreach (KeyValuePair <int, int> kv in buyerDict.OrderByDescending(x => x.Value))
            {
                Buyer buyer = BuyerViewModel.instance().getById(kv.Key);
                if (buyer == null)
                {
                    continue;
                }

                ReportRow row = new ReportRow();
                row.Add(new ReportCell(buyer.Name)
                {
                    ColumnSpan = 1, BorderColor = System.Drawing.Color.Black
                });
                row.Add(null);
                row.Add(new ReportCell(kv.Value.ToString())
                {
                    ColumnSpan = 1, BorderColor = System.Drawing.Color.Black
                });
                Rows.Add(row);
            }
        }
Beispiel #4
0
        //Пятая строка (дата отгрузки и покупатель)
        private bool createShipmentDateRow()
        {
            Buyer buyer = BuyerViewModel.instance().getById(bid.Id_buyer);

            if (buyer == null)
            {
                return(false);
            }
            ReportRow row = new ReportRow();

            row.Cells.Add(new ReportCell("Дата отгрузки")
            {
                Height    = 16.50,
                TextStyle = new List <TextStyle>()
                {
                    TextStyle.Bold
                },
                VerticalAlignment = VerticalAlignment.Bottom
            });
            AddEmptyCell(row, 2);
            string shipmentDate = "";

            if (bid.Planned_shipment_date != null)
            {
                shipmentDate = ((DateTime)bid.Planned_shipment_date).ToString("dd.MM.yyyy");
            }
            row.Cells.Add(new ReportCell(shipmentDate)
            {
                ColumnSpan  = 4,
                BorderColor = System.Drawing.Color.Black
            });
            AddEmptyCell(row, 3);
            row.Cells.Add(new ReportCell()
            {
                VerticalAlignment = VerticalAlignment.Bottom
            });
            row.Cells.Add(new ReportCell("Покупатель")
            {
                TextStyle = new List <TextStyle>()
                {
                    TextStyle.Bold
                },
                VerticalAlignment = VerticalAlignment.Bottom
            });
            AddEmptyCell(row, 2);
            row.Cells.Add(new ReportCell(buyer.Name)
            {
                ColumnSpan  = 4,
                BorderColor = Color.Black
            });
            AddEmptyCell(row, 3);
            row.Cells.Add(new ReportCell()
            {
                VerticalAlignment = VerticalAlignment.Bottom
            });
            Rows.Add(row);

            return(true);
        }
 public SelectBuyerPeriodWindow()
 {
     InitializeComponent();
     DataContext = new
     {
         BuyerCollection = BuyerViewModel.instance().Collection
     };
 }
        //Клик по кнопке печати бланков
        void BtnPrintBlank_Click(object sender, RoutedEventArgs e)
        {
            Bid bid = dgvBid.SelectedItem as Bid;

            if (bid == null)
            {
                return;
            }

            Buyer buyer = BuyerViewModel.instance().getById(bid.Id_buyer);

            if (buyer == null)
            {
                return;
            }

            var openFolderDialog = new System.Windows.Forms.FolderBrowserDialog();

            if (iniFile.KeyExists("report_path") && System.IO.Directory.Exists(iniFile.Read("report_path")))
            {
                openFolderDialog.SelectedPath = iniFile.Read("report_path");
            }
            System.Windows.Forms.DialogResult result =
                openFolderDialog.ShowDialog(Classes.OpenDirectoryDialog.GetIWin32Window(this));

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                processControl.Visibility = Visibility.Visible;
                Task.Factory.StartNew(() => {
                    int reportCount = bid.EquipmentBidCollection.Count;
                    for (int i = 0; i < reportCount; i++)
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { processControl.Text = "Формирование бланков " + (i + 1).ToString() + " из " + reportCount.ToString(); }));
                        EquipmentBid equipmentBid = bid.EquipmentBidCollection[i];
                        string fileName           = "Бланк заявки №" + bid.Id.ToString() + "-" + equipmentBid.Id.ToString() + " " + bid.Account + " " + buyer.Name + ".xlsx";
                        Reports.BidBlank bidBlank = new StangradCRM.Reports.BidBlank(bid, equipmentBid);
                        bidBlank.FileName         = openFolderDialog.SelectedPath + "/" + Classes.ReplaceSpecialCharsFileName.Replace(fileName);
                        if (!bidBlank.Save())
                        {
                            MessageBox.Show(bidBlank.LastError);
                            Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { processControl.Visibility = Visibility.Hidden; }));
                            return;
                        }
                        equipmentBid.Is_blank_print = 1;
                        if (!equipmentBid.save())
                        {
                            MessageBox.Show("Не удалось установить статус 'Бланк заявки сформирован' для оборудования в заявке\n" + equipmentBid.LastError);
                            Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { processControl.Visibility = Visibility.Hidden; }));
                            return;
                        }
                    }
                    Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { processControl.Visibility = Visibility.Hidden; }));
                    MessageBox.Show("Все бланки заявок сохранены в директорию '" + openFolderDialog.SelectedPath + "'");
                    iniFile.Write("report_path", openFolderDialog.SelectedPath);
                    System.Diagnostics.Process.Start(openFolderDialog.SelectedPath);
                });
            }
        }
 void MiDataRefresh_Click(object sender, RoutedEventArgs e)
 {
     Classes.UpdateTask.StartSingle(Dispatcher,
                                    new Action(() => {
         BuyerViewModel.instance().reload();
         ComplectationItemViewModel.instance().reload();
         BidViewModel.instance().reload();
     }),
                                    new Action(() => { updateNotification.Visibility = Visibility.Visible; }),
                                    new Action(() => { updateNotification.Visibility = Visibility.Hidden; }));
 }
        public BuyerWindow()
        {
            InitializeComponent();
            viewSource.Source = BuyerViewModel.instance().Collection;

            viewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                Buyer buyer = e.Item as Buyer;
                if (buyer == null)
                {
                    return;
                }
                e.Accepted = buyer.IsVisible;
            };
            DataContext = new { BuyerCollection = viewSource.View };
        }
Beispiel #9
0
        void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            List <Buyer>   buyerList;
            SaveFileDialog sfDialog = new SaveFileDialog();

            if (dpSelectDate.Visibility == Visibility.Visible)
            {
                if (dpSelectDate.SelectedDate == null)
                {
                    MessageBox.Show("Дата не выбрана!");
                    return;
                }
                buyerList         = BuyerViewModel.instance().getByMoreDateCreated((DateTime)dpSelectDate.SelectedDate);
                sfDialog.FileName = "Список покупателей, созданных с " + ((DateTime)dpSelectDate.SelectedDate).ToString("dd.MM.yyyy") + ".xlsx";
            }
            else
            {
                buyerList         = BuyerViewModel.instance().Collection.ToList();
                sfDialog.FileName = "Список покупателей за весь период.xlsx";
            }

            sfDialog.Filter = "Excel 2007 worksheet (*.xlsx)|*.xlsx";
            if (sfDialog.ShowDialog() != true)
            {
                return;
            }

            Reports.BuyerList buyerListReport = new StangradCRM.Reports.BuyerList(buyerList);
            buyerListReport.FileName = sfDialog.FileName;

            loadingProgress.Visibility = Visibility.Visible;
            Task.Factory.StartNew(() =>
            {
                if (!buyerListReport.Save())
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { errorSave(buyerListReport); }));
                }
                else
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { successSave(buyerListReport); }));
                }
            });
        }
        //Фильтры отображени/сокрытия строк таблиц
        private void SetViewSources()
        {
            equipmentBidViewSource.Source  = EquipmentBidViewModel.instance().Collection;
            equipmentBidViewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                EquipmentBid equipmentBid = e.Item as EquipmentBid;
                if (equipmentBid == null)
                {
                    return;
                }

                Bid bid = dgvBid.SelectedItem as Bid;
                if (bid == null)
                {
                    e.Accepted = false;
                    return;
                }
                if (bid.Id == equipmentBid.Id_bid)
                {
                    e.Accepted = true;
                }
                else
                {
                    e.Accepted = false;
                }
            };

            complectationViewSource.Source  = ComplectationViewModel.instance().Collection;
            complectationViewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                Complectation complectation = e.Item as Complectation;
                if (complectation == null)
                {
                    return;
                }

                EquipmentBid equipmentBid = dgvEquipmentBid.SelectedItem as EquipmentBid;
                if (equipmentBid == null)
                {
                    e.Accepted = false;
                    return;
                }
                if (complectation.Id_equipment_bid == equipmentBid.Id)
                {
                    e.Accepted = true;
                }
                else
                {
                    e.Accepted = false;
                }
            };

            buyerViewSource.Source  = BuyerViewModel.instance().Collection;
            buyerViewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                Buyer buyer = e.Item as Buyer;
                if (buyer == null)
                {
                    return;
                }

                Bid bid = dgvBid.SelectedItem as Bid;
                if (bid == null)
                {
                    e.Accepted = false;
                    return;
                }
                if (buyer.Id == bid.Id_buyer)
                {
                    e.Accepted = true;
                }
                else
                {
                    e.Accepted = false;
                }
            };
        }
        //Фильтры отображени/сокрытия строк таблиц
        private void SetViewSources()
        {
            //Установка источника данных оборудования в заявке
            equipmentBidViewSource.Source = EquipmentBidViewModel.instance().Collection;
            //Установка фильтра
            equipmentBidViewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                EquipmentBid equipmentBid = e.Item as EquipmentBid;
                if (equipmentBid == null)
                {
                    return;
                }

                Bid bid = dgvBid.SelectedItem as Bid;
                if (bid == null)
                {
                    e.Accepted = false;
                    return;
                }
                if (bid.Id == equipmentBid.Id_bid)
                {
                    e.Accepted = true;
                }
                else
                {
                    e.Accepted = false;
                }
            };

            //Установка источника данных комплектация
            complectationViewSource.Source = ComplectationViewModel.instance().Collection;
            //Установка фильтра
            complectationViewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                Complectation complectation = e.Item as Complectation;
                if (complectation == null)
                {
                    return;
                }

                EquipmentBid equipmentBid = dgvEquipmentBid.SelectedItem as EquipmentBid;
                if (equipmentBid == null)
                {
                    e.Accepted = false;
                    return;
                }
                if (complectation.Id_equipment_bid == equipmentBid.Id)
                {
                    e.Accepted = true;
                }
                else
                {
                    e.Accepted = false;
                }
            };

            //Установка источника данных покупателей
            buyerViewSource.Source = BuyerViewModel.instance().Collection;
            //Установка фильтра
            buyerViewSource.Filter += delegate(object sender, FilterEventArgs e)
            {
                Buyer buyer = e.Item as Buyer;
                if (buyer == null)
                {
                    return;
                }

                Bid bid = dgvBid.SelectedItem as Bid;
                if (bid == null)
                {
                    e.Accepted = false;
                    return;
                }
                if (buyer.Id == bid.Id_buyer)
                {
                    e.Accepted = true;
                }
                else
                {
                    e.Accepted = false;
                }
            };
        }
Beispiel #12
0
        public override bool Save()
        {
            Bid bid = BidViewModel.instance().getById(equipmentBid.Id_bid);

            if (bid == null)
            {
                LastError = "Bid not found!";
                return(false);
            }
            Buyer buyer = BuyerViewModel.instance().getById(bid.Id_buyer);

            if (buyer == null)
            {
                LastError = "Buyer not found!";
                return(false);
            }

            Equipment equipment = EquipmentViewModel.instance().getById(equipmentBid.Id_equipment);

            if (equipment == null)
            {
                LastError = "Equipment not found!";
                return(false);
            }
            Modification modification = null;

            if (equipmentBid.Id_modification != null)
            {
                modification = ModificationViewModel.instance().getById((int)equipmentBid.Id_modification);
                if (modification != null)
                {
                    modificationString = modification.Name;
                }
            }

            ReportRow row = new ReportRow();

            row.Cells.Add(new ReportCell(buyer.Name.ToUpper())
            {
                ColumnSpan = 6,
                Height     = 20.25,
                TextStyle  = new List <TextStyle>()
                {
                    TextStyle.Bold
                },
            });
            row.Cells.Add(new ReportCell());
            row.Cells.Add(new ReportCell());
            row.Cells.Add(new ReportCell());
            row.Cells.Add(new ReportCell());
            row.Cells.Add(new ReportCell());
            row.Cells.Add(new ReportCell()
            {
                Width = 0.58, VerticalAlignment = VerticalAlignment.Bottom
            });
            row.Cells.Add(new ReportCell(buyer.City.ToUpper())
            {
                ColumnSpan          = 2,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                TextStyle           = new List <TextStyle>()
                {
                    TextStyle.Bold
                },
            });
            row.Cells.Add(new ReportCell()
            {
                Width               = 7.29,
                VerticalAlignment   = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Right
            });
            Rows.Add(row);

            ReportRow row_1 = new ReportRow();

            row_1.Cells.Add(new ReportCell(buyer.Contact_person.ToUpper())
            {
                ColumnSpan = 6,
                TextStyle  = new List <TextStyle>()
                {
                    TextStyle.Bold
                },
            });
            row_1.Cells.Add(new ReportCell());
            row_1.Cells.Add(new ReportCell());
            row_1.Cells.Add(new ReportCell());
            row_1.Cells.Add(new ReportCell());
            row_1.Cells.Add(new ReportCell());
            row_1.Cells.Add(new ReportCell());
            row_1.Cells.Add(new ReportCell(buyer.Phone.ToUpper())
            {
                ColumnSpan = 2,
                TextStyle  = new List <TextStyle>()
                {
                    TextStyle.Bold
                },
                HorizontalAlignment = HorizontalAlignment.Right
            });
            Rows.Add(row_1);

            Rows.Add(new ReportRow());

            ReportRow row_2 = new ReportRow();

            row_2.Cells.Add(new ReportCell(equipment.Name.ToUpper())
            {
                ColumnSpan = 6,
                TextStyle  = new List <TextStyle>()
                {
                    TextStyle.Bold
                }
            });
            row_2.Cells.Add(new ReportCell());
            row_2.Cells.Add(new ReportCell());
            row_2.Cells.Add(new ReportCell());
            row_2.Cells.Add(new ReportCell());
            row_2.Cells.Add(new ReportCell());
            row_2.Cells.Add(new ReportCell());
            row_2.Cells.Add(new ReportCell(serialNumber.ToUpper())
            {
                RowSpan             = 1,
                ColumnSpan          = 2,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom,
                TextStyle           = new List <TextStyle>()
                {
                    TextStyle.Bold
                }
            });
            Rows.Add(row_2);

            ReportRow row_3 = new ReportRow();

            row_3.Cells.Add(new ReportCell(modificationString.ToUpper())
            {
                ColumnSpan = 6,
                TextStyle  = new List <TextStyle>()
                {
                    TextStyle.Bold
                }
            });
            Rows.Add(row_3);

            AllDocumentFontSize = 14;

            return(Create());
        }
Beispiel #13
0
        public void createData()
        {
            double sum = 0;

            for (int i = 0; i < payment.Count; i++)
            {
                Bid bid = BidViewModel.instance().getById(payment[i].Id_bid);
                if (bid == null || bid.Id_seller != seller.Id)
                {
                    continue;
                }

                Buyer buyer = BuyerViewModel.instance().getById(bid.Id_buyer);

                ReportRow row = new ReportRow();
                row.Cells.Add(new ReportCell(bid.Id.ToString())
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    BorderColor         = System.Drawing.Color.Black
                });

                row.Cells.Add(new ReportCell(bid.Account)
                {
                    BorderColor = System.Drawing.Color.Black
                });

                row.Cells.Add(new ReportCell(payment[i].Payment_date.ToString("dd.MM.yyyy"))
                {
                    BorderColor = System.Drawing.Color.Black
                });

                row.Cells.Add(new ReportCell(buyer.Name)
                {
                    BorderColor = System.Drawing.Color.Black
                });

                row.Cells.Add(new ReportCell(payment[i].Paying.ToString())
                {
                    BorderColor = System.Drawing.Color.Black, HorizontalAlignment = HorizontalAlignment.Right, Format = Format.Money
                });

                Rows.Add(row);

                sum += payment[i].Paying;
            }

            ReportRow sumRow = new ReportRow();

            sumRow.Add(new ReportCell());
            sumRow.Add(new ReportCell());
            sumRow.Add(new ReportCell());
            sumRow.Add(new ReportCell("Итого:")
            {
                HorizontalAlignment = HorizontalAlignment.Right
            });
            sumRow.Add(new ReportCell(sum.ToString().Replace(',', '.'))
            {
                HorizontalAlignment = HorizontalAlignment.Right, BorderColor = System.Drawing.Color.Black, Format = Format.Money
            });
            Rows.Add(sumRow);
        }
 void TbxSearch_TextChanged(object sender, TextChangedEventArgs e)
 {
     BuyerViewModel.instance().fastSearch(tbxSearch.Text);
     viewSource.View.Refresh();
 }