Ejemplo n.º 1
0
        private bool OfPostGbj(vw_glab321 pModel, Result pResult)
        {
            DataTable           dtGbjSum = null;
            string              selectSql = "";
            List <SqlParameter> sqlParmList = null;
            int       nextYear = 0, chkCnts = 0;
            GlaBLL    boGbh = null;
            DataTable dtGbjNext = null;

            try
            {
                nextYear = (new DateTime(Convert.ToInt16(pModel.gfa08), 1, 1)).AddYears(1).Year;
                //過帳會科部門各期餘額檔 下期期初資料
                selectSql   = @"SELECT 
                                gbj01,gbj02,
                                SUM(gbj05) AS gbj05,
                                SUM(gbj06) AS gbj06
                              FROM gbj_tb
                              WHERE gbj03=@gbj03
                                AND gbj04<>4
                              GROUP BY gbj01,gbj02
                            ";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbj03", pModel.gfa08));
                dtGbjSum = OfGetDataTable(selectSql, sqlParmList.ToArray());
                if (dtGbjSum == null || dtGbjSum.Rows.Count == 0)
                {
                    pResult.Message = "取得部門各期餘額加總失敗!";
                    return(false);
                }

                boGbh      = new GlaBLL(OfGetConntion());
                boGbh.TRAN = this.TRAN;
                boGbh.OfCreateDao("gbj_tb", "*", "");
                selectSql = @"SELECT * FROM gbj_tb 
                              WHERE gbj01=@gbj01 AND gbj02=@gbj02 AND gbj03=@gbj03 AND gbj04=@gbj04";
                foreach (DataRow drGbjSum in dtGbjSum.Rows)
                {
                    var gbjSumModel = drGbjSum.ToItem <gbj_tb>(true);
                    sqlParmList = new List <SqlParameter>();
                    sqlParmList.Add(new SqlParameter("@gbj01", gbjSumModel.gbj01));
                    sqlParmList.Add(new SqlParameter("@gbj02", gbjSumModel.gbj02));
                    sqlParmList.Add(new SqlParameter("@gbj03", nextYear));
                    sqlParmList.Add(new SqlParameter("@gbj04", 0));
                    dtGbjNext = boGbh.OfGetDataTable(selectSql, sqlParmList.ToArray());
                    if (dtGbjNext.Rows.Count == 0)
                    {
                        var drGbhNext = dtGbjNext.NewRow();
                        drGbhNext["gbj01"]   = gbjSumModel.gbj01;
                        drGbhNext["gbj02"]   = gbjSumModel.gbj02;
                        drGbhNext["gbj03"]   = nextYear;
                        drGbhNext["gbj04"]   = 0;
                        drGbhNext["gbj05"]   = gbjSumModel.gbj05;
                        drGbhNext["gbj06"]   = gbjSumModel.gbj06;
                        drGbhNext["gbj07"]   = 0;
                        drGbhNext["gbj08"]   = 0;
                        drGbhNext["gbjcomp"] = _loginInfo.CompNo;
                        dtGbjNext.Rows.Add(drGbhNext);
                    }
                    else
                    {
                        var drGbhNext = dtGbjNext.Rows[0];
                        drGbhNext["gbj05"] = gbjSumModel.gbj05;
                        drGbhNext["gbj06"] = gbjSumModel.gbj06;
                        drGbhNext["gbj07"] = 0;
                        drGbhNext["gbj08"] = 0;
                    }
                    chkCnts = boGbh.OfUpdate(dtGbjNext);
                    if (chkCnts != 1)
                    {
                        pResult.Message = "更新年結相關資料(部門餘額)失敗!";
                        return(false);
                    }
                }
                pResult.Success = true;
                return(true);
            }
            catch (Exception ex)
            {
                pResult.Message   = "更新年結相關資料(部門餘額)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 2
0
        private bool OfPostGbiRecursive(string pGba07, gfa_tb pGfaModel, gfb_tb pGfbModel,
                                        decimal pDAmt, decimal pCAmt, decimal pDRec, decimal pCRec, Result pResult)
        {
            string selectSql = "";
            List <SqlParameter> sqlParmList = null;
            GlaBLL    boGbi = null;
            DataTable dtGbi = null;
            DataRow   drGbi = null;

            try
            {
                boGbi      = new GlaBLL(OfGetConntion());
                boGbi.TRAN = this.TRAN;
                boGbi.OfCreateDao("gbi_tb", "*", "");
                selectSql   = @"SELECT * FROM gbi_tb 
                              WHERE gbi01=@gbi01 AND gbi02=@gbi02 ";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbi01", pGba07));
                sqlParmList.Add(new SqlParameter("@gbi02", pGfaModel.gfa02));
                dtGbi = boGbi.OfGetDataTable(selectSql, sqlParmList.ToArray());

                if (dtGbi.Rows.Count == 0)
                {
                    drGbi            = dtGbi.NewRow();
                    drGbi["gbi01"]   = pGba07;
                    drGbi["gbi02"]   = pGfaModel.gfa02;
                    drGbi["gbi03"]   = pDAmt;
                    drGbi["gbi04"]   = pCAmt;
                    drGbi["gbi05"]   = pDRec;
                    drGbi["gbi06"]   = pCRec;
                    drGbi["gbicomp"] = _loginInfo.CompNo;
                    dtGbi.Rows.Add(drGbi);
                }
                else
                {
                    drGbi = dtGbi.Rows[0];

                    drGbi["gbi03"] = Convert.ToDecimal(drGbi["gbi03"]) + pDAmt;
                    drGbi["gbi04"] = Convert.ToDecimal(drGbi["gbi04"]) + pCAmt;
                    drGbi["gbi05"] = Convert.ToDecimal(drGbi["gbi05"]) + pDRec;
                    drGbi["gbi06"] = Convert.ToDecimal(drGbi["gbi06"]) + pCRec;
                }
                if (boGbi.OfUpdate(dtGbi) != 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科每日餘額檔(gbi_tb)失敗!";
                    return(false);
                }

                var gbaParentsModel = OfGetGbaModel(pGba07);
                if (gbaParentsModel.gba07.ToLower() != "root")
                {
                    if (OfPostGbiRecursive(gbaParentsModel.gba07, pGfaModel, pGfbModel,
                                           pDAmt, pCAmt, pDRec, pCRec, pResult) == false)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                pResult.Message   = "更新會科每日餘額檔(gbi_tb)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 3
0
        private bool OfPostGbjRecursive(string pGbj01Parents, gfa_tb pGfaModel, gfb_tb pGfbModel,
                                        decimal pDAmt, decimal pCAmt, decimal pDRec, decimal pCRec, Result pResult)
        {
            string selectSql = "";
            List <SqlParameter> sqlParmList = null;
            GlaBLL    boGbj = null;
            DataTable dtGbj = null;
            DataRow   drGbj = null;

            try
            {
                boGbj      = new GlaBLL(OfGetConntion());
                boGbj.TRAN = this.TRAN;
                boGbj.OfCreateDao("gbj_tb", "*", "");
                selectSql   = @"SELECT * FROM gbj_tb 
                              WHERE gbj01=@gbj01 AND gbj02=@gbj02 
                              AND gbj03=@gbj03 AND gbj04=@gbj04
                            ";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbj01", pGfbModel.gfb03));
                sqlParmList.Add(new SqlParameter("@gbj02", pGbj01Parents));
                sqlParmList.Add(new SqlParameter("@gbj03", pGfaModel.gfa08));
                sqlParmList.Add(new SqlParameter("@gbj04", pGfaModel.gfa09));
                dtGbj = boGbj.OfGetDataTable(selectSql, sqlParmList.ToArray());

                if (dtGbj.Rows.Count == 0)
                {
                    drGbj            = dtGbj.NewRow();
                    drGbj["gbj01"]   = pGfbModel.gfb03;
                    drGbj["gbj02"]   = pGbj01Parents;
                    drGbj["gbj03"]   = pGfaModel.gfa08;
                    drGbj["gbj04"]   = pGfaModel.gfa09;
                    drGbj["gbj05"]   = pDAmt;
                    drGbj["gbj06"]   = pCAmt;
                    drGbj["gbj07"]   = pDRec;
                    drGbj["gbj08"]   = pCRec;
                    drGbj["gbjcomp"] = _loginInfo.CompNo;
                    dtGbj.Rows.Add(drGbj);
                }
                else
                {
                    drGbj = dtGbj.Rows[0];

                    drGbj["gbj05"] = Convert.ToDecimal(drGbj["gbj05"]) + pDAmt;
                    drGbj["gbj06"] = Convert.ToDecimal(drGbj["gbj06"]) + pCAmt;
                    drGbj["gbj07"] = Convert.ToDecimal(drGbj["gbj07"]) + pDRec;
                    drGbj["gbj08"] = Convert.ToDecimal(drGbj["gbj08"]) + pCRec;
                }
                if (boGbj.OfUpdate(dtGbj) != 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新部門餘額檔,上層部門(gbj_tb)失敗!";
                    return(false);
                }

                selectSql   = "SELECT * FROM gbd_tb WHERE gbd02=@gbd02";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbd02", pGbj01Parents));
                var dtGbd = OfGetDataTable(selectSql, sqlParmList.ToArray());
                if (dtGbd == null || dtGbd.Rows.Count == 0)
                {
                    return(true);
                }

                if (dtGbd.Rows.Count > 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新部門餘額檔,有多個上層部門異常!";
                    return(false);
                }

                var gbdModel = dtGbd.Rows[0].ToItem <gbd_tb>();
                if (OfPostGbjRecursive(gbdModel.gbd01, pGfaModel, pGfbModel,
                                       pDAmt, pCAmt, pDRec, pCRec, pResult) == false)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                pResult.Message   = "更新部門餘額檔,上層部門(gbj_tb)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 4
0
        private bool OfPostGbi(gfa_tb pGfaModel, gfb_tb pGfbModel, gba_tb pGbaModel, Result pResult)
        {
            string selectSql = "", updateSql = "", insertSql = "";
            List <SqlParameter> sqlParmList = null;
            decimal             dAmt = 0, cAmt = 0, dRec = 0, cRec = 0;
            GlaBLL    boGbi = null;
            DataTable dtGbi = null;
            DataRow   drGbi = null;

            try
            {
                boGbi      = new GlaBLL(OfGetConntion());
                boGbi.TRAN = this.TRAN;
                boGbi.OfCreateDao("gbi_tb", "*", "");
                selectSql   = @"SELECT * FROM gbi_tb 
                              WHERE gbi01=@gbi01 AND gbi02=@gbi02";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbi01", pGfbModel.gfb03));
                sqlParmList.Add(new SqlParameter("@gbi02", pGfaModel.gfa02));
                dtGbi = boGbi.OfGetDataTable(selectSql, sqlParmList.ToArray());

                if (pGfbModel.gfb06 == "1")
                {
                    dAmt = pGfbModel.gfb07;
                    dRec = 1;
                }
                else
                {
                    cAmt = pGfbModel.gfb07;
                    cRec = 1;
                }

                if (dtGbi.Rows.Count == 0)
                {
                    drGbi            = dtGbi.NewRow();
                    drGbi["gbi01"]   = pGfbModel.gfb03;
                    drGbi["gbi02"]   = pGfaModel.gfa02;
                    drGbi["gbi03"]   = dAmt;
                    drGbi["gbi04"]   = cAmt;
                    drGbi["gbi05"]   = dRec;
                    drGbi["gbi06"]   = cRec;
                    drGbi["gbicomp"] = _loginInfo.CompNo;
                    dtGbi.Rows.Add(drGbi);
                }
                else
                {
                    drGbi          = dtGbi.Rows[0];
                    drGbi["gbi03"] = Convert.ToDecimal(drGbi["gbi03"]) + dAmt;
                    drGbi["gbi04"] = Convert.ToDecimal(drGbi["gbi04"]) + cAmt;
                    drGbi["gbi05"] = Convert.ToDecimal(drGbi["gbi05"]) + dRec;
                    drGbi["gbi06"] = Convert.ToDecimal(drGbi["gbi06"]) + cRec;
                }
                if (boGbi.OfUpdate(dtGbi) != 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科各期餘額檔(gbi_tb)失敗!";
                    return(false);
                }

                //明細科目,需遞迴處理統制科目
                if (pGbaModel.gba06 == "2")
                {
                    if (OfPostGbiRecursive(pGbaModel.gba07, pGfaModel, pGfbModel, dAmt, cAmt, dRec, cRec, pResult) == false)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                pResult.Message   = "更新會科每日餘額檔(gbi_tb)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 5
0
        private bool OfPostGbj(gfa_tb pGfaModel, gfb_tb pGfbModel, gba_tb pGbaModel, Result pResult)
        {
            string selectSql = "";
            List <SqlParameter> sqlParmList = null;
            decimal             dAmt = 0, cAmt = 0, dRec = 0, cRec = 0;
            GlaBLL    boGbj = null;
            DataTable dtGbj = null;
            DataRow   drGbj = null;

            try
            {
                if (pGbaModel.gba09 != "Y")
                {
                    return(true);
                }

                boGbj      = new GlaBLL(OfGetConntion());
                boGbj.TRAN = this.TRAN;
                boGbj.OfCreateDao("gbj_tb", "*", "");
                selectSql   = @"SELECT * FROM gbj_tb 
                              WHERE gbj01=@gbj01 AND gbj02=@gbj02 
                                    AND gbj03=@gbj03 AND gbj04=@gbj04";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbj01", pGfbModel.gfb03));
                sqlParmList.Add(new SqlParameter("@gbj02", pGfbModel.gfb05));
                sqlParmList.Add(new SqlParameter("@gbj03", pGfaModel.gfa08));
                sqlParmList.Add(new SqlParameter("@gbj04", pGfaModel.gfa09));
                dtGbj = boGbj.OfGetDataTable(selectSql, sqlParmList.ToArray());

                if (pGfbModel.gfb06 == "1")
                {
                    dAmt = pGfbModel.gfb07;
                    dRec = 1;
                }
                else
                {
                    cAmt = pGfbModel.gfb07;
                    cRec = 1;
                }

                if (dtGbj.Rows.Count == 0)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科每日餘額檔(gbj_tb)失敗!查無該部門餘額檔!";
                    return(false);
                }
                else
                {
                    drGbj          = dtGbj.Rows[0];
                    drGbj["gbj06"] = Convert.ToDecimal(drGbj["gbj06"]) - dAmt;
                    drGbj["gbj06"] = Convert.ToDecimal(drGbj["gbj06"]) - cAmt;
                    drGbj["gbj07"] = Convert.ToDecimal(drGbj["gbj07"]) - dRec;
                    drGbj["gbj08"] = Convert.ToDecimal(drGbj["gbj08"]) - cRec;
                }
                if (boGbj.OfUpdate(dtGbj) != 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新部門各期餘額檔(gbj_tb)失敗!";
                    return(false);
                }

                //需遞迴處理上層部門
                selectSql   = "SELECT * FROM gbd_tb WHERE gbd02=@gbd02";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbd02", pGfbModel.gfb05));
                var dtGbd = OfGetDataTable(selectSql, sqlParmList.ToArray());
                if (dtGbd == null || dtGbd.Rows.Count == 0)
                {
                    return(true);
                }

                if (dtGbd.Rows.Count > 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新部門餘額檔,有多個上層部門異常!";
                    return(false);
                }

                var gbdModel = dtGbd.Rows[0].ToItem <gbd_tb>();
                if (OfPostGbjRecursive(gbdModel.gbd01, pGfaModel, pGfbModel,
                                       dAmt, cAmt, dRec, cRec, pResult) == false)
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                pResult.Message   = "更新部門各期餘額檔(gbj_tb)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 6
0
        private bool OfPostGbhRecursive(string pGba07, gfa_tb pGfaModel, gfb_tb pGfbModel,
                                        decimal pDAmt, decimal pCAmt, decimal pDRec, decimal pCRec, Result pResult)
        {
            string selectSql = "";
            List <SqlParameter> sqlParmList = null;
            GlaBLL    boGbh = null;
            DataTable dtGbh = null;
            DataRow   drGbh = null;

            try
            {
                boGbh      = new GlaBLL(OfGetConntion());
                boGbh.TRAN = this.TRAN;
                boGbh.OfCreateDao("gbh_tb", "*", "");
                selectSql   = @"SELECT * FROM gbh_tb 
                              WHERE gbh01=@gbh01 AND gbh02=@gbh02 AND gbh03=@gbh03";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbh01", pGba07));
                sqlParmList.Add(new SqlParameter("@gbh02", pGfaModel.gfa08));
                sqlParmList.Add(new SqlParameter("@gbh03", pGfaModel.gfa09));
                dtGbh = boGbh.OfGetDataTable(selectSql, sqlParmList.ToArray());

                if (dtGbh.Rows.Count == 0)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科各期餘額檔(gbh_tb)失敗!查無該期會科餘額檔!";
                    return(false);
                }
                else
                {
                    drGbh          = dtGbh.Rows[0];
                    drGbh["gbh04"] = Convert.ToDecimal(drGbh["gbh04"]) - pDAmt;
                    drGbh["gbh05"] = Convert.ToDecimal(drGbh["gbh05"]) - pCAmt;
                    drGbh["gbh06"] = Convert.ToDecimal(drGbh["gbh06"]) - pDRec;
                    drGbh["gbh07"] = Convert.ToDecimal(drGbh["gbh07"]) - pCRec;
                }
                if (boGbh.OfUpdate(dtGbh) != 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科各期餘額檔統制科目(gbh_tb)失敗!";
                    return(false);
                }

                var gbaParentsModel = OfGetGbaModel(pGba07);
                if (gbaParentsModel.gba07.ToLower() != "root")
                {
                    if (OfPostGbhRecursive(gbaParentsModel.gba07, pGfaModel, pGfbModel,
                                           pDAmt, pCAmt, pDRec, pCRec, pResult) == false)
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                pResult.Message   = "更新會科各期餘額檔統制科目(gbh_tb)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 7
0
        private bool OfPostGbh(gfa_tb pGfaModel, gfb_tb pGfbModel, gba_tb pGbaModel, Result pResult)
        {
            string selectSql = "";
            List <SqlParameter> sqlParmList = null;
            decimal             dAmt = 0, cAmt = 0, dRec = 0, cRec = 0;
            GlaBLL    boGbh = null;
            DataTable dtGbh = null;
            DataRow   drGbh = null;

            try
            {
                boGbh      = new GlaBLL(OfGetConntion());
                boGbh.TRAN = this.TRAN;
                boGbh.OfCreateDao("gbh_tb", "*", "");
                selectSql   = @"SELECT * FROM gbh_tb 
                              WHERE gbh01=@gbh01 AND gbh02=@gbh02 AND gbh03=@gbh03";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gbh01", pGfbModel.gfb03));
                sqlParmList.Add(new SqlParameter("@gbh02", pGfaModel.gfa08));
                sqlParmList.Add(new SqlParameter("@gbh03", pGfaModel.gfa09));
                dtGbh = boGbh.OfGetDataTable(selectSql, sqlParmList.ToArray());

                if (pGfbModel.gfb06 == "1")
                {
                    dAmt = pGfbModel.gfb07;
                    dRec = 1;
                }
                else
                {
                    cAmt = pGfbModel.gfb07;
                    cRec = 1;
                }

                if (dtGbh.Rows.Count == 0)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科各期餘額檔(gbh_tb)失敗!查無該期會科餘額檔!";
                    return(false);
                }
                else
                {
                    drGbh          = dtGbh.Rows[0];
                    drGbh["gbh04"] = Convert.ToDecimal(drGbh["gbh04"]) - dAmt;
                    drGbh["gbh05"] = Convert.ToDecimal(drGbh["gbh05"]) - cAmt;
                    drGbh["gbh06"] = Convert.ToDecimal(drGbh["gbh06"]) - dRec;
                    drGbh["gbh07"] = Convert.ToDecimal(drGbh["gbh07"]) - cRec;
                }
                if (boGbh.OfUpdate(dtGbh) != 1)
                {
                    pResult.Key1    = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                    pResult.Message = "更新會科各期餘額檔(gbh_tb)失敗!";
                    return(false);
                }

                //明細科目,需遞迴處理統制科目
                if (pGbaModel.gba06 == "2")
                {
                    if (OfPostGbhRecursive(pGbaModel.gba07, pGfaModel, pGfbModel, dAmt, cAmt, dRec, cRec, pResult) == false)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = string.Concat(pGfbModel.gfb01, "/", pGfbModel.gfb02);
                pResult.Message   = "更新會科各期餘額檔(gbh_tb)失敗!";
                pResult.Exception = ex;
                return(false);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 產生分錄底稿 來源為收款沖帳單
        /// </summary>
        /// <param name="pCarb350Model"></param>
        /// <param name="pCfaModel"></param>
        /// <param name="pGeaModel"></param>
        /// <param name="pResult"></param>
        /// <returns></returns>
        private bool OfGenGfa(vw_carb350 pCarb350Model, cfa_tb pCfaModel, gea_tb pGeaModel, Result pResult)
        {
            string selectSql = "", updateSql = "";
            List <SqlParameter> sqlParmList = null;
            GlaBLL        boGla = null;
            BasBLL        boBas = null;
            DataTable     dtGfa = null, dtGfb = null;
            DataRow       drGfa = null, drGfb = null;
            string        gfa01 = "", gfa01New = "";
            DateTime?     gfa02;
            string        errMsg = "";
            int           year = 0, period = 0;
            List <geb_tb> gebList  = null;
            cac_tb        cacModel = null; //收款單別
            int           chkCnts  = 0;

            try
            {
                boGla      = new GlaBLL(OfGetConntion());
                boGla.TRAN = this.TRAN;
                boBas      = new BasBLL(OfGetConntion());
                boBas.TRAN = this.TRAN;

                boGla.OfCreateDao("gfa_tb", "*", "");
                selectSql = @"SELECT * FROM gfa_tb WHERE 1<>1";
                dtGfa     = boGla.OfGetDataTable(selectSql);
                drGfa     = dtGfa.NewRow();
                if (!GlobalFn.varIsNull(pCarb350Model.gfa01))
                {
                    gfa01 = pCarb350Model.gfa01;
                }
                else
                {
                    //以應收單別設定的來拋轉
                    cacModel = OfGetCacModel(pCfaModel.cfa01);
                    if (cacModel == null)
                    {
                        pResult.Key1    = pCfaModel.cfa01;
                        pResult.Message = "取得應收單別失敗!";
                        return(false);
                    }
                    if (GlobalFn.varIsNull(cacModel.cac10))
                    {
                        pResult.Key1    = pCfaModel.cfa01;
                        pResult.Message = "未設定應收拋轉總帳單別,請先至單別資料設定!";
                        return(false);
                    }
                    gfa01 = cacModel.cac10;
                }
                if (!GlobalFn.varIsNull(pCarb350Model.gfa02))
                {
                    gfa02 = pCarb350Model.gfa02;
                }
                else
                {
                    gfa02 = pGeaModel.gea05;
                }

                errMsg = "";
                if (boBas.OfGetAutoNo(gfa01, ModuleType.gla, (DateTime)gfa02, out gfa01New, out errMsg) == false)
                {
                    pResult.Key1    = pCfaModel.cfa01;
                    pResult.Message = errMsg;
                    return(false);
                }

                drGfa["gfa01"] = gfa01New;
                drGfa["gfa02"] = gfa02;
                drGfa["gfa03"] = pGeaModel.gea08;
                drGfa["gfa04"] = pGeaModel.gea09;
                drGfa["gfa05"] = "";              //備註
                drGfa["gfa06"] = pGeaModel.gea02; //來源碼-系統別
                drGfa["gfa07"] = pGeaModel.gea01; //來源單號

                if (boGla.OfGetGlaYearPeriod(Convert.ToDateTime(gfa02), out year, out period) == false)
                {
                    pResult.Message = "取得會計年度失敗!";
                    return(false);
                }
                drGfa["gfa08"]   = year;
                drGfa["gfa09"]   = period;
                drGfa["gfa10"]   = DBNull.Value;    //保留
                drGfa["gfa10"]   = DBNull.Value;    //保留
                drGfa["gfa11"]   = DBNull.Value;    //保留
                drGfa["gfa12"]   = DBNull.Value;    //保留
                drGfa["gfa13"]   = DBNull.Value;    //保留
                drGfa["gfa14"]   = DBNull.Value;    //保留
                drGfa["gfa15"]   = DBNull.Value;    //保留
                drGfa["gfa16"]   = DBNull.Value;    //保留
                drGfa["gfa17"]   = DBNull.Value;    //保留
                drGfa["gfa18"]   = DBNull.Value;    //保留
                drGfa["gfa19"]   = DBNull.Value;    //保留
                drGfa["gfa20"]   = DBNull.Value;    //保留
                drGfa["gfaprno"] = 0;
                drGfa["gfaconf"] = "N";
                drGfa["gfaconu"] = DBNull.Value;
                drGfa["gfapost"] = "N";
                drGfa["gfaposd"] = DBNull.Value;
                drGfa["gfaposu"] = DBNull.Value;
                drGfa["gfacomp"] = _loginInfo.CompNo;
                drGfa["gfacreu"] = _loginInfo.UserNo;
                drGfa["gfacreg"] = _loginInfo.DeptNo;
                drGfa["gfacred"] = OfGetNow();
                drGfa["gfamodu"] = DBNull.Value;
                drGfa["gfamodg"] = DBNull.Value;
                drGfa["gfamodd"] = DBNull.Value;
                drGfa["gfasecu"] = _loginInfo.UserNo;
                drGfa["gfasecg"] = _loginInfo.GroupNo;
                dtGfa.Rows.Add(drGfa);

                if (boGla.OfUpdate(dtGfa) == -1)
                {
                    pResult.Key1    = pGeaModel.gea01;
                    pResult.Message = "新增傳票單頭失敗!";
                    return(false);
                }

                gebList = boGla.OfGetGebList(pGeaModel.gea01, pGeaModel.gea02, pGeaModel.gea03, pGeaModel.gea04);
                if (gebList == null || gebList.Count == 0)
                {
                    pResult.Key1    = pGeaModel.gea01;
                    pResult.Message = "查無分錄底稿單身資料!";
                    return(false);
                }

                boGla.OfCreateDao("gfb_tb", "*", "");
                selectSql = @"SELECT * FROM gfb_tb WHERE 1<>1";
                dtGfb     = boGla.OfGetDataTable(selectSql);
                foreach (geb_tb gebModel in gebList.OrderBy(p => p.geb05))
                {
                    drGfb            = dtGfb.NewRow();
                    drGfb["gfb01"]   = gfa01New;        //傳票編號
                    drGfb["gfb02"]   = gebModel.geb05;  //項次
                    drGfb["gfb03"]   = gebModel.geb06;  //科目編號
                    drGfb["gfb04"]   = gebModel.geb07;  //摘要
                    drGfb["gfb05"]   = gebModel.geb08;  //部門
                    drGfb["gfb06"]   = gebModel.geb09;  //借貸別
                    drGfb["gfb07"]   = gebModel.geb10;  //本幣金額
                    drGfb["gfb08"]   = gebModel.geb11;  //原幣幣別
                    drGfb["gfb09"]   = gebModel.geb12;  //匯率
                    drGfb["gfb10"]   = gebModel.geb13;  //原幣金額
                    drGfb["gfb11"]   = DBNull.Value;    //保留
                    drGfb["gfb12"]   = DBNull.Value;    //保留
                    drGfb["gfb13"]   = DBNull.Value;    //保留
                    drGfb["gfb14"]   = DBNull.Value;    //保留
                    drGfb["gfb15"]   = DBNull.Value;    //保留
                    drGfb["gfb16"]   = DBNull.Value;    //保留
                    drGfb["gfb17"]   = DBNull.Value;    //保留
                    drGfb["gfb18"]   = DBNull.Value;    //保留
                    drGfb["gfb19"]   = DBNull.Value;    //保留
                    drGfb["gfb20"]   = DBNull.Value;    //保留
                    drGfb["gfbcomp"] = _loginInfo.CompNo;
                    drGfb["gfbcreu"] = _loginInfo.UserNo;
                    drGfb["gfbcreg"] = _loginInfo.DeptNo;
                    drGfb["gfbcred"] = OfGetNow();
                    drGfb["gfbmodu"] = DBNull.Value;
                    drGfb["gfbmodg"] = DBNull.Value;
                    drGfb["gfbmodd"] = DBNull.Value;
                    dtGfb.Rows.Add(drGfb);
                }

                if (boGla.OfUpdate(dtGfb) == -1)
                {
                    pResult.Key1    = pGeaModel.gea01;
                    pResult.Message = "新增傳票單身失敗!";
                    return(false);
                }

                updateSql   = @"UPDATE cfa_tb 
                            SET cfa12=@cfa12
                            WHERE cfa01=@cfa01
                            ";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@cfa12", gfa01New));
                sqlParmList.Add(new SqlParameter("@cfa01", pCfaModel.cfa01));
                chkCnts = OfExecuteNonquery(updateSql, sqlParmList.ToArray());
                if (chkCnts != 1)
                {
                    pResult.Key1    = pGeaModel.gea01;
                    pResult.Message = "更新收款單失敗!";
                    return(false);
                }

                updateSql   = @"UPDATE gea_tb 
                            SET gea06=@gea06,
                                gea07=@gea07
                            WHERE gea01=@gea01
                                 AND gea02=@gea02
                                AND gea03=@gea03
                                AND gea04=@gea04
                            ";
                sqlParmList = new List <SqlParameter>();
                sqlParmList.Add(new SqlParameter("@gea06", gfa01New));
                sqlParmList.Add(new SqlParameter("@gea07", gfa02));
                sqlParmList.Add(new SqlParameter("@gea01", pGeaModel.gea01));
                sqlParmList.Add(new SqlParameter("@gea02", pGeaModel.gea02));
                sqlParmList.Add(new SqlParameter("@gea03", pGeaModel.gea03));
                sqlParmList.Add(new SqlParameter("@gea04", pGeaModel.gea04));
                chkCnts = OfExecuteNonquery(updateSql, sqlParmList.ToArray());
                if (chkCnts != 1)
                {
                    pResult.Key1    = pGeaModel.gea01;
                    pResult.Message = "更新分稿底稿失敗!";
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                pResult.Key1      = pCfaModel.cfa01;
                pResult.Message   = ex.Message;
                pResult.Exception = ex;
                throw;
            }
        }