Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Diagnostics;
- using System.IO;
- using System.Drawing;
- using static Enums;
- using System.Text;
- namespace MaterialSolutions.Models
- {
- public class Forklift
- {
- public int ForkliftID { get; set; }
- [Required(ErrorMessage = "Serial number is required.")]
- [Display(Name = "Serial")]
- public string SerialNumber { get; set; }
- [Required(ErrorMessage = "Model number is required.")]
- [Display(Name = "Model")]
- public string ModelNumber { get; set; }
- [Required(ErrorMessage = "Manufacturer is required.")]
- [Display(Name = "ManufacturerID")]
- public int ManufacturerID { get; set; }
- [Required(ErrorMessage = "Power type is required.")]
- [Display(Name = "Power")]
- public Power Power { get; set; }
- [Required(ErrorMessage = "Capacity is required.")]
- [Display(Name = "Capacity")]
- public int Capacity { get; set; }
- [Display(Name = "Year")]
- public int Year { get; set; }
- [Display(Name = "Lowered")]
- public int LoweredHeight { get; set; }
- [Required(ErrorMessage = "Raised height is required.")]
- [Display(Name = "Raised")]
- public int RaisedHeight { get; set; }
- [Display(Name = "Purchased")]
- public decimal PurchasedPrice { get; set; }
- [Display(Name = "Wholesale")]
- public decimal WholesalePrice { get; set; }
- [Display(Name = "Retail")]
- public decimal RetailPrice { get; set; }
- [Display(Name = "Comments")]
- public string Comments { get; set; }
- [Required(ErrorMessage = "Location is required.")]
- [Display(Name = "LocationID")]
- public int LocationID { get; set; }
- [Display(Name = "Created")]
- public DateTime Created { get; set; }
- [Display(Name = "Updated")]
- public DateTime Updated { get; set; }
- //Object properties.
- [Display(Name = "Manufacturer")]
- public Manufacturer Manufacturer { get; set; }
- [Display(Name = "Location")]
- public Client Location { get; set; }
- public static Forklift Setup(DataRow dr)
- {
- return new Forklift
- {
- ForkliftID = Convert.ToInt32(dr["ForkliftID"]),
- SerialNumber = dr["SerialNumber"].ToString(),
- ModelNumber = dr["ModelNumber"].ToString(),
- ManufacturerID = Convert.ToInt32(dr["ManufacturerID"]),
- Power = (Power)Convert.ToInt32(dr["PowerID"]),
- Capacity = Convert.ToInt32(dr["Capacity"]),
- Year = Convert.ToInt32(dr["Year"]),
- LoweredHeight = Convert.ToInt32(dr["LoweredHeight"]),
- RaisedHeight = Convert.ToInt32(dr["RaisedHeight"]),
- PurchasedPrice = Convert.ToDecimal(dr["PurchasedPrice"]),
- WholesalePrice = Convert.ToDecimal(dr["WholesalePrice"]),
- RetailPrice = Convert.ToDecimal(dr["RetailPrice"]),
- Comments = dr["Comments"].ToString(),
- LocationID = Convert.ToInt32(dr["LocationID"]),
- Created = Convert.ToDateTime(dr["Created"]),
- Updated = Convert.ToDateTime(dr["Updated"]),
- Manufacturer = Manufacturer.GetForkliftManufacturerByID(Convert.ToInt32(dr["ManufacturerID"])),
- Location = Client.GetClientByID(Convert.ToInt32(dr["LocationID"]))
- };
- }
- public Forklift()
- {
- //Null constructor for internal class use only.
- }
- public Forklift(int id)
- {
- GetForkliftByID(id);
- }
- public static bool RemoveForkliftByID(int id)
- {
- try
- {
- DBConnection.InitConnection();
- DBConnection.DBContext.SetSqlString("Inventory..RemoveForkliftByID", CommandType.StoredProcedure);
- DBConnection.DBContext.AddParameter("@ForkliftID", id, SqlDbType.Int);
- DBConnection.DBContext.GetResultSet();
- return true;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- return false;
- }
- }
- public static Forklift UpdateForklift(Forklift forklift)
- {
- try
- {
- DBConnection.InitConnection();
- DBConnection.DBContext.SetSqlString("Inventory..UpdateForklift", CommandType.StoredProcedure);
- DBConnection.DBContext.AddParameter("@ForkliftID", forklift.ForkliftID, SqlDbType.Int);
- DBConnection.DBContext.AddParameter("@SerialNumber", forklift.SerialNumber, SqlDbType.VarChar);
- DBConnection.DBContext.AddParameter("@ModelNumber", forklift.ModelNumber, SqlDbType.VarChar);
- DBConnection.DBContext.AddParameter("@ManufacturerID", forklift.ManufacturerID, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@PowerID", forklift.Power, SqlDbType.Int);
- DBConnection.DBContext.AddParameter("@Capacity", forklift.Capacity, SqlDbType.Int);
- DBConnection.DBContext.AddParameter("@Year", forklift.Year, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@LoweredHeight", forklift.LoweredHeight, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@RaisedHeight", forklift.RaisedHeight, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@PurchasedPrice", forklift.PurchasedPrice, SqlDbType.Decimal);
- DBConnection.DBContext.AddParameter("@WholesalePrice", forklift.WholesalePrice, SqlDbType.Decimal);
- DBConnection.DBContext.AddParameter("@RetailPrice", forklift.RetailPrice, SqlDbType.Decimal);
- DBConnection.DBContext.AddParameter("@Comments", forklift.Comments, SqlDbType.VarChar);
- DBConnection.DBContext.AddParameter("@LocationID", forklift.LocationID, SqlDbType.Int);
- DataSet resultSet = DBConnection.DBContext.GetResultSet();
- if (resultSet != null)
- {
- DataTable resultTable = resultSet.Tables[0];
- if (resultTable.Rows.Count > 0)
- {
- foreach (DataRow dr in resultTable.Rows)
- {
- return Setup(dr);
- }
- }
- }
- return null;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.ToString());
- return null;
- }
- }
- public static Forklift GetForkliftByID(int id)
- {
- try
- {
- DBConnection.InitConnection();
- DBConnection.DBContext.SetSqlString("Inventory..GetForkliftByID", CommandType.StoredProcedure);
- DBConnection.DBContext.AddParameter("@ForkliftID", id, SqlDbType.Int);
- DataSet resultSet = DBConnection.DBContext.GetResultSet();
- if (resultSet != null)
- {
- DataTable resultTable = resultSet.Tables[0];
- if (resultTable.Rows.Count > 0)
- {
- foreach (DataRow dr in resultTable.Rows)
- {
- return Setup(dr);
- }
- }
- }
- return null;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.ToString());
- return null;
- }
- }
- public static Forklift InsertForklift(Forklift forklift)
- {
- try
- {
- DBConnection.InitConnection();
- DBConnection.DBContext.SetSqlString("Inventory..InsertForklift", CommandType.StoredProcedure);
- DBConnection.DBContext.AddParameter("@SerialNumber", forklift.SerialNumber, SqlDbType.VarChar);
- DBConnection.DBContext.AddParameter("@ModelNumber", forklift.ModelNumber, SqlDbType.VarChar);
- DBConnection.DBContext.AddParameter("@ManufacturerID", forklift.ManufacturerID, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@PowerID", forklift.Power, SqlDbType.Int);
- DBConnection.DBContext.AddParameter("@Capacity", forklift.Capacity, SqlDbType.Int);
- DBConnection.DBContext.AddParameter("@Year", forklift.Year, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@LoweredHeight", forklift.LoweredHeight, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@RaisedHeight", forklift.RaisedHeight, SqlDbType.SmallInt);
- DBConnection.DBContext.AddParameter("@PurchasedPrice", forklift.PurchasedPrice, SqlDbType.Decimal);
- DBConnection.DBContext.AddParameter("@WholesalePrice", forklift.WholesalePrice, SqlDbType.Decimal);
- DBConnection.DBContext.AddParameter("@RetailPrice", forklift.RetailPrice, SqlDbType.Decimal);
- DBConnection.DBContext.AddParameter("@Comments", forklift.Comments, SqlDbType.VarChar);
- DBConnection.DBContext.AddParameter("@LocationID", forklift.LocationID, SqlDbType.Int);
- DataSet resultSet = DBConnection.DBContext.GetResultSet();
- if (resultSet != null)
- {
- DataTable resultTable = resultSet.Tables[0];
- if (resultTable.Rows.Count > 0)
- {
- foreach (DataRow dr in resultTable.Rows)
- {
- return Setup(dr);
- }
- }
- }
- return null;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.ToString());
- return null;
- }
- }
- public static HashSet<Forklift> GetForkliftStockInventory()
- {
- try
- {
- DBConnection.InitConnection();
- DBConnection.DBContext.SetSqlString("Inventory..GetForkliftStock", CommandType.StoredProcedure);
- DataSet resultSet = DBConnection.DBContext.GetResultSet();
- HashSet<Forklift> forkliftStockInventory = new HashSet<Forklift>();
- if (resultSet != null)
- {
- DataTable resultTable = resultSet.Tables[0];
- foreach (DataRow dr in resultTable.Rows)
- {
- forkliftStockInventory.Add(Setup(dr));
- }
- }
- return forkliftStockInventory;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.ToString());
- return null;
- }
- }
- public static Image GetForkliftPicture(int id)
- {
- try
- {
- DBConnection.InitConnection();
- DBConnection.DBContext.SetSqlString("Inventory..GetForkliftPicture", CommandType.StoredProcedure);
- DBConnection.DBContext.AddParameter("@ForkliftID", id, SqlDbType.Int);
- DataSet resultSet = DBConnection.DBContext.GetResultSet();
- if (resultSet != null)
- {
- DataTable resultTable = resultSet.Tables[0];
- if (resultTable.Rows.Count > 0)
- {
- foreach (DataRow dr in resultTable.Rows)
- {
- using (MemoryStream ms = new MemoryStream((byte[])dr["Image"]))
- {
- return Image.FromStream(ms);
- }
- }
- }
- }
- return null;
- }
- catch (Exception ex)
- {
- Debug.WriteLine(ex.ToString());
- return null;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement