/// <summary> /// Method to fetch currency from database and assign to textbox /// </summary> private void getBudgetCurrenceFromProject() { BudgetEstimationBLL BudgetEstimationBLLObj = new BudgetEstimationBLL(); BudgetEstimationBO BudgetEstimationBOObj = new BudgetEstimationBO(); string projectID = Session["PROJECT_ID"].ToString(); BudgetEstimationBOObj = BudgetEstimationBLLObj.getCurrenceFromProject(projectID); MillionUSH.Text = BudgetEstimationBOObj.CurrencyCode; lblTotalBudgEstCurr.Text = BudgetEstimationBOObj.CurrencyCode; CurrenceID.Text = BudgetEstimationBOObj.CurrencyID.ToString(); CurrenceID.Visible = false; }
/// <summary> /// Set edit mode for edit comand /// Delete data from the database for delete comand /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grdBudgetEstimation_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditRow") { ViewState["BudgetEstimationID"] = e.CommandArgument; BudgetEstimationBO objBudgetEstimation = new BudgetEstimationBO(); BudgetEstimationBLL objBudgetEstimationBLL = new BudgetEstimationBLL(); objBudgetEstimation = objBudgetEstimationBLL.GetBudgetEstimationByID(Convert.ToInt32(ViewState["BudgetEstimationID"])); if (objBudgetEstimation != null) { ValueTextBox.Text = UtilBO.CurrencyFormat(Convert.ToDecimal(objBudgetEstimation.ValueAmount)); HiddenFieldTotalValue.Value = (float.Parse(HiddenFieldTotalValue.Value) - float.Parse(objBudgetEstimation.ValueAmount)).ToString(); ValuePerTextBox.Text = objBudgetEstimation.ValueAmountper; BudgetEstimationIDTextBox.Text = objBudgetEstimation.BudgetEstimationID.ToString(); CategoryDropDownList.ClearSelection(); if (CategoryDropDownList.Items.FindByValue(objBudgetEstimation.CategoryID.ToString()) != null) { CategoryDropDownList.Items.FindByValue(objBudgetEstimation.CategoryID.ToString()).Selected = true; } getSubCatByCatID(); SubCategoryDropDownList.ClearSelection(); if (SubCategoryDropDownList.Items.FindByValue(objBudgetEstimation.SubCategoryID.ToString()) != null) { SubCategoryDropDownList.Items.FindByValue(objBudgetEstimation.SubCategoryID.ToString()).Selected = true; } AcountNumberTextBox.Text = objBudgetEstimation.AccountNo; } SetUpdateMode(true); } else if (e.CommandName == "DeleteRow") { string message = string.Empty; string budgetEstimationID = e.CommandArgument.ToString(); BudgetEstimationBLL objBudgetEstimationBLL = new BudgetEstimationBLL(); message = objBudgetEstimationBLL.DeleteBudgetEstimation(Convert.ToInt32(budgetEstimationID)); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data deleted successfully"; } if (message != "") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } ClearDetails(); SetUpdateMode(false); BindEstCategories(); getToatlBudgetValue(); } }
/// <summary> /// To bind data to hidden field in grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void rptBudgetEstCategory_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { HiddenField hdnEstCategoryID = (HiddenField)e.Item.FindControl("hdnEstCategoryID"); GridView grdSubCat = (GridView)e.Item.FindControl("grdBudgetEstimation"); BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); string pID = Session["PROJECT_ID"].ToString(); grdSubCat.DataSource = BudgetEstimationBLLobj.GetBudgetEstimation(pID, Convert.ToInt32(hdnEstCategoryID.Value)); grdSubCat.DataBind(); if (grdSubCat.Rows.Count == 0) { e.Item.Visible = false; } } }
/// <summary> /// to bind new category dropdownlist /// </summary> /// <param name="lastItemSelected"></param> protected void BindNewCategories(bool lastItemSelected) { // used when adding a new Sub Category. BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); AddNewCategoryDropDownList.DataSource = BudgetEstimationBLLobj.getAllCategory(); AddNewCategoryDropDownList.DataTextField = "CategoryName"; AddNewCategoryDropDownList.DataValueField = "CategoryID"; AddNewCategoryDropDownList.DataBind(); if (lastItemSelected) { CategoryDropDownList.Items[CategoryDropDownList.Items.Count - 1].Selected = true; } else { CategoryDropDownList.SelectedIndex = 0; } }
/// <summary> /// To save category details to the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Category_SaveButton_Click(object sender, EventArgs e) { string AlertMessage = string.Empty; string message = string.Empty; BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); try { string uID = Session["USER_ID"].ToString(); BudgetEstimationBO objNEWCategory = new BudgetEstimationBO(); objNEWCategory.CategoryName = AddCategoryTextBox.Text.ToString().Trim(); objNEWCategory.UserID = Convert.ToInt32(uID); //BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); message = BudgetEstimationBLLobj.InsertNEWCategory(objNEWCategory); if (string.IsNullOrEmpty(message) || message == "" || message == "null") { message = "Data saved successfully"; BindCategories(true); BindNewCategories(true); BindEstCategories(); // SubCategoryDropDownList.Items.Clear(); ListItem lstItem = SubCategoryDropDownList.Items[0]; SubCategoryDropDownList.Items.Clear(); SubCategoryDropDownList.Items.Insert(0, lstItem); } } catch (Exception ex) { throw ex; } finally { BudgetEstimationBLLobj = null; AddCategoryTextBox.Text = ""; } AlertMessage = "alert('" + message + "');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", AlertMessage, true); }
/// <summary> /// To bind category dropdownlist /// </summary> /// <param name="lastItemSelected"></param> protected void BindCategories(bool lastItemSelected) { BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); CategoryDropDownList.DataSource = BudgetEstimationBLLobj.getAllCategory(); CategoryDropDownList.DataTextField = "CategoryName"; CategoryDropDownList.DataValueField = "CategoryID"; CategoryDropDownList.DataBind(); CategoryDropDownList.Items.Insert(0, new ListItem("--Select--", "0")); if (lastItemSelected) { CategoryDropDownList.Items[CategoryDropDownList.Items.Count - 1].Selected = true; } else { CategoryDropDownList.SelectedIndex = 0; } }
/// <summary> /// method to bind data to subcategory dropdownlist /// </summary> /// <param name="categoryID"></param> /// <param name="lastItemSelected"></param> protected void BindSubCategories(int categoryID, bool lastItemSelected) { BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); ListItem lstItem = new ListItem(SubCategoryDropDownList.Items[0].Text, SubCategoryDropDownList.Items[0].Value); SubCategoryDropDownList.Items.Clear(); SubCategoryDropDownList.DataSource = BudgetEstimationBLLobj.getSubCatByCatID(categoryID); SubCategoryDropDownList.DataTextField = "SubCategoryName"; SubCategoryDropDownList.DataValueField = "SubCategoryID"; SubCategoryDropDownList.DataBind(); SubCategoryDropDownList.Items.Insert(0, lstItem); if (lastItemSelected) { SubCategoryDropDownList.Items[SubCategoryDropDownList.Items.Count - 1].Selected = true; } else { SubCategoryDropDownList.SelectedIndex = 0; } }
/// <summary> /// To save details to the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveButton_Click(object sender, EventArgs e) { ViewState["BudgetEstimationID"] = 0; BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); if (BudgetEstimationIDTextBox.Text != "0") { string uID = Session["USER_ID"].ToString(); string pID = Session["PROJECT_ID"].ToString(); BudgetEstimationBO objBudgetEstimation = new BudgetEstimationBO(); objBudgetEstimation.BudgetEstimationID = Convert.ToInt32(BudgetEstimationIDTextBox.Text); objBudgetEstimation.CategoryID = Convert.ToInt32(CategoryDropDownList.SelectedItem.Value.ToString().Trim()); objBudgetEstimation.SubCategoryID = Convert.ToInt32(SubCategoryDropDownList.SelectedItem.Value.ToString()); objBudgetEstimation.ValueAmount = ValueTextBox.Text.ToString().Replace(",", "").Trim(); objBudgetEstimation.ValueAmountper = ValuePerTextBox.Text.ToString().Trim(); objBudgetEstimation.UserID = Convert.ToInt32(uID); objBudgetEstimation.ProjectID = Convert.ToInt32(pID); objBudgetEstimation.CurrencyID = Convert.ToInt32(CurrenceID.Text.ToString()); objBudgetEstimation.AccountNo = AcountNumberTextBox.Text.ToString(); //BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); string message = BudgetEstimationBLLobj.EditBudgetEstimation(objBudgetEstimation); if (message == string.Empty || message == "null") { BudgetEstimationIDTextBox.Text = "0"; BindEstCategories(); getToatlBudgetValue(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('Data Updated successfully');", true); ClearDetails(); SetUpdateMode(false); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } } else { try { string uID = Session["USER_ID"].ToString(); string pID = Session["PROJECT_ID"].ToString(); BudgetEstimationBO objBudgetEstimation = new BudgetEstimationBO(); objBudgetEstimation.CategoryID = Convert.ToInt32(CategoryDropDownList.SelectedItem.Value.ToString().Trim()); objBudgetEstimation.SubCategoryID = Convert.ToInt32(SubCategoryDropDownList.SelectedItem.Value.ToString()); objBudgetEstimation.ValueAmount = ValueTextBox.Text.ToString().Replace(",", "").Trim(); objBudgetEstimation.ValueAmountper = ValuePerTextBox.Text; objBudgetEstimation.UserID = Convert.ToInt32(uID); objBudgetEstimation.ProjectID = Convert.ToInt32(pID); objBudgetEstimation.CurrencyID = Convert.ToInt32(CurrenceID.Text.ToString()); objBudgetEstimation.AccountNo = AcountNumberTextBox.Text.ToString(); //if (ddlCurrencyBudget.SelectedIndex > 0) //{ // objBudgetEstimation.BudgetCurrency = Convert.ToInt32(ddlCurrencyBudget.SelectedValue); //} //BudgetEstimationBLL BudgetEstimationBLLobj = new BudgetEstimationBLL(); string message = BudgetEstimationBLLobj.InsertBudgetEstimation(objBudgetEstimation); if (message == string.Empty || message == "null") { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('Data saved successfully');", true); BindEstCategories(); getToatlBudgetValue(); ClearDetails(); } else { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); } } catch (Exception ex) { throw ex; } finally { BudgetEstimationBLLobj = null; } } }