public int addProduct(Product product) { SSGetService getService = new SSGetService(); SSUpdateService updateService = new SSUpdateService(); Product existingProduct = getService.getProductByName(product.name); if (existingProduct.name == null) { using (SqlCommand command = new SqlCommand("INSERT INTO ss_products(name,price,reorder_level,barqr_code)VALUES(@name,@price,@reorder_level,@barqr_code)")) { command.Parameters.AddWithValue("@name", product.name); command.Parameters.AddWithValue("@price", product.price); command.Parameters.AddWithValue("@reorder_level", product.reorder_level); command.Parameters.AddWithValue("@barqr_code", product.barqr_code); int response = service.execute(command); if (response > 0) { this.addLog(new Log() { type = "Add Product", statement = command.CommandText, description = "Added new Product" + product.name, }); } return(response); } } else { return(-2); } }
public int updatePrice(Product product) { SSGetService getService = new SSGetService(); SSAddService addService = new SSAddService(); Product existingProduct = getService.getProductByName(product.name); if (existingProduct.name != null) { using (SqlCommand command = new SqlCommand("UPDATE ss_products SET price=@price WHERE id=" + existingProduct.id + "")) { command.Parameters.AddWithValue("@price", product.price); int response = service.execute(command); if (response > 0) { addService.addLog(new Log() { type = "Updated Price", statement = command.CommandText, description = "Updated [" + existingProduct.id + "] Product", }); } return(response); } } else { return(-404); } }
public int addStock(Stock stock) { SSGetService getService = new SSGetService(); SSUpdateService updateService = new SSUpdateService(); Product existingProduct = getService.getProductByName(stock.name); if (existingProduct.name != null) { Location existingLocation = getService.getLocationByName(stock.location); if (existingLocation.name != null) { string batchName; string batchFormat = DateTime.Now.ToString("MMyyyy"); DataTable batchData = getService.getDataWithFilter(app.objects["batches"], " name like '%" + batchFormat + "' order by created_date desc"); if (batchData.Rows.Count > 0) { DataRow row = batchData.Rows[0]; string name = row.Field <string>("name"); string val = name.Substring(name.IndexOf('B') + 1, name.IndexOf('-') - 1); if (app.isAllDigits(val)) { batchName = "B" + (int.Parse(val) + 1) + "-" + batchFormat; } else { batchName = ""; } } else { batchName = "B1-" + batchFormat; } string batchKey = app.generateId(20); if (batchName != null && batchName != "") { using (SqlCommand batchCommand = new SqlCommand("INSERT INTO ss_batches(name,reference_key,pid,total,balance,sold)VALUES(@name,@reference_key,@pid,@total,@balance,@sold)")) { batchCommand.Parameters.AddWithValue("@name", batchName); batchCommand.Parameters.AddWithValue("@reference_key", batchKey); batchCommand.Parameters.AddWithValue("@pid", existingProduct.id); batchCommand.Parameters.AddWithValue("@total", stock.quantity); batchCommand.Parameters.AddWithValue("@balance", stock.quantity); batchCommand.Parameters.AddWithValue("@sold", 0); int batchResponse = service.execute(batchCommand); if (batchResponse > 0) { Batch batch = getService.getBatchByKey(batchKey); if (batch.key != null) { using (SqlCommand command = new SqlCommand("INSERT INTO ss_stocks(pid,bid,quantity,cost,description,last_modified_date)VALUES(@pid,@bid,@quantity,@cost,@description, getdate())")) { command.Parameters.AddWithValue("@pid", existingProduct.id); command.Parameters.AddWithValue("@bid", batch.id); command.Parameters.AddWithValue("@quantity", stock.quantity); command.Parameters.AddWithValue("@cost", stock.cost); command.Parameters.AddWithValue("@description", stock.description); int response = service.execute(command); if (response > 0) { return(response); } else { return(-1); } } } else { return(-1); } } else { return(-402); } } } else { return(-500); } } else { return(-404); } } else { return(-403); } }