Beispiel #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(FishEntity.LoadingDetailEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_loadingdetail(");
            strSql.Append("mid,productid,productcode,product,specification,shipname,billofgoods,tons,packages,remark,unitprice,contractid,contractno,contractseq,contractdetailid)");
            strSql.Append(" values (");
            strSql.Append("@mid,@productid,@productcode,@product,@specification,@shipname,@billofgoods,@tons,@packages,@remark,@unitprice,@contractid,@contractno,@contractseq,@contractdetailid);");
            strSql.Append("select LAST_INSERT_ID();");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@mid",              MySqlDbType.Int32,    11),
                new MySqlParameter("@productid",        MySqlDbType.Int32,    11),
                new MySqlParameter("@productcode",      MySqlDbType.VarChar,  45),
                new MySqlParameter("@product",          MySqlDbType.VarChar,  50),
                new MySqlParameter("@specification",    MySqlDbType.VarChar,  45),
                new MySqlParameter("@shipname",         MySqlDbType.VarChar,  50),
                new MySqlParameter("@billofgoods",      MySqlDbType.VarChar,  45),
                new MySqlParameter("@tons",             MySqlDbType.Decimal,  12),
                new MySqlParameter("@packages",         MySqlDbType.Int32,    11),
                new MySqlParameter("@remark",           MySqlDbType.VarChar, 255),
                new MySqlParameter("@unitprice",        MySqlDbType.Decimal,  12),
                new MySqlParameter("@contractid",       MySqlDbType.Int32,     8),
                new MySqlParameter("@contractno",       MySqlDbType.VarChar,  45),
                new MySqlParameter("@contractseq",      MySqlDbType.Int32,    10),
                new MySqlParameter("@contractdetailid", MySqlDbType.Int32, 10)
            };
            parameters[0].Value  = model.mid;
            parameters[1].Value  = model.productid;
            parameters[2].Value  = model.productcode;
            parameters[3].Value  = model.product;
            parameters[4].Value  = model.specification;
            parameters[5].Value  = model.shipname;
            parameters[6].Value  = model.billofgoods;
            parameters[7].Value  = model.tons;
            parameters[8].Value  = model.packages;
            parameters[9].Value  = model.remark;
            parameters[10].Value = model.unitprice;
            parameters[11].Value = model.contractid;
            parameters[12].Value = model.contractno;
            parameters[13].Value = model.contractseq;
            parameters[14].Value = model.contractdetailid;

            int id = MySqlHelper.ExecuteSqlReturnId(strSql.ToString(), parameters);

            return(id);
        }
Beispiel #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FishEntity.LoadingDetailEntity GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,mid,productid,productcode,product,specification,shipname,billofgoods,tons,packages,remark,unitprice,contractid,contractno,contractseq,contractdetailid from t_loadingdetail ");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32)
            };
            parameters[0].Value = id;

            FishEntity.LoadingDetailEntity model = new FishEntity.LoadingDetailEntity();
            DataSet ds = MySqlHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(FishEntity.LoadingDetailEntity model)
 {
     return(dal.Update(model));
 }
Beispiel #4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(FishEntity.LoadingDetailEntity model)
 {
     return(dal.Add(model));
 }
Beispiel #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(FishEntity.LoadingDetailEntity model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_loadingdetail set ");
            strSql.Append("mid=@mid,");
            strSql.Append("productid=@productid,");
            strSql.Append("productcode=@productcode,");
            strSql.Append("product=@product,");
            strSql.Append("specification=@specification,");
            strSql.Append("shipname=@shipname,");
            strSql.Append("billofgoods=@billofgoods,");
            strSql.Append("tons=@tons,");
            strSql.Append("packages=@packages,");
            strSql.Append("remark=@remark,");
            strSql.Append("unitprice=@unitprice,");
            strSql.Append("contractid=@contractid,");
            strSql.Append("contractno=@contractno,");
            strSql.Append("contractseq=@contractseq,");
            strSql.Append("contractdetailid=@contractdetailid");
            strSql.Append(" where id=@id");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@mid",              MySqlDbType.Int32,    11),
                new MySqlParameter("@productid",        MySqlDbType.Int32,    11),
                new MySqlParameter("@productcode",      MySqlDbType.VarChar,  45),
                new MySqlParameter("@product",          MySqlDbType.VarChar,  50),
                new MySqlParameter("@specification",    MySqlDbType.VarChar,  45),
                new MySqlParameter("@shipname",         MySqlDbType.VarChar,  50),
                new MySqlParameter("@billofgoods",      MySqlDbType.VarChar,  45),
                new MySqlParameter("@tons",             MySqlDbType.Decimal,  12),
                new MySqlParameter("@packages",         MySqlDbType.Int32,    11),
                new MySqlParameter("@remark",           MySqlDbType.VarChar, 255),
                new MySqlParameter("@unitprice",        MySqlDbType.Decimal,  12),
                new MySqlParameter("@contractid",       MySqlDbType.Int32,    12),
                new MySqlParameter("@contractno",       MySqlDbType.VarChar,  45),
                new MySqlParameter("@contractseq",      MySqlDbType.Int32,    12),
                new MySqlParameter("@contractdetailid", MySqlDbType.Int32,    11),
                new MySqlParameter("@id",               MySqlDbType.Int32, 11)
            };
            parameters[0].Value  = model.mid;
            parameters[1].Value  = model.productid;
            parameters[2].Value  = model.productcode;
            parameters[3].Value  = model.product;
            parameters[4].Value  = model.specification;
            parameters[5].Value  = model.shipname;
            parameters[6].Value  = model.billofgoods;
            parameters[7].Value  = model.tons;
            parameters[8].Value  = model.packages;
            parameters[9].Value  = model.remark;
            parameters[10].Value = model.unitprice;
            parameters[11].Value = model.contractid;
            parameters[12].Value = model.contractno;
            parameters[13].Value = model.contractseq;
            parameters[14].Value = model.contractdetailid;
            parameters[15].Value = model.id;

            int rows = MySqlHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public FishEntity.LoadingDetailEntity DataRowToModel(DataRow row)
 {
     FishEntity.LoadingDetailEntity model = new FishEntity.LoadingDetailEntity();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["mid"] != null && row["mid"].ToString() != "")
         {
             model.mid = int.Parse(row["mid"].ToString());
         }
         if (row["productid"] != null && row["productid"].ToString() != "")
         {
             model.productid = int.Parse(row["productid"].ToString());
         }
         if (row["productcode"] != null)
         {
             model.productcode = row["productcode"].ToString();
         }
         if (row["product"] != null)
         {
             model.product = row["product"].ToString();
         }
         if (row["specification"] != null)
         {
             model.specification = row["specification"].ToString();
         }
         if (row["shipname"] != null)
         {
             model.shipname = row["shipname"].ToString();
         }
         if (row["billofgoods"] != null)
         {
             model.billofgoods = row["billofgoods"].ToString();
         }
         if (row["tons"] != null && row["tons"].ToString() != "")
         {
             model.tons = decimal.Parse(row["tons"].ToString());
         }
         if (row["packages"] != null && row["packages"].ToString() != "")
         {
             model.packages = int.Parse(row["packages"].ToString());
         }
         if (row["unitprice"] != null && row["unitprice"].ToString() != "")
         {
             model.unitprice = decimal.Parse(row["unitprice"].ToString());
         }
         if (row["remark"] != null)
         {
             model.remark = row["remark"].ToString();
         }
         if (row["contractid"] != null && row["contractid"].ToString() != "")
         {
             model.contractid = int.Parse(row["contractid"].ToString());
         }
         if (row["contractno"] != null)
         {
             model.contractno = row["contractno"].ToString();
         }
         if (row["contractseq"] != null && row["contractseq"].ToString() != "")
         {
             model.contractseq = int.Parse(row["contractseq"].ToString());
         }
         if (row["contractdetailid"] != null && row["contractdetailid"].ToString() != "")
         {
             model.contractdetailid = int.Parse(row["contractdetailid"].ToString());
         }
     }
     return(model);
 }
Beispiel #7
0
        protected void AddProducts(int billId, bool isAdd)
        {
            List <FishEntity.LoadingDetailEntity> listNews   = GetDetails(billId);
            List <FishEntity.LoadingDetailEntity> listsource = null;

            FishBll.Bll.LoadingDetailBll detailBll  = new FishBll.Bll.LoadingDetailBll();
            FishBll.Bll.ProductBll       productBll = new FishBll.Bll.ProductBll();

            if (isAdd == false)
            {
                listsource = detailBll.GetDetailOfBill(billId);
                if (listsource != null)
                {
                    foreach (FishEntity.LoadingDetailEntity item in listsource)
                    {
                        bool isExist = listNews.Exists((i) => { return(i.id == item.id); });
                        if (isExist == false)
                        {
                            UpdateProductCount(item.productid, -item.tons, -item.packages);
                            UpdateContract(item.contractid, item.contractdetailid, -item.tons, -item.packages);
                            bool isDelte = detailBll.Delete(item.id);
                        }
                    }
                }
            }

            foreach (FishEntity.LoadingDetailEntity item in listNews)
            {
                if (item.id == 0)
                {
                    int detailId = detailBll.Add(item);
                    if (detailId > 0)
                    {
                        UpdateProductCount(item.productid, -item.tons, -item.packages);
                        UpdateContract(item.contractid, item.contractdetailid, item.tons, item.packages);
                        item.id = detailId;
                    }
                }
                else
                {
                    decimal sWeight  = 0;
                    int     sPackage = 0;
                    if (listsource != null)
                    {
                        FishEntity.LoadingDetailEntity sRecord = listsource.Find((i) => { return(i.id == item.id); });
                        if (sRecord != null)
                        {
                            sWeight  = sRecord.tons;
                            sPackage = sRecord.packages;
                        }
                    }

                    decimal dWeight  = item.tons;
                    int     dPackage = item.packages;

                    decimal weight  = dWeight - sWeight;
                    int     package = dPackage - sPackage;

                    UpdateProductCount(item.productid, weight, package);
                    UpdateContract(item.contractid, item.contractdetailid, weight, package);

                    detailBll.Update(item);
                }
            }

            SetDetail(listNews);
        }
Beispiel #8
0
        protected List <FishEntity.LoadingDetailEntity> GetDetails(int billId)
        {
            dataGridView1.EndEdit();

            List <FishEntity.LoadingDetailEntity> listNews = new List <FishEntity.LoadingDetailEntity>();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }
                FishEntity.LoadingDetailEntity product = new FishEntity.LoadingDetailEntity();
                product.billofgoods = row.Cells["billofgoods"].Value == null ? string.Empty : row.Cells["billofgoods"].Value.ToString().Trim();
                product.mid         = billId;

                int did = 0;
                if (row.Cells["id"].Value != null)
                {
                    int.TryParse(row.Cells["id"].Value.ToString(), out did);
                }
                product.id = did;

                int packageInt = 0;

                if (row.Cells["packages"].Value != null)
                {
                    int.TryParse(row.Cells["packages"].Value.ToString(), out packageInt);
                }
                product.packages = packageInt;

                product.product     = row.Cells["productname"].Value == null ? string.Empty : row.Cells["productname"].Value.ToString();
                product.productcode = row.Cells["code"].Value == null ? string.Empty : row.Cells["code"].Value.ToString();
                int pid = 0;
                if (row.Cells["productid"].Value != null)
                {
                    int.TryParse(row.Cells["productid"].Value.ToString(), out pid);
                }
                product.productid     = pid;
                product.remark        = row.Cells["remark"].Value == null ? string.Empty : row.Cells["remark"].Value.ToString();
                product.shipname      = row.Cells["shipno"].Value == null ? string.Empty : row.Cells["shipno"].Value.ToString();
                product.specification = row.Cells["specification"].Value == null ? string.Empty : row.Cells["specification"].Value.ToString();
                decimal tonsDec = 0;
                if (row.Cells["tons"].Value != null)
                {
                    decimal.TryParse(row.Cells["tons"].Value.ToString(), out tonsDec);
                }
                product.tons = tonsDec;

                decimal unitpriceDec = 0.00M;
                if (row.Cells["unitprice"].Value != null)
                {
                    decimal.TryParse(row.Cells["unitprice"].Value.ToString(), out unitpriceDec);
                }
                product.unitprice = unitpriceDec;


                int contractid = 0;
                if (row.Cells["contractid"].Value != null)
                {
                    int.TryParse(row.Cells["contractid"].Value.ToString(), out contractid);
                }
                product.contractid = contractid;

                //product.contractno = row.Cells["contractno"].Value.ToString();

                int no = 0;
                if (row.Cells["no"].Value != null)
                {
                    int.TryParse(row.Cells["no"].Value.ToString(), out no);
                }
                product.contractseq = no;

                int detailid = 0;
                if (row.Cells["contractdetailid"].Value != null)
                {
                    int.TryParse(row.Cells["contractdetailid"].Value.ToString(), out detailid);
                }
                product.contractdetailid = detailid;

                listNews.Add(product);
            }

            return(listNews);
        }