//Convert DataTable To object method public jobstatusClass ConvertToOjbect(DataTable dt) { jobstatusClass obj_jobstatus = new jobstatusClass(); for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToString(dt.Rows[i]["Jobstatusid"]) != "") { obj_jobstatus.Jobstatusid = Convert.ToInt32(dt.Rows[i]["Jobstatusid"]); } else { obj_jobstatus.Jobstatusid = Convert.ToInt32("0"); } if (Convert.ToString(dt.Rows[i]["Statusname"]) != "") { obj_jobstatus.Statusname = Convert.ToString(dt.Rows[i]["Statusname"]); } else { obj_jobstatus.Statusname = Convert.ToString(""); } } return(obj_jobstatus); }
//Convert DataTable To List method public List <jobstatusClass> ConvertToList(DataTable dt) { List <jobstatusClass> jobstatuslist = new List <jobstatusClass>(); for (int i = 0; i < dt.Rows.Count; i++) { jobstatusClass obj_jobstatus = new jobstatusClass(); if (Convert.ToString(dt.Rows[i]["Jobstatusid"]) != "") { obj_jobstatus.Jobstatusid = Convert.ToInt32(dt.Rows[i]["Jobstatusid"]); } else { obj_jobstatus.Jobstatusid = Convert.ToInt32("0"); } if (Convert.ToString(dt.Rows[i]["Statusname"]) != "") { obj_jobstatus.Statusname = Convert.ToString(dt.Rows[i]["Statusname"]); } else { obj_jobstatus.Statusname = Convert.ToString(""); } jobstatuslist.Add(obj_jobstatus); } return(jobstatuslist); }
//create parameter public void createParameter(jobstatusClass obj, DB_con.DBTrans trans) { try { obj_con.clearParameter(); obj_con.addParameter("@Statusname", string.IsNullOrEmpty(Convert.ToString(obj.Statusname)) ? "" : obj.Statusname); obj_con.addParameter("@Jobstatusid", obj.Jobstatusid, trans); } catch (Exception ex) { throw ex; } }
//Select Constructor public jobstatusCtl(Int32 id) { obj_con = new ConnectionCls(); jobstatusClass obj_job = new jobstatusClass(); using (DataTable dt = selectdatatable(id)) { if (dt.Rows.Count > 0) { obj_job.Jobstatusid = Convert.ToInt32(dt.Rows[0]["Jobstatusid"]); obj_job.Statusname = Convert.ToString(dt.Rows[0]["Statusname"]); } } }
//insert data into database public Int32 insert(jobstatusClass obj) { try { obj_con.clearParameter(); createParameter(obj, DBTrans.Insert); obj_con.BeginTransaction(); obj_con.ExecuteNoneQuery("sp_jobstatus_insert", CommandType.StoredProcedure); obj_con.CommitTransaction(); return(obj.Jobstatusid = Convert.ToInt32(obj_con.getValue("@Jobstatusid"))); } catch (Exception ex) { obj_con.RollbackTransaction(); throw new Exception("sp_jobstatus_insert"); } }
//update edited object public jobstatusClass updateObject(jobstatusClass obj) { try { jobstatusClass oldObj = selectById(obj.Jobstatusid); if (obj.Statusname == null || obj.Statusname.ToString().Trim() == "update") { obj.Statusname = oldObj.Statusname; } return(obj); } catch (Exception ex) { throw new Exception(ex.Message); } }