示例#1
0
        /* constructor that initialize graphic components */
        public BPinventoryView()
        {
            InitializeComponent();

            // initialize export tables
            exportTable[0] = new BPcodedBlankExportTable();
            exportTable[1] = new BPcodedImprintExportTable();
            exportTable[2] = new BPrushCodedBlankExportTable();
            exportTable[3] = new BPrushCodedImprintExportTable();
            exportTable[4] = new BPnetBlankExportTable();
            exportTable[5] = new BPnetImprintExportTable();
            exportTable[6] = new BPrushNetBlankExportTable();
            exportTable[7] = new BPrushNetImprintExportTable();

            // set timers
            for (int i = 0; i <= 7; i++)
            {
                timeLeft[i] = 4;
            }
            timer1.Start(); timer2.Start(); timer3.Start(); timer4.Start(); timer5.Start(); timer6.Start(); timer7.Start(); timer8.Start();

            // set progress
            progressLabel1.Text = 0 + " / " + exportTable[0].Total;
            progressLabel2.Text = 0 + " / " + exportTable[1].Total;
            progressLabel3.Text = 0 + " / " + exportTable[2].Total;
            progressLabel4.Text = 0 + " / " + exportTable[3].Total;
            progressLabel5.Text = 0 + " / " + exportTable[4].Total;
            progressLabel6.Text = 0 + " / " + exportTable[5].Total;
            progressLabel7.Text = 0 + " / " + exportTable[6].Total;
            progressLabel8.Text = 0 + " / " + exportTable[7].Total;

            // call background workers adding data on data grid view
            backgroundWorker1.RunWorkerAsync();
            backgroundWorker2.RunWorkerAsync();
            backgroundWorker3.RunWorkerAsync();
            backgroundWorker4.RunWorkerAsync();
            backgroundWorker5.RunWorkerAsync();
            backgroundWorker6.RunWorkerAsync();
            backgroundWorker7.RunWorkerAsync();
            backgroundWorker8.RunWorkerAsync();

            // set up boolean flag
            for (int i = 0; i <= 7; i++)
            {
                done[i] = false;
            }
        }
示例#2
0
        /* the event for inventory button click */
        private void inventoryButton_Click(object sender, EventArgs e)
        {
            #region Error Check
            // the case if stock quantity table has not been loaded yet
            if (Properties.Settings.Default.StockQuantityTable == null)
            {
                MessageBox.Show(
                    "For performance purpose, please go to\n| VIEW SKU EXPORTS -> Stock Quantity List | and load the table first.",
                    "Sorry", MessageBoxButtons.OK);
                return;
            }

            // local field for excel export
            XlExport export;
            try
            {
                export = new XlExport();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            #endregion

            // save the file
            if (saveFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            // formatting fields
            ds.Reset();
            string[] names = new string[8];
            names[0] = "Coded Blank - CAD";
            names[1] = "Coded Imprinted - CAD";
            names[2] = "Rush Coded Blank - CAD";
            names[3] = "Rush Coded Imprinted- CAD";
            names[4] = "Net Blank - CAD";
            names[5] = "Net Imprinted - CAD";
            names[6] = "Rush Net Blank - CAD";
            names[7] = "Rush Net Imprinted - CAD";
            int[][] textIndex = new int[8][];
            int[]   index     = { 2 };
            for (int i = 0; i < 8; i++)
            {
                textIndex[i] = index;
            }

            // get the save path info
            string extension = saveFileDialog.FileName.Substring(saveFileDialog.FileName.LastIndexOf('.'));
            string path      = saveFileDialog.FileName.Remove(saveFileDialog.FileName.LastIndexOf('.'));

            if (Properties.Settings.Default.BPcodedBlankTable != null &&
                Properties.Settings.Default.BPcodedImprintTable != null &&
                Properties.Settings.Default.BPrushCodedBlankTable != null &&
                Properties.Settings.Default.BPrushCodedImprintTable != null &&
                Properties.Settings.Default.BPnetBlankTable != null &&
                Properties.Settings.Default.BPnetImprintTable != null &&
                Properties.Settings.Default.BPrushNetBlankTable != null &&
                Properties.Settings.Default.BPrushNetImprintTable != null) // tables have already been saved
            {
                #region Table has Loaded Case
                ds.Tables.Add(Properties.Settings.Default.BPcodedBlankTable);
                ds.Tables.Add(Properties.Settings.Default.BPcodedImprintTable);
                ds.Tables.Add(Properties.Settings.Default.BPrushCodedBlankTable);
                ds.Tables.Add(Properties.Settings.Default.BPrushCodedImprintTable);
                ds.Tables.Add(Properties.Settings.Default.BPnetBlankTable);
                ds.Tables.Add(Properties.Settings.Default.BPnetImprintTable);
                ds.Tables.Add(Properties.Settings.Default.BPrushNetBlankTable);
                ds.Tables.Add(Properties.Settings.Default.BPrushNetImprintTable);

                // the case if the save tables are in USD -> change sheets' names to USD
                if (Currency.BrightpearlCurrency == "USD")
                {
                    names[0] = "Coded Blank - USD";
                    names[1] = "Coded Imprinted - USD";
                    names[2] = "Rush Coded Blank - USD";
                    names[3] = "Rush Coded Imprinted- USD";
                    names[4] = "Net Blank - USD";
                    names[5] = "Net Imprinted - USD";
                    names[6] = "Rush Net Blank - USD";
                    names[7] = "Rush Net Imprinted - USD";
                }

                try
                {
                    // export the excel files
                    export.NowExport(path + '_' + Currency.BrightpearlCurrency + extension, ds, names, textIndex);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (Currency.BrightpearlCurrency == "USD")
                {
                    // change currency for each table -> to CAD
                    foreach (DataTable table in ds.Tables)
                    {
                        // change currency for each row in the table -> to CAD
                        foreach (DataRow row in table.Rows)
                        {
                            double[] costList = new double[9];
                            string   cost     = row[4].ToString();

                            costList[0] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[1] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[2] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[3] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[4] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[5] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[6] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[7] = double.Parse(cost.Remove(cost.IndexOf(';'))) / usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[8] = double.Parse(cost) / usd;

                            row[4] = costList[0] + "; " + costList[1] + "; " + costList[2] + "; " + costList[3] + "; " + costList[4] + "; " + costList[5] + "; " + costList[6] + "; " +
                                     costList[7] + "; " + costList[8];
                        }
                    }

                    // change sheets' names to CAD
                    names[0] = "Coded Blank - CAD";
                    names[1] = "Coded Imprinted - CAD";
                    names[2] = "Rush Coded Blank - CAD";
                    names[3] = "Rush Coded Imprinted- CAD";
                    names[4] = "Net Blank - CAD";
                    names[5] = "Net Imprinted - CAD";
                    names[6] = "Rush Net Blank - CAD";
                    names[7] = "Rush Net Imprinted - CAD";

                    try
                    {
                        // export the excel files
                        export = new XlExport();
                        export.NowExport(path + "_CAD" + extension, ds, names, textIndex);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    // change currency for each table -> to USD
                    foreach (DataTable table in ds.Tables)
                    {
                        // change currency for each row in the table -> to USD
                        foreach (DataRow row in table.Rows)
                        {
                            double[] costList = new double[9];
                            string   cost     = row[4].ToString();

                            costList[0] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[1] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[2] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[3] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[4] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[5] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[6] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[7] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[8] = double.Parse(cost) * usd;

                            row[4] = costList[0] + "; " + costList[1] + "; " + costList[2] + "; " + costList[3] + "; " + costList[4] + "; " + costList[5] + "; " + costList[6] + "; " +
                                     costList[7] + "; " + costList[8];
                        }
                    }

                    // change sheets' names to USD
                    names[0] = "Coded Blank - USD";
                    names[1] = "Coded Imprinted - USD";
                    names[2] = "Rush Coded Blank - USD";
                    names[3] = "Rush Coded Imprinted- USD";
                    names[4] = "Net Blank - USD";
                    names[5] = "Net Imprinted - USD";
                    names[6] = "Rush Net Blank - USD";
                    names[7] = "Rush Net Imprinted - USD";

                    try
                    {
                        // export the excel files
                        export = new XlExport();
                        export.NowExport(path + "_USD" + extension, ds, names, textIndex);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                #endregion
            }
            else // load the tables
            {
                #region Table has not Loaded Case
                exportTables    = new ExportTable[8];
                exportTables[0] = new BPcodedBlankExportTable();
                exportTables[1] = new BPcodedImprintExportTable();
                exportTables[2] = new BPrushCodedBlankExportTable();
                exportTables[3] = new BPrushCodedImprintExportTable();
                exportTables[4] = new BPnetBlankExportTable();
                exportTables[5] = new BPnetImprintExportTable();
                exportTables[6] = new BPrushNetBlankExportTable();
                exportTables[7] = new BPrushNetImprintExportTable();
                ExportTableLoadingForm form = new ExportTableLoadingForm(exportTables);
                form.ShowDialog(this);

                if (form.Complete) // the tables have complete
                {
                    // get the data
                    ds = form.Tables;

                    try
                    {
                        // export the excel files
                        export.NowExport(path + "_CAD" + extension, ds, names, textIndex);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    // change currency for each table -> to USD
                    foreach (DataTable table in ds.Tables)
                    {
                        // change currency for each row in the table -> to USD
                        foreach (DataRow row in table.Rows)
                        {
                            double[] costList = new double[9];
                            string   cost     = row[4].ToString();

                            costList[0] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[1] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[2] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[3] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[4] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[5] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[6] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[7] = double.Parse(cost.Remove(cost.IndexOf(';'))) * usd;
                            cost        = cost.Substring(cost.IndexOf(';') + 2);

                            costList[8] = double.Parse(cost) * usd;

                            row[4] = costList[0] + "; " + costList[1] + "; " + costList[2] + "; " + costList[3] + "; " + costList[4] + "; " + costList[5] + "; " + costList[6] + "; " +
                                     costList[7] + "; " + costList[8];
                        }
                    }

                    // change sheets' names to USD
                    names[0] = "Coded Blank - USD";
                    names[1] = "Coded Imprinted - USD";
                    names[2] = "Rush Coded Blank - USD";
                    names[3] = "Rush Coded Imprinted- USD";
                    names[4] = "Net Blank - USD";
                    names[5] = "Net Imprinted - USD";
                    names[6] = "Rush Net Blank - USD";
                    names[7] = "Rush Net Imprinted - USD";

                    try
                    {
                        // export the excel files
                        export = new XlExport();
                        export.NowExport(path + "_USD" + extension, ds, names, textIndex);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else // user close the form early
                {
                    return;
                }

                Properties.Settings.Default.ActivePriceTable = ds.Tables[0];
                #endregion
            }

            ShowExportMessage(saveFileDialog.FileName);
        }