public Boolean Update(CatagoryENT entCatagory) { CatagoryDAL dalCatagory = new CatagoryDAL(); if (dalCatagory.Update(entCatagory)) { return(true); } else { Message = dalCatagory.Message; return(false); } }
public Boolean Update(CatagoryENT entCatagory) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Catagory_UpdateByPKAndUserID"; objCmd.Parameters.AddWithValue("@CatagoryID", entCatagory.CatagoryID); objCmd.Parameters.AddWithValue("@CatagoryName", entCatagory.CatagoryName); objCmd.Parameters.AddWithValue("@CatagoryType", entCatagory.CatagoryType); objCmd.Parameters.AddWithValue("@CatagoryDescripation", entCatagory.CatagoryDescripation); objCmd.Parameters.AddWithValue("@UserID", entCatagory.UserID); objCmd.ExecuteNonQuery(); return(true); } catch (SqlException sqlex) { Message = sqlex.InnerException.ToString(); return(false); } catch (Exception ex) { Message = ex.InnerException.ToString(); return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
public Boolean Insert(CatagoryENT entCatagory) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Catagory_InsertByUserID"; objCmd.Parameters.Add("@CatagoryID", SqlDbType.Int).Direction = ParameterDirection.Output; objCmd.Parameters.Add("@CatagoryName", SqlDbType.VarChar).Value = entCatagory.CatagoryName; objCmd.Parameters.Add("@CatagoryType", SqlDbType.VarChar).Value = entCatagory.CatagoryType; objCmd.Parameters.Add("@CatagoryDescripation", SqlDbType.VarChar).Value = entCatagory.CatagoryDescripation; objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value = entCatagory.UserID; objCmd.ExecuteNonQuery(); entCatagory.CatagoryID = Convert.ToInt32(objCmd.Parameters.Add("@CatagoryID", SqlDbType.Int).Value); return(true); } catch (SqlException sqlex) { Message = sqlex.InnerException.ToString(); return(false); } catch (Exception ex) { Message = ex.InnerException.ToString(); return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
private void FillControls(SqlInt32 CatagoryID, SqlInt32 UserID) { CatagoryBAL balCatagory = new CatagoryBAL(); CatagoryENT entCatagory = new CatagoryENT(); entCatagory = balCatagory.SelectByPK(CatagoryID, UserID); if (!entCatagory.CatagoryName.IsNull) { txtCatagoryName.Text = entCatagory.CatagoryName.Value; } if (!entCatagory.CatagoryType.IsNull) { rbCatagoryType.Text = entCatagory.CatagoryType.Value; } if (!entCatagory.CatagoryDescripation.IsNull) { txtDescripation.Text = entCatagory.CatagoryDescripation.Value; } }
public CatagoryENT SelectByPK(SqlInt32 CatagoryID, SqlInt32 UserID) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Catagory_SelectAllBYPKAndUserID"; objCmd.Parameters.Add("@CatagoryID", SqlDbType.Int).Value = CatagoryID; objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID; CatagoryENT entCatagory = new CatagoryENT(); using (SqlDataReader objSDR = objCmd.ExecuteReader()) { while (objSDR.Read()) { if (!objSDR["CatagoryID"].Equals(DBNull.Value)) { entCatagory.CatagoryID = Convert.ToInt32(objSDR["CatagoryID"].ToString()); } if (!objSDR["CatagoryName"].Equals(DBNull.Value)) { entCatagory.CatagoryName = Convert.ToString(objSDR["CatagoryName"].ToString()); } if (!objSDR["CatagoryType"].Equals(DBNull.Value)) { entCatagory.CatagoryType = Convert.ToString(objSDR["CatagoryType"].ToString()); } if (!objSDR["CatagoryDescripation"].Equals(DBNull.Value)) { entCatagory.CatagoryDescripation = Convert.ToString(objSDR["CatagoryDescripation"].ToString()); } } } return(entCatagory); } catch (SqlException sqlex) { Message = sqlex.InnerException.ToString(); return(null); } catch (Exception ex) { Message = ex.InnerException.ToString(); return(null); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
protected void btnSave_Click(object sender, EventArgs e) { #region Server Side Validation string strError = ""; if (txtCatagoryName.Text.Trim() == "") { strError += "Enter Catagory Name"; } if (rbCatagoryType.Text.Trim() == "") { strError += "Enter Catagory Type"; } if (strError.Trim() != "") { lblErrorMessage.Text = strError; divMessage.Visible = true; return; } #endregion Server Side Validation #region Collect Data CatagoryENT entCatagory = new CatagoryENT(); if (txtCatagoryName.Text != "") { entCatagory.CatagoryName = txtCatagoryName.Text; } if (rbCatagoryType.Text != "") { entCatagory.CatagoryType = rbCatagoryType.Text; } if (txtDescripation.Text != "") { entCatagory.CatagoryDescripation = txtDescripation.Text; } if (Session["UserID"] != null) { entCatagory.UserID = Convert.ToInt32(Session["UserID"].ToString()); } #endregion Collect Data CatagoryBAL balCatagory = new CatagoryBAL(); if (hfCatagoryID.Value == "") { if (balCatagory.Insert(entCatagory)) { lblErrorMessage.Text = "Data Insert Successfully..."; lblErrorMessage.CssClass = "text-success"; divMessage.Visible = true; ClearControls(); } else { lblErrorMessage.Text = balCatagory.Message; } } else { entCatagory.CatagoryID = Convert.ToInt32(hfCatagoryID.Value.ToString().Trim()); if (balCatagory.Update(entCatagory)) { lblErrorMessage.Text = "Data Updated Successfully..."; divMessage.Visible = true; ClearControls(); } else { lblErrorMessage.Text = balCatagory.Message; } } FillGridViewCatagory(Convert.ToInt32(Session["UserID"].ToString())); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "#add-contact", "$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true); }