示例#1
0
        private void btnCreateTempExcel_Click(object sender, System.EventArgs e)
        {
            try
            {
                ExcelInputInfoModel.Port           = tbPort.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.Supplier       = tbSupplier.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.Product        = tbProduct.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.Quantity       = tbQuantity.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.Date           = tbDate.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.VehicleNumber  = tbVehicleNumber.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.TTNNumber      = tbTTNNumber.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.Contract       = tbContact.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.SheetNumber    = tbSheetNumber.Text.ParseToInt().Value - 1;
                ExcelInputInfoModel.StartRowNumber = tbStartRowNumber.Text.ParseToInt().Value - 1;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, Constants.ParamsInputErrorMessage, Constants.ErrorMessage);
                return;
            }

            if (String.IsNullOrEmpty(ExcelInputInfoModel.InputFilePath) ||
                String.IsNullOrEmpty(ExcelInputInfoModel.OutputTempFolderPath))
            {
                MessageBox.Show(this, Constants.InputFileAndDirectoryExistanceErrorMessage, Constants.ErrorMessage);
                return;
            }

            try
            {
                SupplierContractsOutputList = _excelService.CreateTempExcelFile(ExcelInputInfoModel);
            }
            catch (Exception ex)
            {
                FormsLogger.FormsLoggerInstance.Error(ex);
                MessageBox.Show(this, Constants.InputExcelErrorMessage, Constants.ErrorMessage);
                return;
            }

            _excelapp = new Excel.Application
            {
                Visible = true
            };

            var excelappworkbook = _excelapp.Workbooks.Open(Path.Combine(ExcelInputInfoModel.OutputTempFolderPath, FileContants.TEMP_EXCEL_FILE_NAME),
                                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                            Type.Missing, Type.Missing);

            var excelsheets = excelappworkbook.Worksheets;

            _contractsWorksheet = (Excel.Worksheet)excelsheets.Item[1];

            _contractsWorksheet.Change += ExcelworksheetOnChange;
        }