예제 #1
0
//Convert DataTable To List method
        public List <ContactUsDataClass> ConvertToList(DataTable dt)
        {
            List <ContactUsDataClass> ContactUsDatalist = new List <ContactUsDataClass>();

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

                if (Convert.ToString(dt.Rows[i]["Contactusdataid"]) != "")
                {
                    obj_ContactUsData.Contactusdataid = Convert.ToInt32(dt.Rows[i]["Contactusdataid"]);
                }

                if (Convert.ToString(dt.Rows[i]["Name"]) != "")
                {
                    obj_ContactUsData.Name = Convert.ToString(dt.Rows[i]["Name"]);
                }

                if (Convert.ToString(dt.Rows[i]["Email"]) != "")
                {
                    obj_ContactUsData.Email = Convert.ToString(dt.Rows[i]["Email"]);
                }

                if (Convert.ToString(dt.Rows[i]["Messagesubject"]) != "")
                {
                    obj_ContactUsData.Messagesubject = Convert.ToString(dt.Rows[i]["Messagesubject"]);
                }

                if (Convert.ToString(dt.Rows[i]["Detailedmessage"]) != "")
                {
                    obj_ContactUsData.Detailedmessage = Convert.ToString(dt.Rows[i]["Detailedmessage"]);
                }

                if (Convert.ToString(dt.Rows[i]["Addeddatetime"]) != "")
                {
                    obj_ContactUsData.Addeddatetime = Convert.ToDateTime(dt.Rows[i]["Addeddatetime"]);
                }

                if (Convert.ToString(dt.Rows[i]["Addedip"]) != "")
                {
                    obj_ContactUsData.Addedip = Convert.ToString(dt.Rows[i]["Addedip"]);
                }


                ContactUsDatalist.Add(obj_ContactUsData);
            }
            return(ContactUsDatalist);
        }
예제 #2
0
 //insert data into database
 public Int32?insert(ContactUsDataClass obj)
 {
     try
     {
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Insert);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_ContactUsData_insert", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Contactusdataid = Convert.ToInt32(obj_con.getValue("@Contactusdataid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_ContactUsData_insert:" + ex.Message);
     }
 }
예제 #3
0
//Select Constructor
        public ContactUsDataCtl(Int32?id)
        {
            obj_con = new ConnectionCls();
            ContactUsDataClass obj_Con = new ContactUsDataClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_Con.Contactusdataid = Convert.ToInt32(dt.Rows[0]["Contactusdataid"]);
                    obj_Con.Name            = Convert.ToString(dt.Rows[0]["Name"]);
                    obj_Con.Email           = Convert.ToString(dt.Rows[0]["Email"]);
                    obj_Con.Messagesubject  = Convert.ToString(dt.Rows[0]["Messagesubject"]);
                    obj_Con.Detailedmessage = Convert.ToString(dt.Rows[0]["Detailedmessage"]);
                    obj_Con.Addeddatetime   = Convert.ToDateTime(dt.Rows[0]["Addeddatetime"]);
                    obj_Con.Addedip         = Convert.ToString(dt.Rows[0]["Addedip"]);
                }
            }
        }
예제 #4
0
//update edited object
        public ContactUsDataClass updateObject(ContactUsDataClass obj)
        {
            try
            {
                ContactUsDataClass oldObj = selectById(obj.Contactusdataid);
                if (obj.Name == null)
                {
                    obj.Name = oldObj.Name;
                }

                if (obj.Email == null)
                {
                    obj.Email = oldObj.Email;
                }

                if (obj.Messagesubject == null)
                {
                    obj.Messagesubject = oldObj.Messagesubject;
                }

                if (obj.Detailedmessage == null)
                {
                    obj.Detailedmessage = oldObj.Detailedmessage;
                }

                if (obj.Addeddatetime == null)
                {
                    obj.Addeddatetime = oldObj.Addeddatetime;
                }

                if (obj.Addedip == null)
                {
                    obj.Addedip = oldObj.Addedip;
                }

                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #5
0
//create parameter
        public void createParameter(ContactUsDataClass obj, DB_con.DBTrans trans)
        {
            try
            {
                obj_con.clearParameter();

                if (Convert.ToString(obj.Name) != "")
                {
                    obj_con.addParameter("@Name", string.IsNullOrEmpty(Convert.ToString(obj.Name)) ? "" : obj.Name);
                }
                else
                {
                    obj_con.addParameter("@Name", DBNull.Value);
                }

                if (Convert.ToString(obj.Email) != "")
                {
                    obj_con.addParameter("@Email", string.IsNullOrEmpty(Convert.ToString(obj.Email)) ? "" : obj.Email);
                }
                else
                {
                    obj_con.addParameter("@Email", DBNull.Value);
                }

                if (Convert.ToString(obj.Messagesubject) != "")
                {
                    obj_con.addParameter("@Messagesubject", string.IsNullOrEmpty(Convert.ToString(obj.Messagesubject)) ? "" : obj.Messagesubject);
                }
                else
                {
                    obj_con.addParameter("@Messagesubject", DBNull.Value);
                }

                if (Convert.ToString(obj.Detailedmessage) != "")
                {
                    obj_con.addParameter("@Detailedmessage", string.IsNullOrEmpty(Convert.ToString(obj.Detailedmessage)) ? "" : obj.Detailedmessage);
                }
                else
                {
                    obj_con.addParameter("@Detailedmessage", DBNull.Value);
                }

                if (Convert.ToString(obj.Addeddatetime) != "")
                {
                    obj_con.addParameter("@Addeddatetime", string.IsNullOrEmpty(Convert.ToString(obj.Addeddatetime)) ? Convert.ToDateTime("1900-01-01") : obj.Addeddatetime);
                }
                else
                {
                    obj_con.addParameter("@Addeddatetime", DBNull.Value);
                }

                if (Convert.ToString(obj.Addedip) != "")
                {
                    obj_con.addParameter("@Addedip", string.IsNullOrEmpty(Convert.ToString(obj.Addedip)) ? "" : obj.Addedip);
                }
                else
                {
                    obj_con.addParameter("@Addedip", DBNull.Value);
                }

                if (Convert.ToString(obj.Contactusdataid) != "")
                {
                    obj_con.addParameter("@Contactusdataid", Convert.ToInt32(obj.Contactusdataid), trans);
                }
                else
                {
                    obj_con.addParameter("@Contactusdataid", DBNull.Value);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }