private void SetCustomerDg2()
        {
            // Get customers that has no sales assign to from ForecastOrder table
            DataTable dt = ForecastOrderBLL.getCustomerWithNoSalesFo();

            if (dt.Rows.Count != 0)
            {
                dgCustomerData2.ItemsSource = dt.DefaultView;

                // Set sales dropdown in datagrid
                dt = SalesBLL.getSalesAll();
                var Sales = new List <string>();
                Sales.Add("==請選擇業務==");
                foreach (DataRow dr in dt.Rows)
                {
                    Sales.Add(dr[0].ToString() + "-" + dr[1].ToString());
                }
                dgCbSales2.ItemsSource = Sales;
                btnSave2.IsEnabled     = true;
            }
            else
            {
                btnSave2.IsEnabled = false;
            }

            dt = null;
        }
        private void btnExportReport_Click(object sender, RoutedEventArgs e)
        {
            // Create report
            ReportsBLL.calculateReport(Convert.ToInt32(this.lbReportYear.Content));

            // Insert data into excel sheet
            using (ExcelPackage p = new ExcelPackage())
            {
                // Here setting some document properties
                p.Workbook.Properties.Author = "YM";
                p.Workbook.Properties.Title  = "Sales Monthly Report";

                // Create a sheet
                p.Workbook.Worksheets.Add("WorkSheet");
                ExcelWorksheet ws = p.Workbook.Worksheets[1];


                // Write to excel sheet 1
                // sheet 1 table 1 = s1t1, sheet 1 table 2 = s1t2, sheet 1 table 3 = s1t3
                int currentRow = 1;
                currentRow = writeToExcel("s1t1", currentRow, ws, "");
                currentRow = writeToExcel("s1t2", currentRow, ws, "");
                writeToExcel("s1t3", currentRow, ws, "");
                // Write to excel sheet 2
                currentRow = 1;
                p.Workbook.Worksheets.Add("WorkSheet2");
                ExcelWorksheet ws2 = p.Workbook.Worksheets[2];
                p.Workbook.Worksheets.Add("WorkSheet3");
                ExcelWorksheet ws3 = p.Workbook.Worksheets[3];
                DataTable      dt  = SalesBLL.getSalesAll();
                if (dt.Rows.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        currentRow = writeToExcel("s2", currentRow, ws2, dr["Id"].ToString());
                    }
                    // Write s2 Total
                    writeToExcel("s2", currentRow + 2, ws2, "");

                    currentRow = 1;
                    foreach (DataRow dr in dt.Rows)
                    {
                        currentRow = writeToExcel("s3", currentRow, ws3, dr["Id"].ToString());
                    }
                    // Write s3 Total
                    writeToExcel("s3", currentRow + 2, ws3, "");
                }

                // Generate A File with Random name
                Byte[] bin = p.GetAsByteArray();
                //string file = "d:\\" + Guid.NewGuid().ToString() + ".xlsx";
                string savePath = saveFile();
                string file     = savePath;
                File.WriteAllBytes(file, bin);
                System.Windows.Forms.MessageBox.Show("檔案儲存完畢", "Message");
            }
        }
        private void SetCurrentSales()
        {
            DataTable dt = SalesBLL.getSalesAll();

            dgCurrentSales.ItemsSource = dt.DefaultView;
            cbSales01.Items.Clear();
            cbSales02.Items.Clear();
            foreach (DataRow dr in dt.Rows)
            {
                cbSales01.Items.Add(dr[0].ToString() + "-" + dr[1].ToString());
                cbSales02.Items.Add(dr[0].ToString() + "-" + dr[1].ToString());
            }
            cbSales01.SelectedIndex = 0;
            cbSales02.SelectedIndex = 0;
            dt = null;
        }
        private void Initialize()
        {
            // Set year dropdown
            int year = DateTime.Now.Year + 1;

            for (int i = 0; i < 3; i++)
            {
                cbYear.Items.Add((year - i).ToString());
            }
            cbYear.SelectedIndex = 0;

            // Set sales dropdown
            DataTable dt = SalesBLL.getSalesAll();

            foreach (DataRow dr in dt.Rows)
            {
                cbSales.Items.Add(dr[0].ToString() + "-" + dr[1].ToString());
            }
            cbSales.SelectedIndex = 0;
            dt = null;
        }