Quantcast
Channel: Project Customization and Programming forum
Viewing all articles
Browse latest Browse all 5347

Just Testing

$
0
0
public static IList<SelectListItem> GetListData(string selectedValue, string ListName)
        {
            if (selectedValue == null)
            {
                selectedValue = string.Empty;
            }
            string strListName = string.Empty;
            strListName = ListName;
            MFITDDataContext db = new MFITDDataContext();
            List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = "Select ", Value = "0" });
            //Dictionary<string, string> listnamecollection = null;
            SelectListItem itemAll = new SelectListItem();
            //string DropdownTitle = string.Empty;
            // List<ListCountry> lstCountry = new List<ListCountry>();
            if (!string.IsNullOrEmpty(ListName))
            {
                switch (ListName.ToUpper())
                {
                    case "LISTBRANCH":
                        items.AddRange(db.ListBranches.Select(p => new SelectListItem { Text = p.BranchName, Value = p.BranchName, Selected = (p.BranchName == selectedValue ? true : false) }).OrderBy(m => m.Text).ToList());
                        items[0].Text = "Select Branch";
                        break;

                }

                //foreach (var listcoll in lstCountry)
                //{
                //    if (listcoll.CountryName == selectedValue)
                //    {

                //        SelectListItem item = new SelectListItem();
                //        item.Value = listcoll.CountryName.ToString();
                //        item.Text = listcoll.CountryName;
                //        item.Selected = true;
                //        items.Add(item);
                //    }
                //    else
                //    {
                //        SelectListItem item = new SelectListItem();
                //        item.Value = listcoll.CountryName.ToString();
                //        item.Text = listcoll.CountryName;
                //        item.Selected = false;
                //        items.Add(item);
                //    }
                //}
            }
            else
            {

                itemAll.Value = "0";
                itemAll.Text = "All";
                items.Add(itemAll);
            }
            return items;

        }




    public class Test
     {
         public Test() { }
 

        #region Properties
         public int TestID{ get; set; }
         
        #endregion
 
        #region Object Declaration
         #endregion
 
        #region Methods
 
      public void Add(Test Test, ref string strErrorMsg)
         {
 
            SqlParameter[] sp_Parameters = new SqlParameter[4];
             sp_Parameters[0] = new SqlParameter("@TestID", Test.TestID
             #region Data Execution Process
             try
             {
                 objSqlHelper.ExecuteSP("SP_Insert", sp_Parameters, ref strErrorMsg);
             }
             catch (Exception ex)
             {
                 strErrorMsg = ex.Message.ToString();
             }
             #endregion
         }
        public void Edit(Test Test, ref string strErrorMsg)
         {
            SqlParameter[] sp_Parameters = new SqlParameter[5];
             sp_Parameters[0] = new SqlParameter("@Test", Test.TestID);
             #region Data Execution Process
             try
             {
                 objSqlHelper.ExecuteSP("SP_Edit", sp_Parameters, ref strErrorMsg);
             }
             catch (Exception ex)
             {
                 strErrorMsg = ex.Message.ToString();
             }
             #endregion
         }
         public void Delete(int id, ref string strErrorMsg)
         {
             SqlParameter[] sp_Parameters = new SqlParameter[1];
             sp_Parameters[0] = new SqlParameter("@TestID", id);

            #region Data Execution Process
             try
             {
                 objSqlHelper.ExecuteSP("SP_Delete", sp_Parameters, ref strErrorMsg);
             }
             catch (Exception ex)
             {
                 strErrorMsg = ex.Message.ToString();
             }
             #endregion
         }
        public IList<Test> GetAllRecords()
         {
             List<Test> listadversity = new List<Test>();
            DataSet ds = new DataSet();
             try
             {
             SqlParameter[] sp_Parameters = new SqlParameter[1];
             sp_Parameters[1] = new SqlParameter("@TestID", 0);
            ds = objSqlHelper.GetData("SP_Get", sp_Parameters);
            if (ds != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     if (ds.Tables[0].Rows.Count > 0)
                     {
                        listadversity = (from j in ds.Tables[0].AsEnumerable()
                                          select new Test()
                                          {
                                              TestID= Convert.ToString(j["TestID"])                                             
                                          }).ToList();
                     }
                 }
             }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return listadversity;
         }
         public Test GetData_ByID(int TestID)
         {
             Test listTest= new Test();
             DataSet ds = new DataSet();
             try
             {
             SqlParameter[] sp_Parameters = new SqlParameter[2];
            sp_Parameters[1] = new SqlParameter("@TestID", TestID);
            ds = objSqlHelper.GetData("SP_Get", sp_Parameters);
            if (ds != null)
             {
                 if (ds.Tables.Count > 0)
                 {
                     if (ds.Tables[0].Rows.Count > 0)
                     {
                         var queryresult = (from j in ds.Tables[0].AsEnumerable()
                                            select j).FirstOrDefault();
                        if (queryresult != null)
                         {
                            listTest.TestID= queryresult.Table.Rows[0]["TestID"].ToString();
                         }
                     }
                 }
             }
             }
             catch (Exception ex)
             {
                 throw ex;
             }
             return listTest;
         }
        #endregion
    }
 }



    public class SqlHelper
     {
         public string ConnectionString= RoleEnvironment.GetConfigurationSettingValue("ConnectionString");//System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
         public string MemberShipConnectionString = RoleEnvironment.GetConfigurationSettingValue("MemberShipConnectionString");// System.Configuration.ConfigurationManager.ConnectionStrings["MemberShipConnectionString"].ConnectionString;
         public SqlConnection objSQLCon;
         /// <summary>
         /// SQL Transaction object
         /// </summary>
         public SqlTransaction objSQLTran;
         public string _ConnectionString;
        public string ConnectionString
         {
             get { return _ConnectionString; }
             set { _ConnectionString = value; }
         }
        public SqlHelper()
         {
             this._ConnectionString = ConnectionString;
         }
         public SqlHelper(string DataBaseName)
         {
             if (DataBaseName == "MemberShip")
             {
                 this._ConnectionString = MemberShipConnectionString;
             }
             else
             {
                 this._ConnectionString = ConnectionString;
             }
         }

        #region Database Methods
 
        #region Make Connection
         public void MakeDBConnection()
         {
             this.objSQLCon = new SqlConnection(_ConnectionString);
             this.objSQLCon.Open();
         }
         #endregion
 
        #region Close Connection
         public void CloseDBConnection()
         {
             if (this.objSQLCon != null)
             {
                 if (this.objSQLCon.State.ToString() != ConnectionState.Closed.ToString())
                     this.objSQLCon.Close();
                 this.objSQLCon.Dispose();
                 this.objSQLCon = null;
             }
         }
         #endregion
 
        #region Begin Transaction
         public void BeginDBTransaction()
         {
             this.objSQLTran = this.objSQLCon.BeginTransaction();
         }
         #endregion
 
        #region Commit Transaction
         public void CommitDBTransaction()
         {
             this.objSQLTran.Commit();
         }
         #endregion
 
        #region Rollback Transaction
         public void RollbackDBTransaction()
         {
             if (this.objSQLTran != null)
                 this.objSQLTran.Rollback();
         }
         #endregion
 
        #region Set Command Property
         public SqlCommand SetCmdProperties(string strStoredProcedureName, CommandType objCommandType,SqlParameter[] objSqlParm)
         {
             SqlCommand cmdToExecute = new SqlCommand();
             cmdToExecute.CommandText = strStoredProcedureName;
             cmdToExecute.CommandType = objCommandType;
             if (objSqlParm != null)
             {
                 cmdToExecute.Parameters.AddRange(objSqlParm);
             }
             cmdToExecute.Connection = this.objSQLCon;
             cmdToExecute.CommandTimeout = 60;
             return cmdToExecute;
         }
         public SqlCommand SetCmdPropertiesTest(string strStoredProcedureName, CommandType objCommandType, SqlParameter objSqlParm)
         {
             SqlCommand cmdToExecute = new SqlCommand();
             cmdToExecute.CommandText = strStoredProcedureName;
             cmdToExecute.CommandType = objCommandType;
             if (objSqlParm != null)
             {
                 cmdToExecute.Parameters.Add(objSqlParm);
             }
             cmdToExecute.Connection = this.objSQLCon;
             cmdToExecute.CommandTimeout = 60;
             return cmdToExecute;
         }
         #endregion
 
        #region Get Scalar value
         public object GetScalarValue(string strSQL)
         {
             MakeDBConnection();
             SqlCommand objSQMComm = new SqlCommand(strSQL, this.objSQLCon);
 
            try
             {
                 object objScalarVal = objSQMComm.ExecuteScalar();
                 objSQMComm.Dispose();
                 return objScalarVal;
             }
             catch (Exception Ex)
             {
                 if (objSQMComm != null)
                 {
                     objSQMComm.Dispose();
                     objSQMComm = null;
                 }
                 throw Ex;
             }
         }
 
        public object GetScalarValue(string strSQL, SqlParameter[] objSqlPar)
         {
             MakeDBConnection();
 
            SqlCommand objSQMComm = SetCmdProperties(strSQL, CommandType.StoredProcedure, objSqlPar);           
 
            try
             {
                 object objScalarVal = objSQMComm.ExecuteScalar();
                 objSQMComm.Dispose();
                 return objScalarVal;
             }
             catch (Exception Ex)
             {
                 if (objSQMComm != null)
                 {
                     objSQMComm.Dispose();
                     objSQMComm = null;
                 }
                 throw Ex;
             }
         }
         #endregion
 
        #endregion
 
        public DataSet GetData(string strSql)
         {
             DataSet dsDate = new DataSet();
             MakeDBConnection();
             SqlDataAdapter objSqlAdp = new SqlDataAdapter(SetCmdProperties(strSql,CommandType.Text,null));
             objSqlAdp.Fill(dsDate);
             objSqlAdp.Dispose();
             CloseDBConnection();
             return dsDate;
         }
 
        public DataSet GetDataUsingStoredProcedure(string strSql)
         {
             DataSet dsDate = new DataSet();
             MakeDBConnection();
             SqlDataAdapter objSqlAdp = new SqlDataAdapter(SetCmdProperties(strSql, CommandType.StoredProcedure, null));
             objSqlAdp.Fill(dsDate);
             objSqlAdp.Dispose();
             CloseDBConnection();
             return dsDate;
         }
 
        public DataSet GetData(string strSql, SqlParameter[] objSqlPar)
         {
             DataSet dsDate = new DataSet();
             MakeDBConnection();
             SqlDataAdapter objSqlAdp = new SqlDataAdapter(SetCmdProperties(strSql, CommandType.StoredProcedure, objSqlPar));
             objSqlAdp.Fill(dsDate);
             objSqlAdp.Dispose();
             CloseDBConnection();
             return dsDate;
         }
         public void ExecuteSP(string SPName, SqlParameter[] objSqlPar, ref string strErrorMsg)
         {
             MakeDBConnection();
 
            SqlCommand SQLCmd = SetCmdProperties(SPName, CommandType.StoredProcedure, objSqlPar);
 
            #region Data Execution Process
 
            try
             {
                 SQLCmd.ExecuteNonQuery();
             }
             catch (Exception ex)
             {
                 // ************************ Rollback Transaction **************************************
                 strErrorMsg = ex.Message.ToString();
             }
             finally
             {
                 CloseDBConnection();
                 SQLCmd.Dispose();
             }
             #endregion
         }
         public void ExecuteSPTran(string SPName, SqlParameter[] objSqlPar, ref string strErrorMsg)
         {
             MakeDBConnection();
 
            SqlCommand SQLCmd = SetCmdProperties(SPName, CommandType.StoredProcedure, objSqlPar);
 
            #region Data Execution Process
 
            try
             {
                 BeginDBTransaction();
 
                SQLCmd.Transaction = objSQLTran;
 
                SQLCmd.ExecuteNonQuery();
 
                CommitDBTransaction();
             }
             catch (Exception ex)
             {
                 // ************************ Rollback Transaction **************************************
                 RollbackDBTransaction();
                 strErrorMsg = ex.Message.ToString();
             }
             finally
             {
                 CloseDBConnection();
                 SQLCmd.Dispose();
             }
             #endregion
         }
 
        public void ExecuteSPOutParameterTransaction(ref SqlCommand SQLcmd, string SPName, SqlParameter[] objSqlPar, ref string strErrorMsg)
         {
             MakeDBConnection();
 
            SqlCommand SQLCmd = SetCmdProperties(SPName, CommandType.StoredProcedure, objSqlPar);
 
            #region Data Execution Process
 
            try
             {
                 BeginDBTransaction();
 
                SQLCmd.Transaction = objSQLTran;
 
                SQLCmd.ExecuteNonQuery();
 
                CommitDBTransaction();
             }
             catch (Exception ex)
             {
                 // ************************ Rollback Transaction **************************************
                 RollbackDBTransaction();
                 strErrorMsg = ex.Message.ToString();
             }
             finally
             {
                 CloseDBConnection();
                 SQLCmd.Dispose();
             }
             #endregion
         }
         public void ExecuteSPOutParameter(ref SqlCommand SQLcmd, string SPName, SqlParameter[] objSqlPar, ref string strErrorMsg)
         {
             MakeDBConnection();
 
            SQLcmd = SetCmdProperties(SPName, CommandType.StoredProcedure, objSqlPar);
 
            #region Data Execution Process
 
            try
             {
                 SQLcmd.ExecuteNonQuery();
             }
             catch (Exception ex)
             {
                 // ************************ Rollback Transaction **************************************
                 strErrorMsg = ex.Message.ToString();
             }
             finally
             {
                 CloseDBConnection();
                 SQLcmd.Dispose();
             }
             #endregion
         }
     }
 }
 

function OnClickAdd(mode, sectionname, PrimaryKeyvalue) {
     generalmode = mode;
     educationprimarykey = PrimaryKeyvalue;
     var data_Object = {};
 
data_Object[0] = document.getElementsByName('ddl')[0].value;
             data_Object[1] = document.getElementsByName('txtTitle')[0].value;
             

$.ajax({
             type: 'Post',
             url: "/ControllerName/AddEdit",
             data: { "DataObject": data_Object, "Mode": mode, "PrimaryKeyvalue": Primarykeyvalue, "ProfileEducationID": document.getElementsByName('hidProfileEducationID')[0].value },
             datatype: 'html',
             success: function (data) {
                 $('#screen').css({ "display": "block", "width": "", "height": "" });
                 $('#divProcessImages').css({ "display": "none" });
                 $("#Edit").html(data);
                 //$.fn.sfEvalScripts(data);
             },
             error: function (req, status, error) {
                 alert(req.responseText);
             }
         });<%=Html.DropDownList("ddlCountry", ViewData["listcountryData"] as List<SelectListItem>, new { @class = "DropDownList", onkeydown = "fnKeyDown(event)" })%>






Viewing all articles
Browse latest Browse all 5347

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>