Example #1
0
        protected override bool WfExecute()
        {
            vw_glab313    masterModel = null;
            int           chkCnts     = 0;
            StringBuilder sbResult    = null;

            try
            {
                //取得交易物件
                BoMaster.TRAN  = BoMaster.OfGetConntion().BeginTransaction();
                BoGlab313.TRAN = BoMaster.TRAN;

                masterModel = DrMaster.ToItem <vw_glab313>();
                var securityString = WfGetSecurityString();
                var resultList     = BoGlab313.OfGlab313Post(masterModel, securityString, "", LoginInfo);

                if (resultList == null || resultList.Count == 0)
                {
                    WfShowBottomStatusMsg("無可過帳還原資料!");
                    BoGlab313.TRAN.Rollback();
                    return(true);
                }

                chkCnts = resultList.Where(p => p.Success == false).Count();
                if (chkCnts > 0)
                {
                    BoGlab313.TRAN.Rollback();
                    sbResult = new StringBuilder();
                    sbResult.AppendLine(string.Format("執行失敗!"));
                    sbResult.AppendLine(string.Format("過帳還原傳票筆數【{0}】 成功:【{1}】  失敗【{2}】",
                                                      resultList.Count,
                                                      resultList.Count - chkCnts,
                                                      chkCnts
                                                      ));
                    sbResult.AppendLine();
                    sbResult.AppendLine(string.Format("錯誤內容如下"));
                    sbResult.AppendLine("====================================");
                    foreach (Result result in resultList.Where(p => p.Success == false))
                    {
                        sbResult.AppendLine(string.Format("key1:【{0}】 錯誤訊息:【{1}】", result.Key1, result.Message));
                    }
                    WfShowErrorMsg(sbResult.ToString());
                    BoGlab313.TRAN.Rollback();
                    return(false);
                }
                BoMaster.TRAN.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                if (BoMaster.TRAN != null)
                {
                    BoMaster.TRAN.Rollback();
                }
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// 過帳及重過帳共用程式
        /// </summary>
        /// <param name="pModel"></param>
        /// <param name="pPost"></param>
        /// <returns></returns>
        public List <Result> OfGlab313Post(vw_glab313 pModel, string pSecurityString, string pSrcFormId, UserInfo pLoginInfo)
        {
            List <Result>       rtnResultList = null;
            string              selectSql = "";
            string              strQueryRange = "", strQuerySingle = "";
            List <SqlParameter> sqlParmList = null;
            DataTable           dtGfa       = null;
            List <QueryInfo>    queryInfoList;
            QueryInfo           queryModel;
            gfa_tb              gfaModel;

            try
            {
                _loginInfo = pLoginInfo;

                selectSql = @"
                            SELECT * FROM gfa_tb
                            WHERE gfaconf='Y'
                                AND gfapost='Y'
                        ";

                sqlParmList   = new List <SqlParameter>();
                queryInfoList = new List <QueryInfo>();
                #region range 處理
                if (!GlobalFn.varIsNull(pModel.gfa01))
                {
                    queryModel            = new QueryInfo();
                    queryModel.TableName  = "gfa_tb";
                    queryModel.ColumnName = "gfa01";
                    queryModel.ColumnType = "string";
                    queryModel.Value      = pModel.gfa01;
                    queryInfoList.Add(queryModel);
                }
                sqlParmList   = new List <SqlParameter>();
                strQueryRange = WfGetQueryString(queryInfoList, out sqlParmList);
                #endregion

                #region single處理
                if (!GlobalFn.varIsNull(pModel.gfa02_s))
                {
                    sqlParmList.Add(new SqlParameter("@gfa02_s", pModel.gfa02_s));
                    strQuerySingle += string.Format(" AND gfa02>=@gfa02_s");
                }
                if (!GlobalFn.varIsNull(pModel.gfa02_e))
                {
                    sqlParmList.Add(new SqlParameter("@gfa02_e", pModel.gfa02_e));
                    strQuerySingle += string.Format(" AND gfa02<=@gfa02_e");
                }
                #endregion
                selectSql = string.Concat(selectSql, strQueryRange, strQuerySingle, pSecurityString);
                dtGfa     = OfGetDataTable(selectSql, sqlParmList.ToArray());
                if (dtGfa == null || dtGfa.Rows.Count == 0)
                {
                    return(null);
                }

                rtnResultList = new List <Result>();
                foreach (DataRow drGfa in dtGfa.Rows)
                {
                    gfaModel = drGfa.ToItem <gfa_tb>();
                    var result = new Result();
                    rtnResultList.Add(result);

                    if (gfaModel.gfa03 != gfaModel.gfa04)
                    {
                        result.Key1    = gfaModel.gfa01;
                        result.Message = "借貸不平衡!";
                        continue;
                    }

                    if (OfPostGfa(gfaModel) == false)
                    {
                        result.Key1    = gfaModel.gfa01;
                        result.Message = "更新gfa_tb失敗!";
                        continue;
                    }

                    if (OfPostGfb(gfaModel, result) == false)
                    {
                        continue;
                    }

                    result.Success = true;
                }

                return(rtnResultList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }