private void FillControls(SqlInt32 IncomeID, SqlInt32 UserID) { IncomeBAL balIncome = new IncomeBAL(); IncomeENT entIncome = new IncomeENT(); entIncome = balIncome.SelectByPK(IncomeID, UserID); if (!entIncome.IncomeName.IsNull) { txtIncomeName.Text = entIncome.IncomeName.Value; } if (!entIncome.CatagoryID.IsNull) { ddlCatagoryList.SelectedValue = entIncome.CatagoryID.Value.ToString(); } if (!entIncome.Date.IsNull) { txtdate.Text = entIncome.Date.Value.ToString(); } if (!entIncome.Descripation.IsNull) { txtDescripation.Text = entIncome.Descripation.Value.ToString(); } if (!entIncome.IncomeAmount.IsNull) { txtIncomeAmount.Text = entIncome.IncomeAmount.Value.ToString().Trim(); } }
public Boolean Update(IncomeENT entIncome) { IncomeDAL dalIncome = new IncomeDAL(); if (dalIncome.Update(entIncome)) { return(true); } else { Message = dalIncome.Message; return(false); } }
public Boolean Insert(IncomeENT entIncome) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Income_InsertByUserID"; objCmd.Parameters.Add("@IncomeID", SqlDbType.Int).Direction = ParameterDirection.Output; objCmd.Parameters.Add("@IncomeName", SqlDbType.VarChar).Value = entIncome.IncomeName; objCmd.Parameters.Add("@IncomeAmount", SqlDbType.Decimal).Value = entIncome.IncomeAmount; objCmd.Parameters.Add("@CatagoryID", SqlDbType.Int).Value = entIncome.CatagoryID; objCmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = entIncome.Date; objCmd.Parameters.Add("@Descripation", SqlDbType.VarChar).Value = entIncome.Descripation; objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value = entIncome.UserID; objCmd.ExecuteNonQuery(); entIncome.IncomeID = Convert.ToInt32(objCmd.Parameters.Add("@IncomeID", SqlDbType.Int).Value); return(true); } catch (SqlException sqlex) { Message = sqlex.Message.ToString(); return(false); } catch (Exception ex) { Message = ex.Message.ToString(); return(false); } finally { if (objConn.State == ConnectionState.Open) { objConn.Close(); } } } } }
public Boolean Update(IncomeENT entIncome) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Income_UpdateByPKAndUserID"; objCmd.Parameters.AddWithValue("@IncomeID", entIncome.IncomeID); objCmd.Parameters.AddWithValue("@IncomeName", entIncome.IncomeName); objCmd.Parameters.AddWithValue("@IncomeAmount", entIncome.IncomeAmount); objCmd.Parameters.AddWithValue("@CatagoryID", entIncome.CatagoryID); objCmd.Parameters.AddWithValue("@Date", entIncome.Date); objCmd.Parameters.AddWithValue("@Descripation", entIncome.Descripation); objCmd.Parameters.AddWithValue("@UserID", entIncome.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(); } } } } }
protected void btnSave_Click(object sender, EventArgs e) { #region Server Side Validation string strError = ""; if (txtIncomeName.Text.Trim() == "") { strError += "Enter Income Name"; } if (ddlCatagoryList.SelectedIndex == 0) { strError += "Enter Catagory"; } if (txtdate.Text.Trim() == "") { strError += "Enter Date"; } if (txtIncomeAmount.Text.Trim() == "") { strError += "Enter Income Amount"; } if (strError.Trim() != "") { lblErrorMessage.Text = strError; return; } #endregion Server Side Validation #region Collect Data IncomeENT entIncome = new IncomeENT(); if (txtIncomeName.Text.Trim() != "") { entIncome.IncomeName = txtIncomeName.Text; } if (ddlCatagoryList.SelectedIndex > 0) { entIncome.CatagoryID = Convert.ToInt32(ddlCatagoryList.SelectedValue.ToString().Trim()); } if (txtdate.Text.Trim() != "") { entIncome.Date = Convert.ToDateTime(txtdate.Text.ToString()); } if (txtIncomeAmount.Text.Trim() != "") { entIncome.IncomeAmount = Convert.ToDecimal(txtIncomeAmount.Text.ToString().Trim()); } if (Session["UserID"] != null) { entIncome.UserID = Convert.ToInt32(Session["UserID"].ToString()); } entIncome.Descripation = txtDescripation.Text; #endregion Collect Data IncomeBAL balIncome = new IncomeBAL(); if (hfIncomeID.Value == "") { if (balIncome.Insert(entIncome)) { lblErrorMessage.Text = "Data Insert Successfully..."; divMessage.Visible = true; ClearControls(); } else { lblErrorMessage.Text = balIncome.Message; } //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "#add-contact", "$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true); } else { entIncome.IncomeID = Convert.ToInt32(hfIncomeID.Value.ToString().Trim()); if (balIncome.Update(entIncome)) { //Response.Redirect("~/AdminPanel/Income/Income.aspx"); lblErrorMessage.Text = "Data Updated Successfully..."; divMessage.Visible = true; ClearControls(); } else { lblErrorMessage.Text = balIncome.Message; } } fillGridViewIncome(Convert.ToInt32(Session["UserID"].ToString())); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "#add-contact", "$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true); }
public IncomeENT SelectByPK(SqlInt32 IncomeID, SqlInt32 UserID) { using (SqlConnection objConn = new SqlConnection(ConnectionString)) { objConn.Open(); using (SqlCommand objCmd = objConn.CreateCommand()) { try { objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "PR_Income_SelectAllByPKAndUserID"; objCmd.Parameters.Add("@IncomeID", SqlDbType.Int).Value = IncomeID; objCmd.Parameters.Add("@UserID", SqlDbType.Int).Value = UserID; IncomeENT entIncome = new IncomeENT(); using (SqlDataReader objSDR = objCmd.ExecuteReader()) { while (objSDR.Read()) { if (!objSDR["IncomeID"].Equals(DBNull.Value)) { entIncome.IncomeID = Convert.ToInt32(objSDR["IncomeID"].ToString()); } if (!objSDR["IncomeName"].Equals(DBNull.Value)) { entIncome.IncomeName = Convert.ToString(objSDR["IncomeName"].ToString()); } if (!objSDR["IncomeAmount"].Equals(DBNull.Value)) { entIncome.IncomeAmount = Convert.ToDecimal(objSDR["IncomeAmount"].ToString()); } if (!objSDR["CatagoryID"].Equals(DBNull.Value)) { entIncome.CatagoryID = Convert.ToInt32(objSDR["CatagoryID"].ToString()); } if (!objSDR["Date"].Equals(DBNull.Value)) { entIncome.Date = Convert.ToDateTime(objSDR["Date"].ToString()); } if (!objSDR["Descripation"].Equals(DBNull.Value)) { entIncome.Descripation = Convert.ToString(objSDR["Descripation"].ToString()); } } } return(entIncome); } 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(); } } } } }