public List<Transit> GetAllTransit() { //...Create New Instance of Object... List<Transit> list = new List<Transit>(); Transit ins; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("select t.*, tt.TransitType from t_Transit t inner join l_TransitType tt on t.TransitTypeID = tt.TransitTypeID where t.Removed = 0", con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins = new Transit(); ins.TransitID = Convert.ToInt32(drI["TransitID"]); ins.ActualDate = Convert.ToDateTime(drI["ActualDate"]); ins.Amount = Convert.ToDecimal(drI["Amount"]); ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]); ins.CompanyID = Convert.ToInt32(drI["CompanyID"]); ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]); ins.ModifiedBy = Convert.ToString(drI["ModifiedBy"]); ins.Removed = Convert.ToBoolean(drI["Removed"]); ins.TransitTypeID = Convert.ToInt32(drI["TransitTypeID"]); ins.transittype = drI["TransitType"].ToString(); list.Add(ins); } } //...Close Connections... drI.Close(); con.Close(); //...Return... return list; }
public Transit GetTransit(int TransitID) { //...Create New Instance of Object... Transit ins = new Transit(); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); SqlCommand cmdI; //...SQL Commands... cmdI = new SqlCommand("SELECT * FROM l_Transit WHERE TransitID =" + TransitID, con); cmdI.Connection.Open(); SqlDataReader drI = cmdI.ExecuteReader(); //...Retrieve Data... if (drI.HasRows) { while (drI.Read()) { ins.TransitID = Convert.ToInt32(drI["TransitID"]); ins.ActualDate = Convert.ToDateTime(drI["ActualDate"]); ins.Amount = Convert.ToDecimal(drI["Amount"]); ins.CreatedDate = Convert.ToDateTime(drI["CreatedDate"]); ins.CompanyID = Convert.ToInt32(drI["CompanyID"]); ins.ModifiedDate = Convert.ToDateTime(drI["ModifiedDate"]); ins.ModifiedBy = Convert.ToString(drI["ModifiedBy"]); ins.Removed = Convert.ToBoolean(drI["Removed"]); } } //...Close Connections... drI.Close(); con.Close(); //...Return... return ins; }
public Transit Insert(Transit ins) { //...Get User and Date Data... string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now); string EmployeeId = Convert.ToString(HttpContext.Current.Session["Username"]); string strTrx = "TransitIns_" + EmployeeId; //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); //...Command Interface... SqlCommand cmdI = con.CreateCommand(); SqlTransaction trx; trx = con.BeginTransaction(strTrx); cmdI.Connection = con; cmdI.Transaction = trx; try { //...Insert Record... cmdI.CommandText = StoredProcedures.TransitInsert; cmdI.CommandType = System.Data.CommandType.StoredProcedure; //cmdI.Parameters.AddWithValue("@TransitID", ins.TransitID); cmdI.Parameters.AddWithValue("@ActualDate", ins.ActualDate); cmdI.Parameters.AddWithValue("@Amount", ins.Amount); cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now); cmdI.Parameters.AddWithValue("@CompanyID", ins.CompanyID); cmdI.Parameters.AddWithValue("@ModifiedDate",ModifiedDate); cmdI.Parameters.AddWithValue("@ModifiedBy",EmployeeId); cmdI.Parameters.AddWithValue("@Removed", 0); cmdI.Parameters.AddWithValue("@TransitTypeID", ins.TransitTypeID); //...Return new ID ins.TransitID = (int)cmdI.ExecuteScalar(); trx.Commit(); cmdI.Connection.Close(); } catch (SqlException ex) { if (trx != null) trx.Rollback(); } finally { //Check for close and respond accordingly if (con.State != ConnectionState.Closed) { con.Close(); } //Clean up con.Dispose(); cmdI.Dispose(); trx.Dispose(); } return ins; }
public Transit Update(Transit ins) { //...Get User and Date Data... string ModifiedDate = string.Format("{0:yyyy-MM-dd hh:mm:ss}", DateTime.Now); string EmployeeId = Convert.ToString(HttpContext.Current.Session["Username"]); //...Database Connection... DataBaseConnection dbConn = new DataBaseConnection(); SqlConnection con = dbConn.SqlConn(); con.Open(); SqlCommand cmdI = con.CreateCommand(); cmdI.Connection = con; //...Update Record... cmdI.Parameters.Clear(); cmdI.CommandText = StoredProcedures.TransitUpdate; cmdI.CommandType = System.Data.CommandType.StoredProcedure; cmdI.Parameters.AddWithValue("@TransitID", ins.TransitID); cmdI.Parameters.AddWithValue("@ActualDate", ins.ActualDate); cmdI.Parameters.AddWithValue("@Amount", ins.Amount); cmdI.Parameters.AddWithValue("@CreatedDate", DateTime.Now); cmdI.Parameters.AddWithValue("@CompanyID", ins.CompanyID); cmdI.Parameters.AddWithValue("@ModifiedDate",ModifiedDate); cmdI.Parameters.AddWithValue("@ModifiedBy",EmployeeId); cmdI.Parameters.AddWithValue("@TransitTypeID", ins.TransitTypeID); cmdI.ExecuteNonQuery(); cmdI.Connection.Close(); return ins; }
public JsonResult _UpdateTransit(Transit ins) { Transit ins2 = TransRep.Update(ins); //...Repopulate Grid... return Json(new GridModel(TransRep.GetAllTransit())); }