/// <summary> /// update row in the table /// </summary> /// <param name="businessObject">business object</param> /// <returns>true for successfully updated</returns> public bool Update(clsJP_ADMIN businessObject) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_JP_ADMIN_Update]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { sqlCommand.Parameters.Add(new SqlParameter("@Username", SqlDbType.VarChar, 45, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Username)); sqlCommand.Parameters.Add(new SqlParameter("@Pswd", SqlDbType.VarChar, 45, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, businessObject.Pswd)); MainConnection.Open(); sqlCommand.ExecuteNonQuery(); return(true); } catch (Exception ex) { throw new Exception("clsJP_ADMIN::Update::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }
protected void btn_Click(object sender, EventArgs e) { clsJP_ADMIN U = (clsJP_ADMIN)Session["User"]; clsJP_ADMINFactory fac = new clsJP_ADMINFactory(); List <clsJP_ADMIN> User = fac.GetAllBy(clsJP_ADMIN.clsJP_ADMINFields.Username, U.Username); Helper h = new Helper(); if (User != null && User.Count > 0) { if (User[0].Pswd == h.Encrypt(txtOld.Text)) { clsJP_ADMIN NewUser = new clsJP_ADMIN(); NewUser.Username = U.Username; NewUser.Pswd = h.Encrypt(txtNew.Text); fac.Update(NewUser); pnlSuccess.Visible = true; } else { pnlError.Visible = true; } } }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of clsJP_ADMIN</returns> internal List <clsJP_ADMIN> PopulateObjectsFromReader(IDataReader dataReader) { List <clsJP_ADMIN> list = new List <clsJP_ADMIN>(); while (dataReader.Read()) { clsJP_ADMIN businessObject = new clsJP_ADMIN(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(clsJP_ADMIN businessObject, IDataReader dataReader) { if (!dataReader.IsDBNull(dataReader.GetOrdinal(clsJP_ADMIN.clsJP_ADMINFields.Username.ToString()))) { businessObject.Username = dataReader.GetString(dataReader.GetOrdinal(clsJP_ADMIN.clsJP_ADMINFields.Username.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(clsJP_ADMIN.clsJP_ADMINFields.Pswd.ToString()))) { businessObject.Pswd = dataReader.GetString(dataReader.GetOrdinal(clsJP_ADMIN.clsJP_ADMINFields.Pswd.ToString())); } }
/// <summary> /// Select by primary key /// </summary> /// <param name="keys">primary keys</param> /// <returns>clsJP_ADMIN business object</returns> public clsJP_ADMIN SelectByPrimaryKey(clsJP_ADMINKeys keys) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[sp_JP_ADMIN_SelectByPrimaryKey]"; sqlCommand.CommandType = CommandType.StoredProcedure; // Use connection object of base class sqlCommand.Connection = MainConnection; try { MainConnection.Open(); IDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { clsJP_ADMIN businessObject = new clsJP_ADMIN(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("clsJP_ADMIN::SelectByPrimaryKey::Error occured.", ex); } finally { MainConnection.Close(); sqlCommand.Dispose(); } }