protected void btn_Confirm_Click(object sender, EventArgs e) { CheckExchange(); if (tx_FromEntity.Text.Equals("") || tx_ToEntity.Text.Equals("")) { Alert(" You have to select [ From cloumn ] or [ To Entity ] . "); return; } if (tx_Amount.Text.Equals("")) { Alert(" You have to key in To Amount . "); return; } if (tx_FromAmount.Text.Equals("")) { Alert(" You have to key in From Amount . "); return; } string regex = "^[0-9]{0,5}$|^[0-9]{0,5}\\.[0-9]{0,2}$ "; System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) | System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options); if (!reg.IsMatch(tx_Amount.Text)) { Alert(" Please check Amount column . "); return; } using (DataEntryServiceClient _client = new DataEntryServiceClient()) { PeriodServiceClient _pclient = new PeriodServiceClient(); Period _period = new PeriodCollection(_pclient.GetCurrentPeriod())[0]; int _FromEntityID = Convert.ToInt32(lb_FromEntityID.Text); int _ToEntityID = Convert.ToInt32(lb_ToEntityID.Text); decimal _Amount = Convert.ToDecimal(tx_Amount.Text); decimal _FromAmount = Convert.ToDecimal(tx_FromAmount.Text); if ((bool)Session["IsAdd"]) { Transaction _tran = new Transaction(); _tran.Period.ID = _period.ID; _tran.IsPay = IsPay.N; _tran.Creator.UserID = Convert.ToInt32(Session["Userid"]); _tran.Amount = _FromAmount; _tran.FromEntity.EntityID = _FromEntityID; _tran.ToEntity.EntityID = _ToEntityID; _tran.FromCurrency = lb_FromCurrency.Text; _tran.ToCurrency = lb_ToCurrency.Text; _tran.ExchangeRate = Convert.ToDecimal(tx_ExchangeRate.Text); _tran.To_Amount = _Amount; _client.InsertTransaction(_tran); mp1.Hide(); GetData(_period); } else { Transaction _tran = new TransactionCollection(_client.LoadTransactionByID(Convert.ToInt32(lb_ID.Text)))[0]; _tran.FromEntity.EntityID = _FromEntityID; _tran.ToEntity.EntityID = _ToEntityID; _tran.Amount = _FromAmount; _tran.To_Amount = _Amount; _tran.FromCurrency = lb_FromCurrency.Text; _tran.ToCurrency = lb_ToCurrency.Text; _tran.ExchangeRate = Convert.ToDecimal(tx_ExchangeRate.Text); _client.Updatetransaction(_tran); mp1.Hide(); GetData(_period); } } if(Session["Rowindex"]!=null) gv_Transaction.Rows[Convert.ToInt32(Session["Rowindex"])].BackColor = System.Drawing.ColorTranslator.FromHtml("#023e91"); }
protected void gv_Transaction_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer; int id = Convert.ToInt32(gv_Transaction.DataKeys[row.RowIndex].Values[0]); string _FromEntityID =gv_Transaction.DataKeys[row.RowIndex].Values[1].ToString(); string _ToEntityID = gv_Transaction.DataKeys[row.RowIndex].Values[2].ToString(); using (DataEntryServiceClient _client = new DataEntryServiceClient()) { PeriodServiceClient _pclient = new PeriodServiceClient(); Period _period = new PeriodCollection(_pclient.GetCurrentPeriod())[0]; if (e.CommandName.Equals("Btn_Notice")) { _client.SetNotices(id, Convert.ToInt32(Session["Userid"])); GetData(_period); } else if (e.CommandName.Equals("Btn_Confirm")) { Transaction _tran = new TransactionCollection(_client.LoadTransactionByID(id))[0]; _tran.Updater.UserID = Convert.ToInt32(Session["Userid"]); _tran.Period = _period; _client.SetConfirm(_tran); GetData(_period); } else if (e.CommandName.Equals("Btn_Edit")) { Session["IsAdd"] = false; tx_FromEntity.Text = gv_Transaction.Rows[row.RowIndex].Cells[0].Text ; tx_ToEntity.Text = gv_Transaction.Rows[row.RowIndex].Cells[2].Text; tx_Amount.Text = gv_Transaction.Rows[row.RowIndex].Cells[5].Text; lb_FromEntityID.Text = _FromEntityID; lb_ToEntityID.Text = _ToEntityID; lb_FromCurrency.Text = gv_Transaction.Rows[row.RowIndex].Cells[1].Text; lb_ToCurrency.Text = gv_Transaction.Rows[row.RowIndex].Cells[3].Text; tx_ExchangeRate.Text = gv_Transaction.Rows[row.RowIndex].Cells[4].Text; btn_Confirm.Text = ""; lb_ID.Text = id.ToString(); up_Edit.Update(); Session["Rowindex"] = row.RowIndex; mp1.Show(); } gv_Transaction.Rows[row.RowIndex].BackColor = System.Drawing.ColorTranslator.FromHtml("#023e91"); } }