Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            MainStatus _mainStatus = MainStatus.getInstance();
            Status status = _mainStatus.Get();

            foreach (DataGridViewCell cell in _dgvMain.SelectedCells)
            {
                Car car = _dgvMain.GetCar();

                DateTime date = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, 1);

                CreateDocument excelWayBill;

                try
                {
                    excelWayBill = (status == Status.Invoice) ? CreateWayBill(car, date, _dgvMain.GetID(cell.RowIndex)) : CreateWayBill(car, date);
                }
                catch (NullReferenceException)
                {
                    continue;
                }

                if (_action == Actions.Print)
                    excelWayBill.Print();
                else
                    excelWayBill.Show();
            }

            if (_action == Actions.Print)
            {
                MyPrinter printer = new MyPrinter();
                MessageBox.Show("Документы отправлены на печать на принтер " + printer.GetDefaultPrinterName(), "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
        private ToolStripMenuItem CreatePrintAllTable()
        {
            ToolStripMenuItem item = CreateItem("Текущий справочник");
            item.Click += delegate
            {
                MyPrinter myprinter = new MyPrinter();

                string printerName = myprinter.GetDefaultPrinterName();

                if (string.IsNullOrEmpty(printerName))
                {
                    MessageBox.Show("Принтер по умолчанию не найден", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string message = string.Concat("Вывести справочник \"", _mainStatus.ToString(), "\" на печать на принтер ", printerName, "?");

                if (MessageBox.Show(message, "Печать", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    CreateDocument doc = DgvToExcel();
                    doc.Print();
                }
            };
            return item;
        }