예제 #1
0
        public MessageModel delorder(GoDownEntryModel gm, List <ListModel> list)
        {
            List <string> sqlList = new List <string>();

            string mark = "-";

            if (gm.isDeficit)
            {
                mark = "+";
            }

            string sql = "DELETE FROM godownentry WHERE id = '" + gm.id + "' ";
            //string sqlstock = "DELETE s FROM stock s inner join entrymateriel em on s.entrymateriel = em.id WHERE em.entry = '" + gm.id + "'  and s.batchnum >0";
            string sqlup          = "";
            string sqlSafetyStock = "";

            for (int i = 0; i < list.Count; i++)
            {
                sqlup = "update stock set lastModifiedAt = NOW(),quantity = quantity " + mark + list[i].quantity + ",avaquantity = avaquantity  " + mark + list[i].quantity + " where uqkey = '" + gm.supplier + "|" + list[i].materiel + "|" + gm.warehouse + "|";
                if (gm.position != null)
                {
                    sqlup += "" + gm.position + "|";
                }
                else
                {
                    sqlup += "|";
                }
                if (list[i].isBatch)
                {
                    sqlup += "" + list[i].batch + "|";
                }
                else
                {
                    sqlup += "|";
                }
                if (list[i].combination != null)
                {
                    sqlup += "" + list[i].combination + "'";
                }
                else
                {
                    sqlup += "'";
                }
                sqlList.Add(sqlup);

                sqlSafetyStock = "Update safetystock set stock = stock " + mark + list[i].quantity + " where materiel = '" + list[i].materiel + "'";

                sqlList.Add(sqlSafetyStock);
            }
            //sqlList.Add(sqlstock);
            sqlList.Add(sql);
            bool         result = h.ExcuteTransaction(sqlList);
            MessageModel msg;

            if (result)
            {
                msg = new MessageModel(0, "删除成功");
            }
            else
            {
                msg = new MessageModel(10005, "删除失败");
            }
            return(msg);
        }
예제 #2
0
        public MessageModel setList(GoDownEntryModel gm, List <ListModel> list)
        {
            string    sqlold = " SELECT em.id,em.quantity,em.batch,batch.combination,batch.supplier FROM entrymateriel em inner join batchmateriel batch on em.batch = batch.id  where entry = '" + gm.id + "'";
            DataTable dt     = h.ExecuteQuery(sqlold, CommandType.Text);
            Dictionary <int, ListModel> map = new Dictionary <int, ListModel>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var lm = new ListModel();
                lm.id       = Convert.ToInt32(dt.Rows[i]["id"]);
                lm.quantity = Convert.ToDouble(dt.Rows[i]["quantity"]);
                lm.batch    = Convert.ToInt32(dt.Rows[i]["batch"]);
                if (dt.Rows[i]["combination"] != DBNull.Value)
                {
                    lm.combination = Convert.ToInt32(dt.Rows[i]["combination"]);
                }
                lm.supplier = Convert.ToInt32(dt.Rows[i]["supplier"]);
                map.Add(lm.id, lm);
            }

            List <string> sqlList        = new List <string>();
            string        sql            = "";
            string        sqlstock       = "";
            string        sqlSafetyStock = "";

            for (int i = 0; i < list.Count; i++)
            {
                sql = "update entrymateriel set quantity = '" + list[i].quantity + "',price = '" + list[i].price + "'  ";
                if (list[i].conversion != null)
                {
                    sql += ",subquantity = '" + list[i].conversion * list[i].quantity + "'";
                }
                sql += " where id = '" + list[i].id + "'";
                var diff = list[i].quantity - map[list[i].id].quantity;
                if ((diff < 0 && gm.isDeficit) || (diff > 0 && !gm.isDeficit))
                {
                    diff = -diff;
                }
                sqlstock = "update stock set lastModifiedAt = NOW(),quantity = quantity + " + diff + ",avaquantity = avaquantity  +" + diff + " where uqkey = '" + map[list[i].id].supplier + "|" + list[i].materiel + "|" + gm.warehouse + "|";
                if (gm.position != null)
                {
                    sqlstock += "" + gm.position + "|";
                }
                else
                {
                    sqlstock += "|";
                }
                if (list[i].isBatch)
                {
                    sqlstock += "" + map[list[i].id].batch + "|";
                }
                else
                {
                    sqlstock += "|";
                }
                if (map[list[i].id].combination != null)
                {
                    sqlstock += "" + map[list[i].id].combination + "'";
                }
                else
                {
                    sqlstock += "'";
                }

                sqlList.Add(sql);
                sqlList.Add(sqlstock);

                sqlSafetyStock = "Update safetystock set stock = stock " + diff + " where materiel = '" + list[i].materiel + "'";

                sqlList.Add(sqlSafetyStock);
            }
            bool         result = h.ExcuteTransaction(sqlList);
            MessageModel msg    = new MessageModel();

            if (result == true)
            {
                msg = new MessageModel(0, "更新成功");
            }
            else
            {
                msg = new MessageModel(10005, "更新失败");
            }
            return(msg);
        }