Exemplo n.º 1
0
        private List<Consumption> getQueryResult(SqlCommand cmd)
        {
            DbDataReader reader = cmd.ExecuteReader();
            DataTable dt = new DataTable();


            //  IPrintItemDAO printItemDAO = DAOFactory.getInstance().createPrintJobDAO();
            IUserDAO userDAO = DAOFactory.getInstance().createUserDAO();
            IInventoryDAO inventoryDAO = DAOFactory.getInstance().createInventoryDAO();

            List<Consumption> consumptions = new List<Consumption>();
            Consumption consumption = null;

            dt.Load(reader);
            reader.Close();

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    consumption = new Consumption();

                    consumption.objectId = getInt(dt.Rows[i]["ObjectId"]);
                    consumption.createDate = getDateTime(dt.Rows[i]["CreateDate"]);
                    consumption.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]);
                    consumption.updateBy = getString(dt.Rows[i]["UpdateBy"]);
                    consumption.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1);
                    consumption.inventory = inventoryDAO.Get(getInt(dt.Rows[i]["inventoryid"]), cmd.Transaction);
                    consumption.store = getString(dt.Rows[i]["store"]);
                    consumption.storeunit = getString(dt.Rows[i]["storeunit"]);
                    consumption.total = getString(dt.Rows[i]["total"]);
                    consumption.totalunit = getString(dt.Rows[i]["totalunit"]);
                    consumption.used = getString(dt.Rows[i]["used"]);
                    consumption.usedunit = getString(dt.Rows[i]["usedunit"]);
                    consumption.asdate = getDateTime(dt.Rows[i]["asdate"]);

                    consumption.subtotal = getDecimal(dt.Rows[i]["subtotal"]);
                    consumption.subused = getDecimal(dt.Rows[i]["subused"]);
                    consumption.substore = getDecimal(dt.Rows[i]["substore"]);

                    consumptions.Add(consumption);
                }
            }

            return consumptions;
        }
Exemplo n.º 2
0
       public object addconsumption(string objectid, string inventoryid, string total, string totalunit, string store, string storeunit, string used, string usedunit, string asdate)
       {
           int conid = 0;
           int iid = 0;

           DateTime date = DateTime.Now;
           DateTime.TryParse(asdate, out date);

           int.TryParse(objectid, out conid);
           int.TryParse(inventoryid, out iid);

           string result = string.Empty;

           try
           {
               UserAC user = (UserAC)Session["user"];
               String pwd = Request.Params["pwd"];
               IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService");
               IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService");

               Consumption consumption = objectService.getconsumption(conid, user);
               Inventory inventory = objectService.getInventoryById(iid, user);

               if (inventory == null)
                   throw new Exception("This inventory is not exist !");

               if (consumption == null)
                   consumption = new Consumption();

               consumption.asdate = date;
               consumption.total = total;
               consumption.totalunit = totalunit;
               consumption.store = store;
               consumption.storeunit = storeunit;
               consumption.used = used;
               consumption.usedunit = usedunit;
               consumption.inventory = inventory;

               if (conid == 0)
               {
                   service.addConsumption(consumption, user);
                   result = "Add Successfully!";
               }
               else
               {
                   service.updateConsumption(consumption, user);
                   result = "Update Successfully !";
               }


               return Content("{success:true,result:\"" + result + "\",objectid:\"" + objectid.ToString() + "\"}");
           }
           catch (Exception ex)
           {
               return Content("{success:false,result:\"" + ex.Message + "\",objectid:\"--\"}");
           }
       }
Exemplo n.º 3
0
        public bool addConsumption(Consumption consumption, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                IConsumptionDAO inventoryDao = DAOFactory.getInstance().createConsumptionDAO();
                ISequenceDAO seqDAO = DAOFactory.getInstance().createSequenceDAO();
                consumption.objectId = seqDAO.getNextObjectId(transaction);
                consumption.updateBy = user.eng_name;
                consumption.createDate = DateTime.Now;
                consumption.updateDate = DateTime.Now;
                consumption.isDeleted = false;

                inventoryDao.add(consumption, transaction);
                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 4
0
        public bool deleteConsumption(Consumption consumption, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                IConsumptionDAO ccDao = DAOFactory.getInstance().createConsumptionDAO();

                consumption.updateBy = user.eng_name;
                consumption.updateDate = DateTime.Now;
                consumption.isDeleted = false;

                ccDao.delete(consumption, transaction);
                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Exemplo n.º 5
0
        internal static string getConsumptionJson(Consumption consumption)
        {
            StringBuilder consumptionJson = new StringBuilder();

            consumptionJson.Append("{").Append("conid:'").Append(consumption.objectId.ToString()).Append("',")
               .Append("total:'").Append(consumption.total.ToString ()).Append("',")
               .Append("store:'").Append(consumption.store.ToString ()).Append("',")
                .Append("totalunit:'").Append(consumption.totalunit.ToString ()).Append("',")
                 .Append("storeunit:'").Append(consumption.storeunit.ToString ()).Append("',")
                  .Append("usedunit:'").Append(consumption.usedunit.ToString ()).Append("',")
                   .Append("asdate:'").Append(consumption.asdate.Value.ToString ("MM/dd/yyyy")).Append("',")
               .Append("used:'").Append(consumption.used.ToString ()).Append("'}");

            return consumptionJson.ToString();
        }