Ejemplo n.º 1
0
        public bool Add(Inventory inventory, DbTransaction transaction)
        {
            IFPObjectDAO fpObjectDAO = DAOFactory.getInstance().createFPObjectDAO();
            fpObjectDAO.add(inventory, transaction);

            SqlTransaction trans = (SqlTransaction)transaction;
            String sql = "insert into inventory(ObjectId, orderno, assetno,category,receiveddate,receivedby,orderdeadline,remark,contactperson,tel,productno,productnameen,productnamecn,description,dimension,unit,unitcost,quantity,stored,status) values " +
                "(@ObjectId, @orderno,@assetno,@category,@receiveddate,@receivedby,@orderdeadline,@remark,@contactperson,@tel,@productno,@productnameen,@productnamecn,@description,@dimension,@unit,@unitcost,@quantity,@stored,@status)";
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = sql;
            cmd.Transaction = trans;
            cmd.Connection = trans.Connection;

            int? reid = null;

            if (inventory.receivedby != null)
                reid = inventory.receivedby.objectId;

            cmd.Parameters.Add(genSqlParameter("ObjectId", SqlDbType.Int, 10, inventory.objectId));
            cmd.Parameters.Add(genSqlParameter("orderno", SqlDbType.NVarChar, 50, inventory.orderno));
            cmd.Parameters.Add(genSqlParameter("assetno", SqlDbType.NVarChar, 50, inventory.assetno));
            cmd.Parameters.Add(genSqlParameter("category", SqlDbType.VarChar, 50, inventory.category));
            cmd.Parameters.Add(genSqlParameter("receiveddate", SqlDbType.DateTime, 50, inventory.receiveddate));
            cmd.Parameters.Add(genSqlParameter("receivedby", SqlDbType.Int, 10, reid));
            cmd.Parameters.Add(genSqlParameter("orderdeadline", SqlDbType.VarChar, 50, inventory.orderdeadline));
            cmd.Parameters.Add(genSqlParameter("remark", SqlDbType.NVarChar, 255, inventory.remark));
            cmd.Parameters.Add(genSqlParameter("contactperson", SqlDbType.NVarChar, 50, inventory.contactperson));
            cmd.Parameters.Add(genSqlParameter("tel", SqlDbType.NVarChar, 50, inventory.Tel));
            cmd.Parameters.Add(genSqlParameter("productno", SqlDbType.NVarChar, 50, inventory.productno));
            cmd.Parameters.Add(genSqlParameter("productnameen", SqlDbType.NVarChar, 50, inventory.productnameen));
            cmd.Parameters.Add(genSqlParameter("productnamecn", SqlDbType.NVarChar, 10, inventory.productnamecn));
            cmd.Parameters.Add(genSqlParameter("description", SqlDbType.NVarChar, 255, inventory.description));
            cmd.Parameters.Add(genSqlParameter("dimension", SqlDbType.NVarChar, 50, inventory.dimension));
            cmd.Parameters.Add(genSqlParameter("unit", SqlDbType.NVarChar, 50, inventory.unit));
            cmd.Parameters.Add(genSqlParameter("unitcost", SqlDbType.NVarChar, 50, inventory.unitcost));
            cmd.Parameters.Add(genSqlParameter("quantity", SqlDbType.NVarChar, 50, inventory.quantity));
            cmd.Parameters.Add(genSqlParameter("stored", SqlDbType.NVarChar, 50, inventory.stored));

            cmd.Parameters.Add(genSqlParameter("status", SqlDbType.NVarChar, 50, inventory.status));
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            return true;
        }
Ejemplo n.º 2
0
       public object add(string cid, string category, string productno, string productnameen, string productnamecn,
                                string dimension, string unit, string unitcost, string receivedby, string deadline, string receiveddate,
                                string person, string tel, string remark,string description,string quantity)
       {
           int objectid = 0;
           int uid =0;
           int.TryParse(cid, out objectid);
           int.TryParse (receivedby ,out uid );
           string result = "";
           DateTime orderdeadline = DateTime.Now;
           if(!string.IsNullOrEmpty (deadline))
           DateTime.TryParse(deadline, out orderdeadline);

           DateTime rd=DateTime.Now ;
           if(!string.IsNullOrEmpty (receiveddate ))
           DateTime .TryParse (receiveddate ,out rd);

       

           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");

               Inventory inventory = objectService.getInventoryById(objectid, user);
               UserAC ru = objectService.getUserByID(uid, user);

  //             var inventories = objectService.getInventories(" and productno='" + productno + "' and inventory.objectid <> '" + objectid + "'", 100, 0, // null, false, user);

//               if (inventories.Count() > 0)
//                   throw new Exception("Product No. Exist !");
              

               if (inventory == null)
                   inventory = new Inventory();


               inventory.category = category;
               inventory.contactperson = person;
               inventory.description = description;
               inventory.dimension = dimension;
               inventory.orderdeadline = orderdeadline;
               inventory.productnamecn = productnamecn;
               inventory.productnameen = productnameen;
               inventory.productno = productno;
               inventory.receiveddate = rd;
               inventory.remark = remark;
               inventory.quantity = quantity;
               inventory.Tel = tel;
               inventory.unit = unit;
               inventory.unitcost = unitcost;
               if (ru != null)
                   inventory.receivedby = ru;

               if (objectid == 0)
               {
                   objectid = service.addInventory(inventory, user);
                   result = "Add Successfully!";
               }
               else
               {
                   service.updateInventory(inventory, user);
                   result = "Update Successfully !";
               }


               return Content("{success:true,result:\"" + result + "\",objectid:\"" + objectid.ToString() + "\"}");
           }
           catch (Exception ex)
           {
               return Content("{success:false,result:\"" + ex.Message.Replace("'", "\\\'").Replace("\r\n", "\\\r\\\n") + "\",objectid:\"--\"}");
           }
       }
Ejemplo n.º 3
0
        public bool deleteInventory(Inventory inventory, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                IInventoryDAO ccDao = DAOFactory.getInstance().createInventoryDAO();

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

                ccDao.delete(inventory, transaction);
                transaction.Commit();
                return true;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            } 
        }
Ejemplo n.º 4
0
        public int addInventory(Inventory inventory, UserAC user)
        {
            IDatabase db = DAOFactory.getInstance().getDatabase();
            DbConnection conn = db.getConnection();
            DbTransaction transaction = db.beginTransaction(conn);
            try
            {
                IInventoryDAO inventoryDao = DAOFactory.getInstance().createInventoryDAO();
                ISequenceDAO seqDAO = DAOFactory.getInstance().createSequenceDAO();
                inventory.objectId = seqDAO.getNextObjectId(transaction);
                inventory.assetno = "AAA" + inventory.objectId;
                inventory.updateBy = user.eng_name;
                inventory.createDate = DateTime.Now;
                inventory.updateDate = DateTime.Now;
                inventory.isDeleted = false;

                inventoryDao.Add(inventory, transaction);
                transaction.Commit();
                return inventory.objectId;
            }
            catch (Exception e)
            {
                transaction.Rollback();
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 5
0
        private List<Inventory> getQueryResult(SqlCommand cmd)
        {
            DbDataReader reader = cmd.ExecuteReader();
            DataTable dt = new DataTable();


            //  IPrintItemDAO printItemDAO = DAOFactory.getInstance().createPrintJobDAO();
            IUserDAO userDAO = DAOFactory.getInstance().createUserDAO();
            IConsumptionDAO  consumptionDAO = DAOFactory.getInstance().createConsumptionDAO();

            List<Inventory> inventories = new List<Inventory>();
            Inventory inventory = null;

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

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

                    inventory.objectId = getInt(dt.Rows[i]["ObjectId"]);
                    inventory.createDate = getDateTime(dt.Rows[i]["CreateDate"]);
                    inventory.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]);
                    inventory.updateBy = getString(dt.Rows[i]["UpdateBy"]);
                    inventory.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1);
                    inventory.assetno = getString(dt.Rows[i]["assetno"]);
                    inventory.category = getString(dt.Rows[i]["category"]);
                    inventory.contactperson = getString(dt.Rows[i]["contactperson"]);
                    inventory.description = getString(dt.Rows[i]["description"]);
                    inventory.dimension = getString(dt.Rows[i]["dimension"]);
                    inventory.orderdeadline = getDateTime(dt.Rows[i]["orderdeadline"]);
                    inventory.orderno = getString(dt.Rows[i]["orderno"]);
                    inventory.productnamecn = getString(dt.Rows[i]["productnamecn"]);
                    inventory.productnameen = getString(dt.Rows[i]["productnameen"]);
                    inventory.productno = getString(dt.Rows[i]["productno"]);
                    inventory.quantity = getString(dt.Rows[i]["quantity"]);
                    inventory.receivedby = userDAO.get(getInt(dt.Rows[i]["receivedby"]), cmd.Transaction);
                    inventory.receiveddate = getDateTime(dt.Rows[i]["receiveddate"]);
                    inventory.remark = getString(dt.Rows[i]["remark"]);
                    inventory.stored = consumptionDAO.cateStoredCount(getInt(dt.Rows[i]["ObjectId"]), cmd.Transaction).ToString();
                    inventory.Tel = getString(dt.Rows[i]["Tel"]);
                    inventory.unit = getString(dt.Rows[i]["unit"]);
                    inventory.unitcost = getString(dt.Rows[i]["unitcost"]);
                    inventory.status = getString(dt.Rows[i]["status"]);
               
                    inventories.Add(inventory);
                }
            }
            return inventories;
        }
Ejemplo n.º 6
0
        internal static string getInventoryJson(Inventory inventory)
        {
            StringBuilder deliveryJson = new StringBuilder();

            deliveryJson.Append("{").Append("objectid:'").Append(inventory.objectId.ToString()).Append("',")
                 .Append("category:'").Append(inventory.category == null ? string.Empty : inventory.category.Replace("'", "\\\'")).Append("',")
                  .Append("assetno:'").Append(inventory.assetno == null ? string.Empty : inventory.assetno.Replace("'", "\\\'")).Append("',")
                    .Append("productnameen:'").Append(inventory.productnameen == null ? string.Empty : inventory.productnameen.Replace("'", "\\\'")).Append("',")
                       .Append("productnamecn:'").Append(inventory.productnamecn == null ? string.Empty : inventory.productnamecn.Replace("'", "\\\'")).Append("',")
                      .Append("description:'").Append(inventory.description == null ? string.Empty : inventory.description.Replace("'", "\\\'").Replace ("\r","\\r").Replace ("\n","\\n")).Append("',")
                         .Append("quantity:'").Append(inventory.quantity == null ? string.Empty : inventory.quantity.Replace("'", "\\\'")).Append("',")
                            .Append("asat:'").Append(inventory.updateDate == null ? string.Empty : inventory.updateDate.Value.ToString("yyyy-MM-dd")).Append("',")
                             .Append("stored:'").Append(inventory.stored == null ? string.Empty : inventory.stored).Append("',")
  .Append("productno:'").Append(inventory.productno == null ? string.Empty : inventory.productno).Append("',")
   .Append("dimension:'").Append(inventory.dimension == null ? string.Empty : inventory.dimension).Append("',")
     .Append("unit:'").Append(inventory.unit == null ? string.Empty : inventory.unit).Append("',")
       .Append("unitcost:'").Append(inventory.unitcost == null ? string.Empty : inventory.unitcost).Append("',")
           .Append("receivedby:'").Append(inventory.receivedby == null ? string.Empty : inventory.receivedby.objectId.ToString()).Append("',")
            .Append("person:'").Append(inventory.contactperson == null ? string.Empty : inventory.contactperson.ToString()).Append("',")
             .Append("tel:'").Append(inventory.Tel == null ? string.Empty : inventory.Tel.ToString()).Append("',")
             .Append("deadline:'").Append(inventory.orderdeadline == null ? string.Empty : inventory.orderdeadline.Value.ToString("yyyy-MM-dd")).Append("',")
                          .Append("receiveddate:'").Append(inventory.receiveddate == null ? string.Empty : inventory.receiveddate.Value.ToString("yyyy-MM-dd")).Append("',")

            .Append("remark:'").Append(inventory.remark == null ? string.Empty : inventory.remark.ToString()).Append("'}");

            return deliveryJson.ToString();
        }