public DataTable M_StoreClose_Check(M_StoreClose_Entity msce, string mode)
 {
     return(mscdl.M_StoreClose_Check(msce, mode));
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.Title = "GetsujiShiireSyuukeiSyori";

            if (loginbl.ReadConfig() == true)
            {
                //コマンドライン引数を配列で取得する
                string[] cmds = System.Environment.GetCommandLineArgs();

                if (cmds.Length - 1 >= (int)FrmMainForm.ECmdLine.PcID + 1)
                {
                    InOperatorCD   = cmds[(int)FrmMainForm.ECmdLine.OperatorCD];
                    InStoreCD      = cmds[(int)FrmMainForm.ECmdLine.PcID + 1];
                    InProcessMode  = cmds[(int)FrmMainForm.ECmdLine.PcID + 2];
                    InFiscalYYYYMM = cmds[(int)FrmMainForm.ECmdLine.PcID + 3].Replace("/", "");
                }

                gsbl = new GetsujiShimeShori_BL();

                //処理モードを覚える
                M_Control_Entity mce = new M_Control_Entity();
                mce.MainKey = "1";
                Mode        = gsbl.GetMode(mce);

                bool execFlg = false;

                M_StoreClose_Entity me = new M_StoreClose_Entity();
                if (Mode.Equals(1))
                {
                    //Mode		=	1	の場合			(=ALL店舗)
                }
                else if (Mode.Equals(2))
                {
                    //Mode		=	2	の場合			(=店舗ごとに計算)
                    me.StoreCD = InStoreCD;
                }
                bool ret = gsbl.M_StoreClose_SelectAll(me);
                if (ret)
                {
                    //FiscalYYYYMM<Parameter受取	FiscalYYYYMM
                    //またはFiscalYYYYMM=Parameter受取	FiscalYYYYMM&	ClosePosition5=0なら
                    if (gsbl.Z_Set(me.FiscalYYYYMM) <= gsbl.Z_Set(InFiscalYYYYMM))
                    {
                        if (gsbl.Z_Set(me.FiscalYYYYMM) == gsbl.Z_Set(InFiscalYYYYMM))
                        {
                            if (me.ClosePosition5.Equals("0"))
                            {
                                execFlg = true;
                            }
                        }
                        else
                        {
                            execFlg = true;
                        }
                        InFiscalYYYYMM = me.FiscalYYYYMM;
                    }
                }

                if (execFlg)
                {
                    //【データ更新】
                    D_MonthlyPurchase_Entity de = new D_MonthlyPurchase_Entity
                    {
                        PC       = Login_BL.GetHostName(),
                        Operator = InOperatorCD,
                        YYYYMM   = InFiscalYYYYMM,
                        StoreCD  = InStoreCD,
                        Mode     = Mode
                    };

                    api.ExecUpdate(de);
                }
            }
        }
        /// <summary>
        /// 月次締処理
        /// SeikyuuShimeShoriより更新時に使用
        /// </summary>
        public bool M_StoreClose_Update(M_StoreClose_Entity me)
        {
            M_StoreClose_DL dl = new M_StoreClose_DL();

            return(dl.M_StoreClose_Update(me));
        }
        /// <summary>
        /// Error Check for the whole form
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private bool ErrorCheck(int index)
        {
            if (index == 11)
            {
                if (type == 1)
                {
                    DataTable dtpay = new DataTable();
                    dpe.LargePayNO = ScPaymentProcessNum.TxtCode.Text;
                    dtpay          = sibl.D_Pay_LargePayNoSelect(dpe);
                    if (dtpay.Rows.Count == 0)
                    {
                        sibl.ShowMessage("E138");
                        ScPaymentProcessNum.SetFocus(1);
                        return(false);
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(dtpay.Rows[0]["DeleteDateTime"].ToString()))
                        {
                            sibl.ShowMessage("E140");
                            ScPaymentProcessNum.SetFocus(1);
                            return(false);
                        }
                    }
                }

                else if (type == 2)
                {
                    if (!RequireCheck(new Control[] { ScPaymentNum.TxtCode }))
                    {
                        return(false);
                    }

                    DataTable dtpayno = new DataTable();
                    dpe.PayNo = ScPaymentNum.TxtCode.Text;
                    dtpayno   = sibl.D_Pay_PayNoSelect(dpe);
                    if (dtpayno.Rows.Count == 0)
                    {
                        sibl.ShowMessage("E138");
                        ScPaymentNum.SetFocus(1);
                        return(false);
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(dtpayno.Rows[0]["DeleteDateTime"].ToString()))
                        {
                            sibl.ShowMessage("E140");
                            ScPaymentNum.SetFocus(1);
                            return(false);
                        }
                        if (!string.IsNullOrWhiteSpace(dtpayno.Rows[0]["FBCreateDate"].ToString()))
                        {
                            sibl.ShowMessage("E144");
                            ScPaymentNum.SetFocus(1);
                            return(false);
                        }
                        txtPaymentDate.Text         = dtpayno.Rows[0]["PayDate"].ToString();
                        mfye.InputPossibleStartDate = txtPaymentDate.Text;
                        mfye.InputPossibleEndDate   = txtPaymentDate.Text;
                        DataTable dtcontrol = new DataTable();
                        dtcontrol = sibl.M_Control_PaymentSelect(mfye);
                        if (dtcontrol.Rows.Count == 0)
                        {
                            sibl.ShowMessage("E115");
                            ScPaymentNum.SetFocus(1);
                            return(false);
                        }
                        //else
                        //{
                        //    DataDisplay();
                        //}
                    }
                }

                else if (type == 3)
                {
                    if (!RequireCheck(new Control[] { txtDueDate2 }))
                    {
                        return(false);
                    }
                    else
                    {
                        int result = txtDueDate1.Text.CompareTo(txtDueDate2.Text);
                        if (result > 0)
                        {
                            sibl.ShowMessage("E104");
                            txtDueDate2.Focus();
                        }
                    }

                    //if (!RequireCheck(new Control[] { ScPayee.TxtCode }))
                    //    return false;
                    //else
                    //if(!string.IsNullOrWhiteSpace(ScPayee.TxtCode.Text))
                    //{
                    mve.VendorCD      = ScPayee.TxtCode.Text;
                    mve.ChangeDate    = DateTime.Now.ToString("yyyy/MM/dd");
                    mve.MoneyPayeeFlg = "1";
                    DataTable dtvendor = new DataTable();
                    dtvendor = sibl.M_Vendor_Select(mve);
                    if (dtvendor.Rows.Count == 0)
                    {
                        sibl.ShowMessage("E101");
                        ScPayee.SetFocus(1);
                        return(false);
                    }
                    else
                    {
                        ScPayee.LabelText = dtvendor.Rows[0]["VendorName"].ToString();
                    }
                    //}
                }
            }
            else if (index == 12)
            {
                if (!RequireCheck(new Control[] { txtPaymentDate }))
                {
                    return(false);
                }

                mfye.InputPossibleStartDate = txtPaymentDate.Text;
                mfye.InputPossibleEndDate   = txtPaymentDate.Text;
                DataTable dtcontrol = new DataTable();
                dtcontrol = sibl.M_Control_PaymentSelect(mfye);
                if (dtcontrol.Rows.Count == 0)
                {
                    sibl.ShowMessage("E115");
                    ScPaymentNum.SetFocus(1);
                    return(false);
                }

                //店舗の締日チェック
                //店舗締マスターで判断
                M_StoreClose_Entity msce = new M_StoreClose_Entity();
                msce.StoreCD      = InOperatorCD;
                msce.FiscalYYYYMM = txtPaymentDate.Text.Replace("/", "").Substring(0, 6);
                DataTable dtposition = sibl.CheckClosePosition(msce);
                if (dtposition.Rows.Count > 0)
                {
                    if (dtposition.Rows[0]["ClosePosition2"].ToString() == "1")
                    {
                        sibl.ShowMessage("E203");
                        return(false);
                    }
                    else if (dtposition.Rows[0]["ClosePosition2"].ToString() == "2")
                    {
                        sibl.ShowMessage("E194");
                        return(false);
                    }
                }

                if (!RequireCheck(new Control[] { ScStaff.TxtCode }))
                {
                    return(false);
                }
                else
                {
                    mse.StaffCD    = ScStaff.TxtCode.Text;
                    mse.ChangeDate = txtPaymentDate.Text;
                    DataTable dtstaff = new DataTable();
                    dtstaff = sibl.M_Staff_Select(mse);
                    //if (!ScStaff.SelectData())
                    if (dtstaff.Rows.Count == 0)
                    {
                        sibl.ShowMessage("E101");
                        ScStaff.SetFocus(1);
                        return(false);
                    }
                    else
                    {
                        ScStaff.LabelText = dtstaff.Rows[0]["StaffName"].ToString();
                    }
                }

                //if (!RequireCheck(new Control[] {cboPaymentType}))
                if (string.IsNullOrWhiteSpace(cboPaymentType.SelectedValue.ToString()))
                {
                    sibl.ShowMessage("E102");
                    cboPaymentType.Focus();
                    return(false);
                }
                else
                {
                    mmpe.ID = "314";
                    DataTable dtmulti = new DataTable();
                    dtmulti = sibl.M_MultiPorpose_Select(mmpe);
                    if (dtmulti.Rows.Count == 0)
                    {
                        sibl.ShowMessage("E128");
                        cboPaymentType.Focus();
                        return(false);
                    }
                    else
                    {
                        string name = dtmulti.Rows[0]["Char1"].ToString();
                    }
                }

                if (string.IsNullOrWhiteSpace(cboPaymentSourceAcc.SelectedValue.ToString()))
                {
                    sibl.ShowMessage("E102");
                    cboPaymentSourceAcc.Focus();
                    return(false);
                }
                mke.ChangeDate = txtPaymentDate.Text;
                DataTable dtkouza = new DataTable();
                dtkouza = sibl.M_Kouza_SelectByDate(mke);
                if (dtkouza.Rows.Count == 0)
                {
                    sibl.ShowMessage("E128");
                    cboPaymentSourceAcc.Focus();
                    return(false);
                }
                else
                {
                    cboPaymentSourceAcc.SelectedValue = dtkouza.Rows[0]["KouzaCD"].ToString();
                }
                if (string.IsNullOrWhiteSpace(txtBillSettleDate.Text))
                {
                    sibl.ShowMessage("E102");
                    txtBillSettleDate.Focus();
                    return(false);
                }
            }

            return(true);
        }
        protected override void PrintSec()
        {
            // レコード定義を行う
            // DataTable table = new DataTable();
            ukkthbl = new UrikakekinTairyuuHyou_BL();
            string    header = string.Empty;
            DataTable dtPrint;

            if (PrintMode != EPrintMode.DIRECT)
            {
                return;
            }
            if (ErrorCheck())
            {
                msce = new M_StoreClose_Entity();
                msce = GetStoreClose_Data();

                DateTime now      = Convert.ToDateTime(txtDate.Text.ToString() + "/01 00:00:00");
                string[] strmonth = new string[12];
                for (int i = 11; i >= 0; i--)
                {
                    strmonth[i] = now.AddMonths(-i).ToString().Substring(0, 7);
                }


                dtPrint = ukkthbl.Select_DataToExport(msce);
                //header = "棚入れリスト";

                try
                {
                    if (dtPrint == null || dtPrint.Rows.Count <= 0)
                    {
                        bbl.ShowMessage("E128");
                        txtDate.Focus();
                    }
                    else
                    {
                        string customerCD = string.Empty;
                        for (int i = 0; i < dtPrint.Rows.Count; i++)
                        {
                            if (customerCD != dtPrint.Rows[i]["CustomerCD"].ToString())
                            {
                                customerCD = dtPrint.Rows[i]["CustomerCD"].ToString();
                            }

                            DataTable dtResult = dtPrint.Select("SaleA='売上' and CustomerCD='" + customerCD + "'").CopyToDataTable();
                            if (dtResult.Rows.Count == 1)
                            {
                                dtPrint.Rows[i]["Result"] = dtResult.Rows[0]["Result"].ToString();
                            }
                        }

                        //xsdファイルを保存します。

                        //①保存した.xsdはプロジェクトに追加しておきます。
                        DialogResult ret;
                        UrikakekinTairyuuHyou_Report Report = new UrikakekinTairyuuHyou_Report();

                        switch (PrintMode)
                        {
                        case EPrintMode.DIRECT:

                            ret = bbl.ShowMessage("Q202");
                            if (ret == DialogResult.No)
                            {
                                return;
                            }
                            //}

                            // 印字データをセット



                            Report.SetDataSource(dtPrint);
                            Report.Refresh();
                            Report.SetParameterValue("txtStore", cboStore.SelectedValue.ToString() + "  " + cboStore.Text);
                            Report.SetParameterValue("txtMonth11", strmonth[11].ToString());
                            Report.SetParameterValue("txtMonth10", strmonth[10].ToString());
                            Report.SetParameterValue("txtMonth9", strmonth[9].ToString());
                            Report.SetParameterValue("txtMonth8", strmonth[8].ToString());
                            Report.SetParameterValue("txtMonth7", strmonth[7].ToString());
                            Report.SetParameterValue("txtMonth6", strmonth[6].ToString());
                            Report.SetParameterValue("txtMonth5", strmonth[5].ToString());
                            Report.SetParameterValue("txtMonth4", strmonth[4].ToString());
                            Report.SetParameterValue("txtMonth3", strmonth[3].ToString());
                            Report.SetParameterValue("txtMonth2", strmonth[2].ToString());
                            Report.SetParameterValue("txtMonth1", strmonth[1].ToString());
                            Report.SetParameterValue("txtMonth0", strmonth[0].ToString());

                            if (ret == DialogResult.Yes)
                            {
                                var previewForm = new Viewer();
                                previewForm.CrystalReportViewer1.ShowPrintButton = true;
                                previewForm.CrystalReportViewer1.ReportSource    = Report;
                                previewForm.ShowDialog();
                            }
                            else         /// //Still Not Working because of Applymargin and Printer not Setting up  (PTK Will Solve)
                            {
                                //int marginLeft = 360;
                                CrystalDecisions.Shared.PageMargins margin = Report.PrintOptions.PageMargins;
                                margin.leftMargin   = DefaultMargin.Left;     // mmの指定をtwip単位に変換する
                                margin.topMargin    = DefaultMargin.Top;
                                margin.bottomMargin = DefaultMargin.Bottom;   //mmToTwip(marginLeft);
                                margin.rightMargin  = DefaultMargin.Right;
                                Report.PrintOptions.ApplyPageMargins(margin); /// Error Now
                                // プリンタに印刷
                                System.Drawing.Printing.PageSettings ps;
                                try
                                {
                                    System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();

                                    CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();

                                    System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();

                                    Report.PrintOptions.PrinterName = "\\\\dataserver\\Canon LBP2900";
                                    System.Drawing.Printing.PageSettings pSettings = new System.Drawing.Printing.PageSettings(printerSettings);

                                    Report.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;

                                    Report.PrintOptions.PrinterDuplex = PrinterDuplex.Simplex;

                                    Report.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
                                }
                                catch (Exception ex)
                                {
                                }
                            }
                            break;

                        case EPrintMode.PDF:
                            if (bbl.ShowMessage("Q204") != DialogResult.Yes)
                            {
                                return;
                            }
                            string filePath = "";
                            if (!ShowSaveFileDialog(InProgramNM, out filePath))
                            {
                                return;
                            }

                            // 印字データをセット
                            Report.SetDataSource(dtPrint);
                            Report.Refresh();
                            Report.SetParameterValue("txtSouko", cboStore.SelectedValue.ToString() + "  " + cboStore.Text);
                            Report.SetParameterValue("txtHeader", header);

                            bool result = OutputPDF(filePath, Report);

                            //PDF出力が完了しました。
                            bbl.ShowMessage("I202");

                            break;
                        }
                        //InsertLog(Get_L_Log_Entity(dtPrint));
                    }
                }
                finally
                {
                }
            }
        }
        public void ExcelExport()
        {
            if (ErrorCheck())
            {
                if (CheckBeforeExport())
                {
                    if (bbl.ShowMessage("Q205") == DialogResult.Yes)
                    {
                        msce = new M_StoreClose_Entity();
                        msce = GetStoreClose_Data();

                        DateTime now      = Convert.ToDateTime(txtDate.Text.ToString() + "/01 00:00:00");
                        string[] strmonth = new string[12];
                        for (int i = 11; i >= 0; i--)
                        {
                            strmonth[i] = now.AddMonths(-i).ToString().Substring(0, 7).ToString();
                        }

                        DataTable dt = ukkthbl.Select_DataToExport(msce);
                        //DataRow dr = dt.NewRow();
                        //dr["CustomerCD"] = "";
                        //dr["CustomerName"] = "";
                        //dr["SaleA"] = "";
                        //dr["11"] = Convert.ToString(strmonth[11]);
                        //dr["10"] = strmonth[10].ToString();
                        //dr["9"] = strmonth[9].ToString();
                        //dr["8"] = strmonth[8].ToString();
                        //dr["7"] = strmonth[7].ToString();
                        //dr["6"] = strmonth[6].ToString();
                        //dr["5"] = strmonth[5].ToString();
                        //dr["4"] = strmonth[4].ToString();
                        //dr["3"] = strmonth[3].ToString();
                        //dr["2"] = strmonth[2].ToString();
                        //dr["1"] = strmonth[1].ToString();
                        //dr["0"] = strmonth[0].ToString();
                        //dt.Rows.Add(dr);

                        if (dt.Rows.Count > 0)
                        {
                            string customerCD = string.Empty;
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                if (customerCD != dt.Rows[i]["CustomerCD"].ToString())
                                {
                                    customerCD = dt.Rows[i]["CustomerCD"].ToString();
                                }

                                DataTable dtResult = dt.Select("SaleA='売上' and CustomerCD='" + customerCD + "'").CopyToDataTable();
                                if (dtResult.Rows.Count == 1)
                                {
                                    dt.Rows[i]["Result"] = dtResult.Rows[0]["Result"].ToString();
                                }
                            }
                            //dt.Columns["CustomerCD"].ColumnName =" ";
                            //dt.Columns["CustomerName"].ColumnName = " ";
                            //dt.Columns["SaleA"].ColumnName = " ";
                            dt.Columns["11"].ColumnName = strmonth[11].ToString();
                            dt.Columns["10"].ColumnName = strmonth[10].ToString();
                            dt.Columns["9"].ColumnName  = strmonth[9].ToString();
                            dt.Columns["8"].ColumnName  = strmonth[8].ToString();
                            dt.Columns["7"].ColumnName  = strmonth[7].ToString();
                            dt.Columns["6"].ColumnName  = strmonth[6].ToString();
                            dt.Columns["5"].ColumnName  = strmonth[5].ToString();
                            dt.Columns["4"].ColumnName  = strmonth[4].ToString();
                            dt.Columns["3"].ColumnName  = strmonth[3].ToString();
                            dt.Columns["2"].ColumnName  = strmonth[2].ToString();
                            dt.Columns["1"].ColumnName  = strmonth[1].ToString();
                            dt.Columns["0"].ColumnName  = strmonth[0].ToString();

                            DataTable dtExport   = dt;
                            string    folderPath = "C:\\SMS\\";
                            if (!Directory.Exists(folderPath))
                            {
                                Directory.CreateDirectory(folderPath);
                            }
                            SaveFileDialog savedialog = new SaveFileDialog();
                            savedialog.Filter           = "Excel Files|*.xlsx;";
                            savedialog.Title            = "Save";
                            savedialog.FileName         = "売掛滞留一覧表印刷";
                            savedialog.InitialDirectory = folderPath;

                            savedialog.RestoreDirectory = true;
                            if (savedialog.ShowDialog() == DialogResult.OK)
                            {
                                #region Test
                                //Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application();
                                //excel.Application.Workbooks.Add(Type.Missing);
                                //excel.Columns.AutoFit();
                                //for(int i=3; i< dtExport.Columns.Count+1; i++)
                                //{
                                //    Microsoft.Office.Interop.Excel.Range xlRange = (Microsoft.Office.Interop.Excel.Range)excel.Cells[3, i];
                                //    //xlRange.Font.Bold = -1;
                                //    xlRange.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                                //    xlRange.Borders.Weight = 1d;
                                //    xlRange.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                                //    excel.Cells[3, i] = dtExport.Columns[i - 1].ColumnName;
                                //}

                                ///*For storing Each row and column value to excel sheet*/
                                //for (int i = 1; i < dtExport.Rows.Count; i++)
                                //{
                                //    for (int j = 0; j < dtExport.Columns.Count; j++)
                                //    {
                                //        if (dtExport.Rows[i][j] != null)
                                //        {
                                //            Microsoft.Office.Interop.Excel.Range xlRange = (Microsoft.Office.Interop.Excel.Range)excel.Cells[i + 2, j + 1];
                                //            xlRange.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
                                //            xlRange.Borders.Weight = 1d;
                                //            excel.Cells[i + 2, j + 1] = "'"+dtExport.Rows[i][j].ToString();
                                //        }
                                //    }
                                //}
                                //excel.Columns.AutoFit(); // Auto fix the columns size
                                //System.Windows.Forms.Application.DoEvents();
                                //string name = "売掛滞留一覧表印刷";
                                //if (Directory.Exists("C:\\CTR_Data\\")) // Folder dic
                                //{
                                //    excel.ActiveWorkbook.SaveCopyAs("C:\\CTR_Data\\" +name + ".xlsx");
                                //}
                                //else
                                //{
                                //    Directory.CreateDirectory("C:\\CTR_Data\\");
                                //    excel.ActiveWorkbook.SaveCopyAs("C:\\CTR_Data\\" + name + ".xlsx");
                                //}
                                //excel.ActiveWorkbook.Saved = true;
                                //System.Windows.Forms.Application.DoEvents();
                                #endregion

                                if (Path.GetExtension(savedialog.FileName).Contains(".xlsx"))
                                {
                                    Microsoft.Office.Interop.Excel._Application excel     = new Microsoft.Office.Interop.Excel.Application();
                                    Microsoft.Office.Interop.Excel._Workbook    workbook  = excel.Workbooks.Add(Type.Missing);
                                    Microsoft.Office.Interop.Excel._Worksheet   worksheet = null;

                                    worksheet      = workbook.ActiveSheet;
                                    worksheet.Name = "worksheet";
                                    using (XLWorkbook wb = new XLWorkbook())
                                    {
                                        wb.Worksheets.Add(dtExport, "worksheet");
                                        wb.Worksheet("worksheet").Row(1).InsertRowsAbove(1);
                                        wb.Worksheet("worksheet").Row(1).InsertRowsAbove(1);
                                        wb.Worksheet("worksheet").Row(1).InsertRowsAbove(1);
                                        wb.Worksheet("worksheet").Cell(1, 1).Value = "年月:";
                                        wb.Worksheet("worksheet").Cell(2, 1).Value = "店舗:";
                                        wb.Worksheet("worksheet").Cell(1, 2).Value = "'" + strmonth[11].ToString();
                                        wb.Worksheet("worksheet").Cell(1, 3).Value = "~";
                                        wb.Worksheet("worksheet").Cell(1, 4).Value = "'" + strmonth[0].ToString();
                                        wb.Worksheet("worksheet").Cell(2, 2).Value = "'" + cboStore.SelectedValue.ToString();
                                        wb.Worksheet("worksheet").Cell(2, 3).Value = cboStore.Text.ToString();

                                        wb.Worksheet("worksheet").Cell(4, 1).Value  = " ";
                                        wb.Worksheet("worksheet").Cell(4, 2).Value  = " ";
                                        wb.Worksheet("worksheet").Cell(4, 3).Value  = " ";
                                        wb.Worksheet("worksheet").Cell(4, 16).Value = "売掛月数";

                                        //wb.Worksheet("worksheet").Cell(3, 4).Value = "'" + strmonth[11].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 5).Value = "'" + strmonth[10].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 6).Value = "'" + strmonth[9].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 7).Value = "'" + strmonth[8].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 8).Value = "'" + strmonth[7].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 9).Value = "'" + strmonth[6].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 10).Value = "'" + strmonth[5].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 11).Value = "'" + strmonth[4].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 12).Value = "'" + strmonth[3].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 13).Value = "'" + strmonth[2].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 14).Value = "'" + strmonth[1].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 15).Value = "'" + strmonth[0].ToString();
                                        //wb.Worksheet("worksheet").Cell(3, 16).Value = "売掛月数";


                                        //wb.Worksheet("worksheet").SetShowRowColHeaders(true);
                                        wb.Worksheet("worksheet").Tables.FirstOrDefault().ShowAutoFilter = false;
                                        //wb.Worksheet("worksheet").Tables.FirstOrDefault().ShowHeaderRow = false;
                                        //wb.Worksheet("worksheet").Rows("4").Delete();
                                        wb.SaveAs(savedialog.FileName);
                                        bbl.ShowMessage("I203", string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                                    }
                                    Process.Start(Path.GetDirectoryName(savedialog.FileName));
                                }
                                // Process.Start(Path.GetDirectoryName(savedialog.FileName));
                            }
                        }
                        else
                        {
                            bbl.ShowMessage("E128");
                            txtDate.Focus();
                        }
                    }
                }
            }
        }
        private void SubBtnClick(int index)
        {
            int[]  valC          = { 0, 0, 0, 0, 0 };
            string OperateModeNm = "";
            bool   ret           = false;

            switch (index)
            {
            case (int)EIndex.Uriage:
            case (int)EIndex.Shiire:
            case (int)EIndex.Nyukin:
            case (int)EIndex.Shiharai:
            case (int)EIndex.Zaiko:
                if (detailButtons[index].Text.Equals("仮締する"))
                {
                    //①画面を変更⇒
                    detailLabels[index].Text      = "仮締中(入力不可)";
                    detailLabels[index].BackColor = Color.FromArgb(255, 255, 0);
                    detailButtons[index].Enabled  = true;
                    detailButtons[index].Text     = "仮締キャンセルする";
                    valC[index]   = 1;
                    OperateModeNm = "仮締 月次仮締・";
                }
                else
                {
                    //①画面を変更⇒
                    detailLabels[index].Text      = "入力可";
                    detailLabels[index].BackColor = Color.FromArgb(255, 192, 0);
                    detailButtons[index].Enabled  = true;
                    detailButtons[index].Text     = "仮締する";
                    valC[index]   = 0;
                    OperateModeNm = "キャンセル 月次仮締・";
                }

                switch (index)
                {
                case (int)EIndex.Uriage:
                    OperateModeNm += "売上";
                    break;

                case (int)EIndex.Shiire:
                    OperateModeNm += "仕入";
                    break;

                case (int)EIndex.Nyukin:
                    OperateModeNm += "入金";
                    break;

                case (int)EIndex.Shiharai:
                    OperateModeNm += "支払";
                    break;

                case (int)EIndex.Zaiko:
                    OperateModeNm += "在庫";
                    break;
                }
                break;

            case (int)EIndex.Saiken:
            case (int)EIndex.Saimu:
            case (int)EIndex.ZaikoShukei:

                OperateModeNm = "集計 月次集計・";
                switch (index)
                {
                case (int)EIndex.Saiken:
                    OperateModeNm += "債権";
                    //②計算処理を実行
                    //GetsujiSaikenKeisanSyori.exe を起動する
                    ret = ExecSaikenSaimu(GetsujiSaikenKeisanSyori);
                    break;

                case (int)EIndex.Saimu:
                    OperateModeNm += "債務";
                    //②計算処理を実行
                    //GetsujiSaimuKeisanSyori.exe を起動する
                    ret = ExecSaikenSaimu(GetsujiSaimuKeisanSyori);
                    break;

                case (int)EIndex.ZaikoShukei:
                    OperateModeNm += "在庫";
                    //②計算処理を実行
                    //GetsujiZaikoKeisanSyori.exe を起動する
                    ret = ExecSaikenSaimu(GetsujiZaikoKeisanSyori);
                    if (!ret)
                    {
                        return;
                    }
                    //GetsujiShiireKeisanSyori.exe   を起動する
                    ret = ExecSaikenSaimu(GetsujiShiireKeisanSyori);
                    break;
                }
                if (!ret)
                {
                    return;
                }

                //①画面を変更⇒
                detailLabels[index].Text      = "計算中";
                detailLabels[index].BackColor = Color.White;
                detailButtons[index].Enabled  = false;
                detailButtons[index].Text     = "計算する";
                break;

            case (int)EIndex.All:
                SubBtnClick((int)EIndex.Saiken);
                SubBtnClick((int)EIndex.Saimu);
                SubBtnClick((int)EIndex.ZaikoShukei);

                break;
            }
            //②Table更新
            //OperateModeNm:仮締 or キャンセル or 集計 or 確定 or 解除
            //月次仮締・売上,月次仮締・入金,月次仮締・仕入,月次仮締・支払,月次仮締・在庫,月次集計・債権,月次処理・債務,月次処理・在庫,月次確定
            M_StoreClose_Entity me = new M_StoreClose_Entity
            {
                StoreCD        = CboStoreCD.SelectedValue == null ? "" : CboStoreCD.SelectedValue.ToString(),
                FiscalYYYYMM   = lblChangeDate.Text.Replace("/", ""),
                ClosePosition1 = valC[0].ToString(),    //売上
                ClosePosition2 = valC[2].ToString(),    //仕入
                ClosePosition3 = valC[1].ToString(),    //入金
                ClosePosition4 = valC[3].ToString(),    //支払
                ClosePosition5 = valC[4].ToString(),    //在庫
                Mode           = Mode,
                Kbn            = index + 1,
                Operator       = InOperatorCD,
                PC             = InPcID,
                OperateModeNm  = OperateModeNm
            };

            ret = gsbl.M_StoreClose_Update(me);
        }
        private bool ErrorCheck(int kbn = 0)
        {
            if (kbn == 1)
            {
                //JANCD
                if (!RequireCheck(new Control[] { txtJanCD }))
                {
                    return(false);
                }

                if (!CheckWidth(1))
                {
                    return(false);
                }

                if (!CheckWidth(2))
                {
                    return(false);
                }

                //【Data Area Detail】に存在するJANCDで無い場合、Error
                DataRow[] rows = dtJuchu.Select("JANCD = '" + txtJanCD.Text + "'");
                if (rows.Length == 0)
                {
                    bbl.ShowMessage("E148");
                    txtJanCD.Focus();
                    return(false);
                }
                else if (rows.Length > 1)
                {
                    //【Data Area Detail】に複数存在するJANCDの場合
                    //「該当する行が複数存在します。右の一覧から選択してください」
                    bbl.ShowMessage("E149");
                    txtJanCD.Focus();
                    return(false);
                }
                else
                {
                    //【Data Area Detail】に1つだけ存在するJANCDの場合
                    //画面転送表01に従って、画面情報を表示
                    //rows[0]よりDataTableのRowIndexを求める
                    int rowindex = dtJuchu.Rows.IndexOf(rows[0]);
                    txtJanCD.Tag = rowindex;

                    SetDataFromDataTable(rowindex + 1);
                }
            }
            if (kbn == 2)
            {
                //出荷数
                //入力無くても良い(It is not necessary to input)
                //入力無い場合、0とする(When there is no input, it is set to 0)
                txtShippingSu.Text = bbl.Z_SetStr(txtShippingSu.Text);

                //入力された場合
                //出荷数>	Form.出荷可能数の場合、Error E150
                if (bbl.Z_Set(txtShippingSu.Text) > bbl.Z_Set(lblSyukkaKanouSu.Text))
                {
                    bbl.ShowMessage("E150");
                    txtShippingSu.Focus();
                    return(false);
                }

                //お買上額等の計算を行う
                //お買上額←form.単価×	出荷数
                lblJuchuuSuu.Text = "\\" + bbl.Z_SetStr(bbl.Z_Set(lblJuchuuUnitPrice.Text.Replace("\\", "")) * bbl.Z_Set(txtShippingSu.Text));

                //うち税額 Function_消費税計算.out金額1
                int    taxRateFLG = Convert.ToInt16(dtJuchu.Rows[(int)txtJanCD.Tag]["TaxRateFLG"]);
                string ymd        = dtJuchu.Rows[(int)txtJanCD.Tag]["JuchuuDate"].ToString();

                decimal zeinukiKin = bbl.GetZeinukiKingaku(bbl.Z_Set(lblJuchuuSuu.Text.Replace("\\", "")), taxRateFLG, ymd);
                lblSalesTax.Text = "\\" + bbl.Z_SetStr(bbl.Z_Set(lblJuchuuSuu.Text.Replace("\\", "")) - zeinukiKin);
            }
            if (kbn == 0 || kbn == 3)
            {
                //お買上日
                //必須入力(Entry required)、入力なければエラー(If there is no input, an error)E102
                if (string.IsNullOrWhiteSpace(txtSalesDate.Text))
                {
                    //E102
                    bbl.ShowMessage("E102");
                    txtSalesDate.Focus();
                    return(false);
                }

                txtSalesDate.Text = bbl.FormatDate(txtSalesDate.Text);

                //日付として正しいこと(Be on the correct date)E103
                if (!bbl.CheckDate(txtSalesDate.Text))
                {
                    //E103
                    bbl.ShowMessage("E103");
                    txtSalesDate.Focus();
                    return(false);
                }

                //店舗の締日チェック
                //店舗締マスターで判断
                M_StoreClose_Entity mse = new M_StoreClose_Entity();
                mse.StoreCD      = mStoreCD;
                mse.FiscalYYYYMM = txtSalesDate.Text.Replace("/", "").Substring(0, 6);
                bool ret = tprg_Shukka_Bl.CheckStoreClose(mse, true, false, false, false, true);
                if (!ret)
                {
                    txtSalesDate.Focus();
                    return(false);
                }

                //お買上日から入金予定日を自動計算し表示する(お買上日が変更されたた再計算)
                if (txtSalesDate.Text != mSaleDate)
                {
                    Fnc_PlanDate_Entity fpe = new Fnc_PlanDate_Entity();
                    fpe.KaisyuShiharaiKbn = "0";    // "1";
                    fpe.CustomerCD        = lblCustomerNo.Text;
                    fpe.ChangeDate        = txtSalesDate.Text;
                    fpe.TyohaKbn          = "0";

                    txtFirstCollectPlanDate.Text = bbl.Fnc_PlanDate(fpe);

                    mSaleDate = txtSalesDate.Text;
                }
            }
            if (kbn == 0 || kbn == 4)
            {
                //入金予定日
                //必須入力(Entry required)、入力なければエラー(If there is no input, an error)E102
                if (string.IsNullOrWhiteSpace(txtFirstCollectPlanDate.Text))
                {
                    //E102
                    bbl.ShowMessage("E102");
                    txtFirstCollectPlanDate.Focus();
                    return(false);
                }

                txtFirstCollectPlanDate.Text = bbl.FormatDate(txtFirstCollectPlanDate.Text);
            }

            return(true);
        }