private void frmCosting_Load(object sender, EventArgs e) { StockHoldingRate_DL objStockHoldingRateDL = new StockHoldingRate_DL(ConnectionStringClass.GetConnection()); Employee_DL objEmpDL = new Employee_DL(ConnectionStringClass.GetConnection()); Department_DL objDepDL = new Department_DL(ConnectionStringClass.GetConnection()); Section_DL objSection_DL = new Section_DL(ConnectionStringClass.GetConnection()); try { StockHoldingRate obj = new StockHoldingRate(); obj = objStockHoldingRateDL.GetFinal(); Employee objChangedBy = objEmpDL.Get(obj.ChangedBy); txtEnterdBy.Text = objChangedBy.EmployeeName; txtEnterdDate.Text = obj.FromDate.Value.ToShortDateString(); txtCurrentRate.Text = obj.Cost.ToString(); bindStockHolding.DataSource = objStockHoldingRateDL.Get(); bindDepartment.DataSource = objSection_DL.GetDataView(); objCompanyOverHeadRate = objCompanyOverHeadRate_DL.Get(); if (objCompanyOverHeadRate != null) { txtComDate.Text = objCompanyOverHeadRate.EnterdDate.ToShortDateString(); txtComEnterd.Text = objCompanyOverHeadRate.EnterdBy.EmployeeNameID; txtComRate.Text = objCompanyOverHeadRate.Rate.ToString(); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSet_Click(object sender, EventArgs e) { StockHoldingRate_DL objStockHoldingRateDL = new StockHoldingRate_DL(ConnectionStringClass.GetConnection()); Employee_DL objEmpDL = new Employee_DL(ConnectionStringClass.GetConnection()); try { if (!txtNewRate.Text.Equals("")) { DialogResult dr = MessageBox.Show(this, "Are you sure you want to change current Stock Holding Rate?\nChanging the rate cannot be Undo, Click Yes to continue, No to cancel", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (dr == DialogResult.Yes) { StockHoldingRate objNewStockHoldingRate = new StockHoldingRate(); objNewStockHoldingRate.Cost = Convert.ToDecimal(txtNewRate.Text); objNewStockHoldingRate.ChangedBy = CurrentUser.EmployeeID; objNewStockHoldingRate.FromDate = DateTime.Now; objNewStockHoldingRate.ToDate = DateTime.Now; objStockHoldingRateDL.Add(objNewStockHoldingRate); StockHoldingRate obj = new StockHoldingRate(); obj = objStockHoldingRateDL.GetFinal(); Employee objChangedBy = objEmpDL.Get(obj.ChangedBy); txtEnterdBy.Text = objChangedBy.EmployeeName; txtEnterdDate.Text = obj.FromDate.Value.ToShortDateString(); txtCurrentRate.Text = obj.Cost.ToString(); bindStockHolding.DataSource = objStockHoldingRateDL.Get(); gvStockHoldingRates.CurrentCell = gvStockHoldingRates[1, gvStockHoldingRates.Rows.Count - 1]; gvStockHoldingRates.FirstDisplayedScrollingRowIndex = gvStockHoldingRates.Rows.Count - 1; } } else { MessageBox.Show(this, "Please enter a value as a New Rate", "Empty Fields", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }