//Convert DataTable To object method
        public servicecontractClass ConvertToOjbect(DataTable dt)
        {
            servicecontractClass obj_servicecontract = new servicecontractClass();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToString(dt.Rows[i]["Servicecontractid"]) != "")
                {
                    obj_servicecontract.Servicecontractid = Convert.ToInt32(dt.Rows[i]["Servicecontractid"]);
                }
                else
                {
                    obj_servicecontract.Servicecontractid = Convert.ToInt32("0");
                }

                if (Convert.ToString(dt.Rows[i]["Projectid"]) != "")
                {
                    obj_servicecontract.Projectid = Convert.ToInt32(dt.Rows[i]["Projectid"]);
                }
                else
                {
                    obj_servicecontract.Projectid = Convert.ToInt32("0");
                }

                if (Convert.ToString(dt.Rows[i]["Servicecontractname"]) != "")
                {
                    obj_servicecontract.Servicecontractname = Convert.ToString(dt.Rows[i]["Servicecontractname"]);
                }
                else
                {
                    obj_servicecontract.Servicecontractname = Convert.ToString("");
                }
            }
            return(obj_servicecontract);
        }
//create parameter
        public void createParameter(servicecontractClass obj, DB_con.DBTrans trans)
        {
            try
            {
                obj_con.clearParameter();
                obj_con.addParameter("@Projectid", string.IsNullOrEmpty(Convert.ToString(obj.Projectid)) ? 0 : obj.Projectid);
                obj_con.addParameter("@Servicecontractname", string.IsNullOrEmpty(Convert.ToString(obj.Servicecontractname)) ? "" : obj.Servicecontractname);
                obj_con.addParameter("@Servicecontractid", obj.Servicecontractid, trans);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
//Select Constructor
        public servicecontractCtl(Int32 id)
        {
            obj_con = new ConnectionCls();
            servicecontractClass obj_ser = new servicecontractClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_ser.Servicecontractid   = Convert.ToInt32(dt.Rows[0]["Servicecontractid"]);
                    obj_ser.Projectid           = Convert.ToInt32(dt.Rows[0]["Projectid"]);
                    obj_ser.Servicecontractname = Convert.ToString(dt.Rows[0]["Servicecontractname"]);
                }
            }
        }
 //insert data into database
 public Int32 insert(servicecontractClass obj)
 {
     try
     {
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Insert);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_servicecontract_insert", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Servicecontractid = Convert.ToInt32(obj_con.getValue("@Servicecontractid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_servicecontract_insert");
     }
 }
//Convert DataTable To List method
        public List <servicecontractClass> ConvertToList(DataTable dt)
        {
            List <servicecontractClass> servicecontractlist = new List <servicecontractClass>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                servicecontractClass obj_servicecontract = new servicecontractClass();

                if (Convert.ToString(dt.Rows[i]["Servicecontractid"]) != "")
                {
                    obj_servicecontract.Servicecontractid = Convert.ToInt32(dt.Rows[i]["Servicecontractid"]);
                }
                else
                {
                    obj_servicecontract.Servicecontractid = Convert.ToInt32("0");
                }

                if (Convert.ToString(dt.Rows[i]["Projectid"]) != "")
                {
                    obj_servicecontract.Projectid = Convert.ToInt32(dt.Rows[i]["Projectid"]);
                }
                else
                {
                    obj_servicecontract.Projectid = Convert.ToInt32("0");
                }

                if (Convert.ToString(dt.Rows[i]["Servicecontractname"]) != "")
                {
                    obj_servicecontract.Servicecontractname = Convert.ToString(dt.Rows[i]["Servicecontractname"]);
                }
                else
                {
                    obj_servicecontract.Servicecontractname = Convert.ToString("");
                }


                servicecontractlist.Add(obj_servicecontract);
            }
            return(servicecontractlist);
        }
//update edited object
        public servicecontractClass updateObject(servicecontractClass obj)
        {
            try
            {
                servicecontractClass oldObj = selectById(obj.Servicecontractid);
                if (obj.Projectid == null || obj.Projectid.ToString().Trim() == "0")
                {
                    obj.Projectid = oldObj.Projectid;
                }

                if (obj.Servicecontractname == null || obj.Servicecontractname.ToString().Trim() == "update")
                {
                    obj.Servicecontractname = oldObj.Servicecontractname;
                }

                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }