protected void btnReallocateSubmit_Click(object sender, EventArgs e) { int?nullable = null; try { btnNewTransaction.Visible = false; #region validations //if (ddlRFromProj.SelectedIndex == 0) //{ // lblRErrorMsg.Text = "Select reallocate from project"; // ddlRFromProj.Focus(); // return; //} if (txtFromProjNum.Text == "") { lblRErrorMsg.Text = "Select reallocate from project"; txtFromProjNum.Focus(); return; } if (ddlRFromFund.Items.Count > 1 && ddlRFromFund.SelectedIndex == 0) { lblRErrorMsg.Text = "Select fund from reallocate from project"; ddlRFromFund.Focus(); return; } if (ddlRFromFundType.Items.Count > 1 && ddlRFromFundType.SelectedIndex == 0) { lblRErrorMsg.Text = "Select fund type from reallocate from project"; ddlRFromFundType.Focus(); return; } if (txtRToAmt.Text == "" || txtRfromAmt.Text == "" || Convert.ToDecimal(txtRfromAmt.Text) == 0 || Convert.ToDecimal(txtRToAmt.Text) == 0) { lblRErrorMsg.Text = "Please enter a non zero amount before proceed"; return; } //if (ddlRToProj.Items.Count > 1 && ddlRToProj.SelectedIndex == 0) //{ // lblRErrorMsg.Text = "Select reallocate to project"; // ddlRToProj.Focus(); // return; //} if (ddlRToFund.Items.Count > 1 && ddlRToFund.SelectedIndex == 0) { lblRErrorMsg.Text = "Select fund from reallocate to project"; ddlRToFund.Focus(); return; } if (ddlRtoFundType.Items.Count > 1 && ddlRtoFundType.SelectedIndex == 0) { lblRErrorMsg.Text = "Select fund type from reallocate to project"; ddlRtoFundType.Focus(); return; } if (Convert.ToInt32(txtRfromAmt.Text) < Convert.ToInt32(txtRToAmt.Text)) { lblRErrorMsg.Text = "Reallocate to amount can't be more than available reallocation from amount"; txtRToAmt.Focus(); return; } //if (ddlRFromProj.SelectedValue == ddlRToProj.SelectedValue) if (txtFromProjNum.Text == txtToProjNum.Text) { if (ddlRFromFund.SelectedValue.ToString() == ddlRToFund.SelectedValue.ToString()) { if (ddlRtoFundType.SelectedValue.ToString() == ddlRFromFundType.SelectedValue.ToString()) { lblRErrorMsg.Text = "Fund cannot be reallocated to same fund type. Reallocate to different fund type."; ddlRtoFundType.Focus(); return; } } } //if (hfTransId.Value != "" && hfRFromTransId.Value !="") //{ // DataTable dtIsDuplicate = new DataTable(); // dtIsDuplicate = FinancialTransactions.IsDuplicateReallocation(Convert.ToInt32(ddlRFromProj.SelectedValue.ToString()), Convert.ToInt32(hfRFromTransId.Value), Convert.ToInt32(hfTransId.Value)); // if (dtIsDuplicate.Rows.Count > 0) // { // lblRErrorMsg.Text = "A reallocation was already made to this Fund and can not be reallocated to same fund. Reallocate to different fund"; // ddlRToFund.Focus(); // return; // } //} if (hfBalAmt.Value != "") { if (Convert.ToDecimal(txtRToAmt.Text) > Convert.ToDecimal(hfBalAmt.Value)) { if (Convert.ToDecimal(hfBalAmt.Value) == 0) { lblRErrorMsg.Text = "Reallocation is complete, more funds not allowed"; return; } // txtRToAmt.Text = hfBalAmt.Value; lblRErrorMsg.Text = "Amount can not be more than available balance amount"; return; } } decimal n; bool availFunds = decimal.TryParse(lblAvailFund.Text.Trim(), out n); if (!availFunds || Convert.ToDecimal(txtRfromAmt.Text) > Convert.ToDecimal(lblAvailFund.Text)) { if (!availFunds) { lblRErrorMsg.Text = "Amount can't be more than available reallocate funds (" + CommonHelper.myDollarFormat(0) + ") for the selected from project"; } else { lblRErrorMsg.Text = "Amount can't be more than available reallocate from funds (" + CommonHelper.myDollarFormat(lblAvailFund.Text) + ") for the selected from project"; } txtRfromAmt.Focus(); return; } #endregion if (hfReallocateGuid.Value == "") { hfReallocateGuid.Value = Guid.NewGuid().ToString(); } DataTable dtable = new DataTable(); dtable = FinancialTransactions.AddBoardReallocationTransaction(Convert.ToInt32(hfProjId.Value.ToString()), txtFromProjNum.Text == txtToProjNum.Text ? Convert.ToInt32(hfProjId.Value.ToString()) : Convert.ToInt32(hfToProjId.Value.ToString()), Convert.ToDateTime(txtRfromDate.Text), Convert.ToInt32(ddlRFromFund.SelectedValue.ToString()), Convert.ToInt32(ddlRFromFundType.SelectedValue.ToString()), Convert.ToDecimal(txtRfromAmt.Text), Convert.ToInt32(ddlRToFund.SelectedValue.ToString()), Convert.ToInt32(ddlRtoFundType.SelectedValue.ToString()), Convert.ToDecimal(txtRToAmt.Text), hfRFromTransId.Value == "" ? nullable : Convert.ToInt32(hfRFromTransId.Value), hfTransId.Value == "" ? nullable : Convert.ToInt32(hfTransId.Value), hfReallocateGuid.Value.ToString()); hfRFromTransId.Value = dtable.Rows[0][0].ToString(); hfTransId.Value = dtable.Rows[0][1].ToString(); lblRErrorMsg.Text = "Reallocation was added successfully"; BindGvReallocate(Convert.ToInt32(hfProjId.Value.ToString())); ClearReallocationToPanel(); } catch (Exception ex) { lblRErrorMsg.Text = ex.Message; } }