Exemple #1
0
        /// <summary>
        /// 保存(传入事务处理)
        /// </summary>
        /// <param name="p_Entity"></param>
        /// <param name="p_BE"></param>
        /// <param name="sqlTrans"></param>
        public void RSave(FHForm p_Entity, BaseEntity[] p_BE, ArrayList list, IDBTransAccess sqlTrans)
        {
            try
            {
                string sql = "DELETE FROM Sale_FHFormDts WHERE MainID=" + p_Entity.ID.ToString();
                sql += " AND ID NOT IN" + string.Format("({0})", GetIDExist(p_BE));
                sqlTrans.ExecuteNonQuery(sql);//删除原单据里应该删除的明细数据,即数据库里有但是UI里已经删除的数据

                sql = "DELETE Sale_FHFormDtsPack WHERE MainID=" + SysString.ToDBString(p_Entity.ID);
                sqlTrans.ExecuteNonQuery(sql);


                for (int i = 0; i < p_BE.Length; i++)
                {
                    FHFormDts entitydts = (FHFormDts)p_BE[i];
                    if (entitydts.ID != 0)//ID不为0说明数据库中已经存在
                    {
                        entitydts.MainID = p_Entity.ID;
                        this.RUpdate(entitydts, sqlTrans);
                    }
                    else
                    {
                        entitydts.MainID = p_Entity.ID;
                        this.RAdd(entitydts, sqlTrans);
                    }
                }

                for (int i = 0; i < list.Count; i++)
                {
                    FHFormDtsPackRule rule      = new FHFormDtsPackRule();
                    FHFormDtsPack     entitydts = (FHFormDtsPack)list[i];
                    entitydts.MainID = p_Entity.ID;
                    rule.RAdd(entitydts, sqlTrans);
                }
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// 新增(传入事务处理)
        /// </summary>
        /// <param name="p_BE">要新增的实体</param>
        /// <param name="sqlTrans">事务类</param>
        public void RAdd(int p_ID, string p_IDStr, IDBTransAccess sqlTrans)
        {
            try
            {
                string sql = "SELECT SectionID,JarNum,Batch FROM WH_PackBox WHERE ID IN (" + p_IDStr + ")";
                sql += " GROUP BY SectionID,JarNum,Batch";
                DataTable     dt     = sqlTrans.Fill(sql);
                int           MaxSeq = GetMaxSeq(p_ID);
                decimal       Qty    = 0;
                FHFormDtsRule rule   = new FHFormDtsRule();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i == 0)//第一行更新
                    {
                        sql  = "SELECT * FROM WH_PackBox WHERE ID IN (" + p_IDStr + ")";
                        sql += " AND SectionID=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["SectionID"]));
                        sql += " AND JarNum=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["JarNum"]));
                        sql += " AND Batch=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["Batch"]));
                        DataTable dtsql = sqlTrans.Fill(sql);

                        FHFormDts entitydts = new FHFormDts(sqlTrans);
                        entitydts.ID = p_ID;
                        entitydts.SelectByID();
                        entitydts.SectionID = SysConvert.ToString(dt.Rows[i]["SectionID"]);
                        entitydts.JarNum    = SysConvert.ToString(dt.Rows[i]["JarNum"]);
                        entitydts.Batch     = SysConvert.ToString(dt.Rows[i]["Batch"]);
                        entitydts.Qty       = SysConvert.ToDecimal(dtsql.Compute("SUM(Qty)", ""));
                        entitydts.PieceQty  = dtsql.Rows.Count;
                        entitydts.PackFlag  = 1;
                        entitydts.Amount    = entitydts.Qty * entitydts.SingPrice;
                        rule.RUpdate(entitydts, sqlTrans);

                        FHFormDtsPackRule prule = new FHFormDtsPackRule();
                        sql  = "DELETE Sale_FHFormDtsPack WHERE MainID=" + SysString.ToDBString(entitydts.MainID);
                        sql += " AND Seq=" + SysString.ToDBString(entitydts.Seq);
                        sqlTrans.ExecuteNonQuery(sql);
                        for (int j = 0; j < dtsql.Rows.Count; j++)
                        {
                            FHFormDtsPack pentity = new FHFormDtsPack(sqlTrans);
                            pentity.MainID = entitydts.MainID;
                            pentity.Seq    = entitydts.Seq;
                            pentity.SubSeq = j + 1;
                            pentity.BoxNo  = SysConvert.ToString(dtsql.Rows[j]["BoxNo"]);
                            pentity.Qty    = SysConvert.ToDecimal(dtsql.Rows[j]["Qty"]);
                            pentity.DID    = entitydts.ID;
                            prule.RAdd(pentity, sqlTrans);
                        }
                    }
                    else
                    {
                        sql  = "SELECT * FROM WH_PackBox WHERE ID IN (" + p_IDStr + ")";
                        sql += " AND SectionID=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["SectionID"]));
                        sql += " AND JarNum=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["JarNum"]));
                        sql += " AND Batch=" + SysString.ToDBString(SysConvert.ToString(dt.Rows[i]["Batch"]));
                        DataTable dtsql = sqlTrans.Fill(sql);

                        FHFormDts entitydts = new FHFormDts(sqlTrans);
                        entitydts.ID = p_ID;
                        entitydts.SelectByID();
                        entitydts.Seq       = MaxSeq + i;
                        entitydts.SectionID = SysConvert.ToString(dt.Rows[i]["SectionID"]);
                        entitydts.JarNum    = SysConvert.ToString(dt.Rows[i]["JarNum"]);
                        entitydts.Batch     = SysConvert.ToString(dt.Rows[i]["Batch"]);
                        entitydts.Qty       = SysConvert.ToDecimal(dtsql.Compute("SUM(Qty)", ""));
                        entitydts.PieceQty  = dtsql.Rows.Count;
                        entitydts.PackFlag  = 1;

                        entitydts.Amount = entitydts.Qty * entitydts.SingPrice;

                        sql  = "SELECT ID FROM Sale_FHFormDts WHERE MainID=" + SysString.ToDBString(entitydts.MainID);
                        sql += " AND Seq=" + SysString.ToDBString(entitydts.Seq);
                        if (sqlTrans.Fill(sql).Rows.Count > 0)
                        {
                            throw new BaseException("不能增行,该行已存在");
                        }
                        rule.RAdd(entitydts, sqlTrans);

                        IOFormDtsPackRule prule = new IOFormDtsPackRule();
                        sql  = "DELETE Sale_FHFormDtsPack WHERE MainID=" + SysString.ToDBString(entitydts.MainID);
                        sql += " AND Seq=" + SysString.ToDBString(entitydts.Seq);
                        sqlTrans.ExecuteNonQuery(sql);
                        for (int j = 0; j < dtsql.Rows.Count; j++)
                        {
                            FHFormDtsPack pentity = new FHFormDtsPack(sqlTrans);
                            pentity.MainID = entitydts.MainID;
                            pentity.Seq    = entitydts.Seq;
                            pentity.SubSeq = j + 1;
                            pentity.BoxNo  = SysConvert.ToString(dtsql.Rows[j]["BoxNo"]);
                            pentity.Qty    = SysConvert.ToDecimal(dtsql.Rows[j]["Qty"]);
                            pentity.DID    = entitydts.ID;
                            prule.RAdd(pentity, sqlTrans);
                        }
                    }
                }
            }
            catch (BaseException)
            {
                throw;
            }
            catch (Exception E)
            {
                throw new BaseException(E.Message);
            }
        }