예제 #1
0
        protected override bool WfAppendUpdate()
        {
            vw_admi611          admi611Model = null;
            int                 chkCnts      = 0;
            StringBuilder       sbSql        = null;
            List <SqlParameter> sqlParmsList;
            CommonBLL           boAppend;
            DataTable           dtady = null;

            try
            {
                boAppend      = new InvBLL(BoMaster.OfGetConntion());
                boAppend.TRAN = BoMaster.TRAN;
                boAppend.OfCreateDao("ady_tb", "*", "");
                admi611Model = DrMaster.ToItem <vw_admi611>();

                //處理明細--均先刪後新增
                if (FormEditMode != YREditType.新增)
                {
                    sbSql        = new StringBuilder();
                    sqlParmsList = new List <SqlParameter>();
                    sbSql.AppendLine("DELETE FROM ady_tb WHERE ady01=@ady01");
                    sqlParmsList.Add(new SqlParameter("@ady01", admi611Model.adx01));
                    chkCnts = boAppend.OfExecuteNonquery(sbSql.ToString(), sqlParmsList.ToArray());


                    sbSql        = new StringBuilder();
                    sqlParmsList = new List <SqlParameter>();
                    sbSql.AppendLine("SELECT * FROM ady_tb");
                    sbSql.AppendLine("WHERE 1<>1");
                    dtady = boAppend.OfGetDataTable(sbSql.ToString());
                    foreach (vw_admi611s detailModel in Admi611sList)
                    {
                        var drady = dtady.NewRow();
                        drady["ady01"]   = detailModel.ady01;
                        drady["ady02"]   = detailModel.ady02;
                        drady["ady03"]   = detailModel.ady03;
                        drady["ady04"]   = detailModel.ady04;
                        drady["ady05"]   = detailModel.ady05;
                        drady["ady06"]   = detailModel.ady06;
                        drady["ady07"]   = detailModel.ady07;
                        drady["adycreu"] = detailModel.adycreu;
                        drady["adycreg"] = detailModel.adycreg;
                        if (detailModel.adycred == null)
                        {
                            drady["adycred"] = DBNull.Value;
                        }
                        else
                        {
                            drady["adycred"] = detailModel.adycred;
                        }

                        drady["adymodu"] = detailModel.adymodu;
                        drady["adymodg"] = detailModel.adymodg;

                        if (detailModel.adymodd == null)
                        {
                            drady["adymodd"] = DBNull.Value;
                        }
                        else
                        {
                            drady["adymodd"] = detailModel.adymodd;
                        }
                        dtady.Rows.Add(drady);
                    }
                    boAppend.OfUpdate(dtady);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        protected override bool WfExecute()
        {
            vw_invb500          invb500Model;
            List <QueryInfo>    queryInfoList;
            QueryInfo           queryModel;
            List <SqlParameter> sqlParmList;
            string        strQueryRange, strWhere, strOrderBy;
            DataTable     dtMain, dtIpaInsert, dtIpbInsert;
            DataRow       drIpa, drIpb;
            StringBuilder sbSql, sbInsert;
            int           chkCnts = 0;
            string        ipa01New = "", errMsg = "";

            try
            {
                //取得交易物件
                BoMaster.TRAN = BoMaster.OfGetConntion().BeginTransaction(IsolationLevel.ReadUncommitted);
                BoInv.TRAN    = BoMaster.TRAN;
                BoBas.TRAN    = BoMaster.TRAN;

                invb500Model = DrMaster.ToItem <vw_invb500>();
                #region range 查詢條件
                queryInfoList = new List <QueryInfo>();
                if (!GlobalFn.varIsNull(invb500Model.icc01))
                {
                    queryModel = new QueryInfo();

                    queryModel.TableName  = "icc_tb";
                    queryModel.ColumnName = "icc01";
                    queryModel.ColumnType = TabMaster.DtSource.Columns["icc01"].DataType.Name;
                    queryModel.Value      = invb500Model.icc01;
                    queryInfoList.Add(queryModel);
                }
                if (!GlobalFn.varIsNull(invb500Model.icc02))
                {
                    queryModel            = new QueryInfo();
                    queryModel.TableName  = "icc_tb";
                    queryModel.ColumnName = "icc02";
                    queryModel.ColumnType = TabMaster.DtSource.Columns["icc02"].DataType.Name;
                    queryModel.Value      = invb500Model.icc02;
                    queryInfoList.Add(queryModel);
                }

                if (!GlobalFn.varIsNull(invb500Model.icc03))
                {
                    queryModel            = new QueryInfo();
                    queryModel.TableName  = "icc_tb";
                    queryModel.ColumnName = "icc03";
                    queryModel.ColumnType = TabMaster.DtSource.Columns["icc03"].DataType.Name;
                    queryModel.Value      = invb500Model.icc02;
                    queryInfoList.Add(queryModel);
                }

                sqlParmList   = new List <SqlParameter>();
                strQueryRange = BoMaster.WfGetQueryString(queryInfoList, out sqlParmList);
                strWhere      = strQueryRange;
                #endregion

                var strSecurity = WfGetSecurityString();    //暫時無權限問題,先保留
                if (!GlobalFn.varIsNull(strSecurity))
                {
                    strWhere += strSecurity;
                }

                //取得資料
                sbSql = new StringBuilder();
                sbSql.AppendLine("SELECT * FROM icc_tb");
                sbSql.AppendLine("WHERE 1=1");

                #region 加入排序
                strOrderBy = "";
                switch (invb500Model.order_by_1)
                {
                case "1":
                    strOrderBy = " ORDER BY icc03,";
                    break;

                case "2":
                    strOrderBy = " ORDER BY icc01,";
                    break;

                case "3":
                    strOrderBy = " ORDER BY icc02,";
                    break;
                }
                switch (invb500Model.order_by_2)
                {
                case "1":
                    strOrderBy += "icc03,";
                    break;

                case "2":
                    strOrderBy += "icc01,";
                    break;

                case "3":
                    strOrderBy += "icc02,";
                    break;
                }
                switch (invb500Model.order_by_3)
                {
                case "1":
                    strOrderBy += "icc03";
                    break;

                case "2":
                    strOrderBy += "icc01";
                    break;

                case "3":
                    strOrderBy += "icc02";
                    break;
                }
                #endregion

                dtMain           = BoMaster.OfGetDataTable(string.Concat(sbSql.ToString(), strWhere, strOrderBy), sqlParmList.ToArray());
                dtMain.TableName = "Master";

                if (dtMain == null || dtMain.Rows.Count == 0)
                {
                    WfShowErrorMsg("查無資料,請重新過濾條件!");
                    BoMaster.TRAN.Rollback();
                    return(false);
                }

                #region 寫入盤點清冊
                //新增單頭
                if (BoBas.OfGetAutoNo(invb500Model.ipa01, ModuleType.stp, (DateTime)invb500Model.ipa02, out ipa01New, out errMsg) == false)
                {
                    WfShowErrorMsg(errMsg);
                    return(false);
                }

                BoInv.OfCreateDao("ipa_tb", "*", "");
                sbInsert = new StringBuilder();
                sbInsert.AppendLine("SELECT * FROM ipa_tb");
                sbInsert.AppendLine("WHERE 1<>1");
                dtIpaInsert      = BoInv.OfGetDataTable(sbInsert.ToString());
                drIpa            = dtIpaInsert.NewRow();
                drIpa["ipa01"]   = ipa01New;
                drIpa["ipa02"]   = invb500Model.ipa02;
                drIpa["ipa03"]   = invb500Model.ipa03;
                drIpa["ipa04"]   = invb500Model.ipa04;
                drIpa["ipa05"]   = "N";
                drIpa["ipa06"]   = DBNull.Value;
                drIpa["ipa07"]   = "N";
                drIpa["ipa08"]   = DBNull.Value;
                drIpa["ipacomp"] = LoginInfo.CompNo;
                drIpa["ipasecu"] = LoginInfo.UserNo;
                drIpa["ipasecg"] = LoginInfo.GroupNo;
                drIpa["ipacreu"] = LoginInfo.UserNo;
                drIpa["ipacreg"] = LoginInfo.DeptNo;
                drIpa["ipacred"] = Now;
                drIpa["ipamodu"] = DBNull.Value;
                drIpa["ipamodg"] = DBNull.Value;
                drIpa["ipamodd"] = DBNull.Value;

                dtIpaInsert.Rows.Add(drIpa);
                if (BoInv.OfUpdate(dtIpaInsert) != 1)
                {
                    errMsg = "新增盤點清冊(ipa_tb)失敗!";
                    BoMaster.TRAN.Rollback();
                    WfShowErrorMsg(errMsg);
                    return(false);
                }

                BoInv.OfCreateDao("ipb_tb", "*", "");
                sbInsert = new StringBuilder();
                sbInsert.AppendLine("SELECT * FROM ipb_tb");
                sbInsert.AppendLine("WHERE 1<>1");
                dtIpbInsert = BoInv.OfGetDataTable(sbInsert.ToString());
                var i = 0;
                foreach (DataRow drIcc in dtMain.Rows)
                {
                    i++;
                    drIpb = dtIpbInsert.NewRow();
                    var iccModel = drIcc.ToItem <icc_tb>();
                    drIpb["ipb01"]   = ipa01New;
                    drIpb["ipb02"]   = i;
                    drIpb["ipb03"]   = iccModel.icc01;
                    drIpb["ipb04"]   = iccModel.icc02;
                    drIpb["ipb05"]   = iccModel.icc03;
                    drIpb["ipb06"]   = iccModel.icc05;
                    drIpb["ipb07"]   = iccModel.icc04;
                    drIpb["ipb30"]   = 0;
                    drIpb["ipb31"]   = DBNull.Value;
                    drIpb["ipb32"]   = DBNull.Value;
                    drIpb["ipb40"]   = 0;
                    drIpb["ipb41"]   = DBNull.Value;
                    drIpb["ipb42"]   = DBNull.Value;
                    drIpb["ipb50"]   = 0;
                    drIpb["ipb51"]   = DBNull.Value;
                    drIpb["ipb52"]   = DBNull.Value;
                    drIpb["ipbcomp"] = LoginInfo.CompNo;
                    drIpb["ipbcreu"] = LoginInfo.UserNo;
                    drIpb["ipbcreg"] = LoginInfo.DeptNo;
                    drIpb["ipbcred"] = Now;
                    drIpb["ipbmodu"] = DBNull.Value;
                    drIpb["ipbmodg"] = DBNull.Value;
                    drIpb["ipbmodd"] = DBNull.Value;
                    dtIpbInsert.Rows.Add(drIpb);
                }
                if (BoInv.OfUpdate(dtIpbInsert) <= 0)
                {
                    errMsg = "新增盤點清冊(ipb_tb)失敗!";
                    BoMaster.TRAN.Rollback();
                    WfShowErrorMsg(errMsg);
                    return(false);
                }
                #endregion
                BoMaster.TRAN.Commit();

                #region 檢視產生資料
                if (WfShowConfirmMsg("盤點清冊展開完成,是否要檢視盤點資料?") == DialogResult.Yes)
                {
                    sbSql = new StringBuilder();
                    sbSql.AppendLine(string.Format(" AND ipa01='{0}'", ipa01New));
                    WfShowForm("invb501", false, new object[] { "admi600", this.LoginInfo, sbSql.ToString() });
                }
                #endregion
                return(true);
            }
            catch (Exception ex)
            {
                BoMaster.TRAN.Rollback();
                throw ex;
            }
        }