public bool update(AssetConsumption assetConsumption, DbTransaction transaction) { IFPObjectDAO objDAO = DAOFactory.getInstance().createFPObjectDAO(); objDAO.update(assetConsumption, transaction); SqlTransaction trans = (SqlTransaction)transaction; String sql = "update AssetConsumption set jobid = @jobid,qty = @qty, size = @size, unit = @unit, purpose = @purpose, cost = @cost, product = @product where ObjectId = @ObjectId"; SqlCommand cmd = new SqlCommand(); cmd.CommandText = sql; cmd.Transaction = trans; cmd.Connection = trans.Connection; cmd.Parameters.Add(genSqlParameter("ObjectId", SqlDbType.Int, 10, assetConsumption.objectId)); cmd.Parameters.Add(genSqlParameter("jobid", SqlDbType.NVarChar, 255, assetConsumption.jobid)); cmd.Parameters.Add(genSqlParameter("qty", SqlDbType.NVarChar, 255, assetConsumption.qty)); cmd.Parameters.Add(genSqlParameter("size", SqlDbType.NVarChar, 255, assetConsumption.size)); cmd.Parameters.Add(genSqlParameter("unit", SqlDbType.NVarChar, 255, assetConsumption.unit)); cmd.Parameters.Add(genSqlParameter("purpose", SqlDbType.Int, 10, assetConsumption.purpose)); cmd.Parameters.Add(genSqlParameter("cost", SqlDbType.NVarChar, 50, assetConsumption.cost)); if (assetConsumption.product != null) cmd.Parameters.Add(genSqlParameter("product", SqlDbType.Int, 10, assetConsumption.product.objectId)); else cmd.Parameters.Add(genSqlParameter("product", SqlDbType.Int, 10, null)); cmd.ExecuteNonQuery(); cmd.Dispose(); return true; }
public ActionResult addJobDetail() { String jobid = Request.Params["jobid"]; String pid = Request.Params["pid"]; String detailx = Request.Params["new-detail-x"]; String detaily = Request.Params["new-detail-y"]; String unit = Request.Params["new-detail-unit"]; String purpose = Request.Params["newjob-purpose"]; String detailz = Request.Params["new-detail-z"]; String sProduct = Request.Params["product"]; IFPService service = (IFPService)FPServiceHolder.getInstance().getService("fpService"); IFPObjectService objectService = (IFPObjectService)FPServiceHolder.getInstance().getService("fpObjectService"); UserAC user = (UserAC)Session["user"]; PrintItem job = objectService.getPrintJobByID(jobid,user); if (job == null) { return Content("{success:false, result:\"Item is not found.\"}"); } if(detailx == "" && detaily == "" && unit == "") return Content("{success:false, result:\"Please enter the job details.\"}"); AssetConsumption detail = new AssetConsumption(); try { detail.jobid = jobid; detail.purpose = int.Parse(purpose); detail.qty = detailz; detail.size = detailx + "x" + detaily; detail.unit = unit; if (unit == "MM") detail.qty = ""; else detail.size = ""; int iProdcut = int.Parse(sProduct); Inventory product = objectService.getInventoryById(iProdcut, user); detail.product = product; detail.createDate = DateTime.Now; detail.cost = "";//TODO bool success = service.addNewJobDetail(detail, user); if(success) return Content("{success:true, result:\"Update success\"}"); else return Content("{success:false, result:\"Update Failed\"}"); } catch (Exception e) { return Content("{success:false, result:\"" + "Add job failed. ex=" + e.Message + "\"}"); } }
public bool deleteJobDetail(AssetConsumption detail, UserAC user) { IDatabase db = DAOFactory.getInstance().getDatabase(); DbConnection conn = db.getConnection(); DbTransaction transaction = db.beginTransaction(conn); try { IAssetConsumptionDAO detailDAO = DAOFactory.getInstance().createPrintJobDetailDAO(); detail.updateBy = user.eng_name; detailDAO.delete(detail, transaction); transaction.Commit(); return true; } catch (Exception e) { transaction.Rollback(); throw e; } finally { conn.Close(); } }
public bool delete(AssetConsumption assetConsumption, DbTransaction transaction) { IFPObjectDAO objDAO = DAOFactory.getInstance().createFPObjectDAO(); objDAO.delete(assetConsumption, transaction); return true; }
private List<AssetConsumption> getQueryResult(SqlCommand cmd) { DbDataReader reader = cmd.ExecuteReader(); DataTable dt = new DataTable(); List<AssetConsumption> assetConsumptions = new List<AssetConsumption>(); AssetConsumption assetConsumption = null; IInventoryDAO inventoryDAO = DAOFactory.getInstance().createInventoryDAO(); dt.Load(reader); reader.Close(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { assetConsumption = new AssetConsumption(); assetConsumption.objectId = getInt(dt.Rows[i]["ObjectId"]); assetConsumption.createDate = getDateTime(dt.Rows[i]["CreateDate"]); assetConsumption.updateDate = getDateTime(dt.Rows[i]["UpdateDate"]); assetConsumption.updateBy = getString(dt.Rows[i]["UpdateBy"]); assetConsumption.isDeleted = (getInt(dt.Rows[i]["IsDeleted"]) == 1); assetConsumption.jobid = getString(dt.Rows[i]["jobid"]); assetConsumption.qty = getString(dt.Rows[i]["qty"]); assetConsumption.size = getString(dt.Rows[i]["size"]); assetConsumption.unit = getString(dt.Rows[i]["unit"]); assetConsumption.purpose = getInt(dt.Rows[i]["purpose"]); assetConsumption.cost = getString(dt.Rows[i]["cost"]); assetConsumption.product = inventoryDAO.Get(getInt(dt.Rows[i]["product"]),cmd.Transaction); assetConsumptions.Add(assetConsumption); } } return assetConsumptions; }