Ejemplo n.º 1
0
        /// <summary>
        /// 获取采购入库单实体数据
        /// </summary>
        /// <param name="cCode"></param>
        /// <returns></returns>
        public EntityRdRecord01Head GetEntityRdRecord01Head(string cCode)
        {
            EntityRdRecord01Head         entity   = new EntityRdRecord01Head();
            List <Entityrdrecords01Body> listBody = new List <Entityrdrecords01Body>();
            string sqlHead = "SELECT cCode ,dDate,cVenCode,cPTCode,cWhCode,cRdCode,cOrderCode,cMaker,cMemo FROM RdRecord01 WHERE cCode = @cCode ";
            string sqlBody = "SELECT cInvCode,iQuantity,iOriTaxCost,ioriSum,iTaxRate,cBatch FROM RdRecords01 WHERE ID = (SELECT ID FROM RdRecord01 WHERE cCode = @cCode )";

            SqlParameter[] paras =
            {
                new SqlParameter("@cCode", cCode)
            };
            SqlDataReader drHead = DB_SqlHelper.ExecuteReader(CommandType.Text, sqlHead, paras);
            SqlDataReader drBody = DB_SqlHelper.ExecuteReader(CommandType.Text, sqlBody, paras);

            while (drBody.Read())
            {
                Entityrdrecords01Body body = new Entityrdrecords01Body();
                body.cInvCode    = drBody["cInvCode"].ToString();
                body.iQuantity   = Convert.ToDecimal(drBody["iQuantity"] ?? 0);
                body.iOriTaxCost = Convert.ToDecimal(drBody["iOriTaxCost"] ?? 0);
                body.ioriSum     = Convert.ToDecimal(drBody["ioriSum"] ?? 0);
                body.iTaxRate    = Convert.ToDecimal(drBody["iTaxRate"] ?? 0);
                body.cBatch      = drBody["cBatch"].ToString();
                listBody.Add(body);
            }

            if (drHead.Read())
            {
                entity.cCode      = cCode;
                entity.dDate      = Convert.ToDateTime(drHead["dDate"]);
                entity.cVenCode   = drHead["cVenCode"].ToString();
                entity.cPTCode    = drHead["cPTCode"].ToString();
                entity.cWhCode    = drHead["cWhCode"].ToString();
                entity.cRdCode    = drHead["cRdCode"].ToString();
                entity.cOrderCode = drHead["cOrderCode"].ToString();
                entity.cMaker     = drHead["cMaker"].ToString();
                entity.cMemo      = drHead["cMemo"].ToString();
                entity.Details    = listBody;
            }
            return(entity);
        }
Ejemplo n.º 2
0
        public string InsertRdRecord01(EntityRdRecord01Head RdRecord01Head)
        {
            int?RdRecord01HeadID;

            if (RdRecord01Head == null || RdRecord01Head.Details == null || RdRecord01Head.Details.Count == 0)
            {
                throw new JRException("采购入库单新增失败!没有数据!");
            }
            #region 验证

            string POID = null;
            //传入采购订单号时判断对应的采购订单是否存在
            if (!string.IsNullOrWhiteSpace(RdRecord01Head.cOrderCode))
            {
                POID = GetPOID(RdRecord01Head.cOrderCode);
                if (string.IsNullOrEmpty(POID))
                {
                    throw new JRException(string.Format("U8中不存在采购订单号:{0}", RdRecord01Head.cOrderCode));
                }
            }
            #endregion
            int detailCount = RdRecord01Head.Details.Count;
            int head_id     = 0;
            int body_end_Id = 0;

            GetId("00", "rd", detailCount, out head_id, out body_end_Id);
            string sql = string.Format(@"insert into RdRecord01(ID,bRdFlag,cVouchType,cBusType,cSource,cWhCode,
                                         dDate,cCode,cRdCode,cPTCode,cVenCode,cMemo,bTransFlag,cMaker,VT_ID,bIsSTQc,
                                         iTaxRate,iExchRate,cExch_Name,dnmaketime,csysbarcode,cOrderCode,ipurorderid)
                                         values
                                         (@ID,@bRdFlag,@cVouchType,@cBusType,@cSource,@cWhCode,
                                         @dDate,@cCode,@cRdCode,@cPTCode,@cVenCode,left(@cMemo,255),@bTransFlag,@cMaker,@VT_ID,@bIsSTQc,
                                         @iTaxRate,@iExchRate,@cExch_Name,@dnmaketime,@csysbarcode,@cOrderCode,@ipurorderid)");

            SqlParameter[] para =
            {
                new SqlParameter("@ID",          head_id),
                new SqlParameter("@bRdFlag",     RdRecord01Head.bRdFlag),
                new SqlParameter("@cVouchType",  RdRecord01Head.cVouchType),
                new SqlParameter("@cBusType",    RdRecord01Head.cBusType),
                new SqlParameter("@cSource",     RdRecord01Head.cSource),
                new SqlParameter("@cWhCode",     RdRecord01Head.cWhCode),
                new SqlParameter("@dDate",       RdRecord01Head.dDate),
                new SqlParameter("@cCode",       RdRecord01Head.cCode),
                new SqlParameter("@cRdCode",     RdRecord01Head.cRdCode),
                new SqlParameter("@cPTCode",     RdRecord01Head.cPTCode),
                new SqlParameter("@cVenCode",    RdRecord01Head.cVenCode),
                new SqlParameter("@cMemo",       RdRecord01Head.cMemo),
                new SqlParameter("@bTransFlag",  RdRecord01Head.bTransFlag),
                new SqlParameter("@cMaker",      RdRecord01Head.cMaker),
                new SqlParameter("@VT_ID",       RdRecord01Head.VT_ID),
                new SqlParameter("@bIsSTQc",     RdRecord01Head.bIsSTQc),
                new SqlParameter("@iTaxRate",    RdRecord01Head.iTaxRate),
                new SqlParameter("@iExchRate",   RdRecord01Head.iExchRate),
                new SqlParameter("@cExch_Name",  RdRecord01Head.cExch_Name),
                new SqlParameter("@dnmaketime",  DateTime.Now),
                new SqlParameter("@csysbarcode", RdRecord01Head.cSysbarCode),
                new SqlParameter("@cOrderCode",  GetDBValue(RdRecord01Head.cOrderCode)),
                new SqlParameter("@ipurorderid", GetDBValue(POID)),
            };

            int headCount = this.DB_SqlHelper.ExecuteNonQuery(sql, para);
            if (headCount > 0)
            {
                try
                {
                    List <ExecuteHelp> sqlList = new List <ExecuteHelp>();
                    RdRecord01HeadID = GetRdRecord01HeadID(RdRecord01Head.cCode);
                    if (RdRecord01HeadID == null)
                    {
                        throw new JRException("采购入库单表头新增失败!");
                    }
                    string getCurrentStockSql = GetCurrentStockSql("Rd01");

                    for (int i = 0; i < detailCount; i++)
                    {
                        Entityrdrecords01Body body = RdRecord01Head.Details[i];
                        string         bodySql     = string.Format(@"insert into rdrecords01(AutoID,ID,cInvCode,iQuantity,iUnitCost,iPrice,
                                                         iAPrice,iFlag,fACost,chVencode,iOriTaxCost,iOriCost,iOriMoney,iOriTaxPrice,
                                                         ioriSum,iTaxRate,iTaxPrice,iSum,iBillSettleCount,iMatSettleState,iNQuantity
                                                         ,bCosting,irowno,cbsysbarcode,cPOID,iPOsID,cBatch
                                                         ,iSQuantity,iSNum,iMoney,dSDate,bTaxCost,cbaccounter,corufts,isotype,iProductType)
                                                         values
                                                         (@AutoID,@ID,@cInvCode,@iQuantity,@iUnitCost,@iPrice,
                                                         @iAPrice,@iFlag,@fACost,@chVencode,@iOriTaxCost,@iOriCost,@iOriMoney,@iOriTaxPrice,
                                                         @ioriSum,@iTaxRate,@iTaxPrice,@iSum,@iBillSettleCount,@iMatSettleState,@iNQuantity
                                                         ,@bCosting,@irowno,@cbsysbarcode,@cPOID,@iPOsID,@cBatch
                                                         ,0,0,0,NULL,1,NULL,NULL,0,0);
                                                        INSERT INTO IA_ST_UnAccountVouch01 (IDUN,IDSUN,cVouTypeUN,cBustypeUN)
                                                        VALUES(@ID,@AutoID,'01','普通采购');                                                  
                                                        {0}
                                                        update po_podetails set iReceivedQTY=isnull(iReceivedQTY,0) + @iQuantity where POID=@POID and cInvCode =@cInvCode", getCurrentStockSql);
                        SqlParameter[] bodyPara    =
                        {
                            new SqlParameter("@AutoID",           body_end_Id - detailCount + i + 1),
                            new SqlParameter("@ID",               RdRecord01HeadID),
                            new SqlParameter("@cInvCode",         body.cInvCode),
                            new SqlParameter("@iQuantity",        body.iQuantity),
                            new SqlParameter("@iUnitCost",        body.iUnitCost),
                            new SqlParameter("@iPrice",           body.iPrice),
                            new SqlParameter("@iAPrice",          body.iAPrice),
                            new SqlParameter("@iFlag",            body.iFlag),
                            new SqlParameter("@fACost",           body.fACost),
                            new SqlParameter("@chVencode",        body.chVencode),
                            new SqlParameter("@iOriTaxCost",      body.iOriTaxCost),
                            new SqlParameter("@iOriCost",         body.iOriCost),
                            new SqlParameter("@iOriMoney",        body.iOriMoney),
                            new SqlParameter("@iOriTaxPrice",     body.iOriTaxPrice),
                            new SqlParameter("@ioriSum",          body.ioriSum),
                            new SqlParameter("@iTaxRate",         body.iTaxRate),
                            new SqlParameter("@iTaxPrice",        body.iTaxPrice),
                            new SqlParameter("@iSum",             body.iSum),
                            new SqlParameter("@iBillSettleCount", body.iBillSettleCount),
                            new SqlParameter("@iMatSettleState",  body.iMatSettleState),
                            new SqlParameter("@iNQuantity",       body.iQuantity),
                            new SqlParameter("@bCosting",         body.bCosting),
                            new SqlParameter("@irowno",           i + 1),
                            new SqlParameter("@cbsysbarcode",     RdRecord01Head.cSysbarCode + "|" + (i + 1)),
                            new SqlParameter("@cPOID",            GetDBValue(RdRecord01Head.cOrderCode)),
                            new SqlParameter("@iPOsID",           GetDBValue(GetiPOsID(POID,                  body.cInvCode))),
                            new SqlParameter("@POID",             GetDBValue(POID)),
                            new SqlParameter("@cBatch",           GetDBValue(body.cBatch)),
                            new SqlParameter("@cWhCode",          GetDBValue(RdRecord01Head.cWhCode)),
                        };
                        sqlList.Add(new ExecuteHelp()
                        {
                            SQL = bodySql, Parameters = bodyPara
                        });
                    }
                    int bodyCount = this.DB_SqlHelper.ExecuteNonQuery(sqlList);
                }
                catch (Exception ex)
                {
                    // 表体执行错误,表头也要回滚
                    DeleteRdRecord01(RdRecord01Head.cCode);
                    throw ex;
                }
            }
            else
            {
                throw new JRException("采购入库单表头新增失败!");
            }
            return(RdRecord01HeadID == null ? null : RdRecord01HeadID.ToString());
        }