ASP.Net code:
<asp:DropDownList ID="ddlKid" runat="server" AutoPostBack="true" CssClass="ddlReports"
Width="160px" OnSelectedIndexChanged="ddlKid_SelectedIndexChanged">
</asp:DropDownList>
C# code:
protected void ddlKid_SelectedIndexChanged(object sender, EventArgs e)
{
int i = ddlKid.SelectedIndex;
count = i;
int KidId = int.Parse(KidArray[i].ToString());
ArrayList ADA = new ArrayList();
ADA.Add(FirstAssignment.SelectedItem);
ADA.Add(SecondAssignment.SelectedItem);
DrawTableNew(ADA, KidId);
}
protected void Page_Load(object sender, EventArgs e)
{
GameLib.Reports.ReportID = 6;
if (!IsPostBack)
{
FillGrades();
FillKids();
count = 0;
Label1.Visible = false;
FirstAssignment.Visible = false;
SecondAssignment.Visible = false;
L1st.Visible = false;
L2nd.Visible = false;
Header.Visible = false;
Label2.Visible = false;
Div2.Visible = false;
Panel1.Visible = false;
DwdTable.Visible = false;
DwdButton2.Visible = false;
pnlIssues.Visible = false;
Panel2.Visible = false;
}
else
{
FillGrades();
// FillKids();
}
}
protected void FillKids()
{
ddlKid.Visible = true;
try
{
if (GameUser.UserType == 1)
{
ddlKid.Items.Insert(0, new System.Web.UI.WebControls.ListItem(GameUser.UserName, GameUser.UserID.ToString()));
}
else
{
DataTable dt = new DataTable();
//dt = GameLib.GameUser.GetKidsForParent(GameUser.UserID);
dt = GameLib.GameUser.GetKidsForParentAsPerGrade(GameUser.UserID, ddlAssessment.SelectedItem.ToString());
for (int i = 0; i < dt.Rows.Count; i++)
{
int kidId = (int)dt.Rows[i]["intUserID"];
KidArray.Add(kidId);
}
if (dt.Rows.Count <= 0)
{
//MPEGrade.Show();
}
else
{
ddlKid.DataSource = dt;
ddlKid.DataTextField = "vchLoginName";
ddlKid.DataValueField = "vchGradeName";
ddlKid.DataBind();
}
}
}
catch
{
}
}
The problem is my ddlKid_SelectedIndexChanged is not executing. After page load it stops at else statement. Its code for fill kids(Adding drop down data).
The fill kid only called on the first that is !postback.
you can change binding value:
fill kids value like:
string vchLoginName=//login name from db;
string vchGradeName=//Grade name from db;
ddlKid.Items.Add(new ListItem(vchLoginName,vchGradeName));
Related
I have spent some time designing my first project using C#, it is a Windows form project with 8 buttons on the side. pressing one of the buttons will open another form within the parent form as a window. On clicking the button the new form loads up about 27 objects mostly Labels, Textboxes, Comboboxes and a few DateTimePickers. For some reason it you can see it drawing the boxes and it looks slow. I have an SQL db included with my project which is tiny and contains only 2 rows of data. It is very dishearting to spend all that time working on it only to see it run like a ZX Spectrum. I am using Microsoft Visual Studio 2019 and is fully updated. I have no errors, no warnings thank god but the performance is horrible. One of the comboBoxes when selected will make visible 3 more textBoxes and even making those visible is really slow. Is there something I am doing wrong or is there a way to have it working faster please?
This is the code of my childForm which opens from the main parentForm, sorry is is a bit long but it is all of it.
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace AvianManager.Forms
{
public partial class formMyBirds : Form
{
SqlConnection connection = new SqlConnection(#"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Dion\Documents\AvianManager.mdf;Integrated Security=True;Connect Timeout=30");
public formMyBirds()
{
InitializeComponent();
}
private void formMyBirds_Load(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
var form = Application.OpenForms["formMyBirdsHelper"]; // Lookup form and check if already open
if (form == null)
{
formMyBirdsHelper MyBirdsHelper = new formMyBirdsHelper(); // Instantiate a FormMyBirdsHelp object.
MyBirdsHelper.Show(); // Show FormMyBirdsHelp and
}
}
private void comboBoxLegBandType_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = this.comboBoxLegBandType.GetItemText(this.comboBoxLegBandType.SelectedItem);
if (selected != "None" || selected == null)
{
textBoxLegBandID.Visible = true;
labelLegBandId.Visible = true;
textBoxLegBandSize.Visible = true;
labelLegBandSize.Visible = true;
}
else
{
textBoxLegBandID.Visible = false;
labelLegBandId.Visible = false;
textBoxLegBandSize.Visible = false;
labelLegBandSize.Visible = false;
}
}
private void comboBoxPrevOwner_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = this.comboBoxPrevOwner.GetItemText(this.comboBoxPrevOwner.SelectedItem);
if (selected != "No")
{
textBoxLastOwnerName.Visible = true;
labelLastOwnerName.Visible = true;
textBoxLastOwnerFone.Visible = true;
labelLastOwnerFone.Visible = true;
textBoxLastOwnerAddr.Visible = true;
labelLastOwnerAddr.Visible = true;
}
else
{
textBoxLastOwnerName.Visible = false;
labelLastOwnerName.Visible = false;
textBoxLastOwnerFone.Visible = false;
labelLastOwnerFone.Visible = false;
textBoxLastOwnerAddr.Visible = false;
labelLastOwnerAddr.Visible = false;
}
}
private void comboBoxVitalStatus_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = this.comboBoxVitalStatus.GetItemText(this.comboBoxVitalStatus.SelectedItem);
if (selected != "Alive")
{
dateTimeDateOfDeath.Visible = true;
labelDateOfDeath.Visible = true;
textBoxCauseOfDeath.Visible = true;
labelCauseOfDeath.Visible = true;
}
else
{
dateTimeDateOfDeath.Visible = false;
labelDateOfDeath.Visible = false;
textBoxCauseOfDeath.Visible = false;
labelCauseOfDeath.Visible = false;
}
}
private void comboBoxRetained_SelectedIndexChanged(object sender, EventArgs e)
{
string selected = this.comboBoxRetained.GetItemText(this.comboBoxRetained.SelectedItem);
if (selected != "Yes")
{
dateTimeRelinquishedDate.Visible = true;
labelRelinquishedDate.Visible = true;
}
else
{
dateTimeRelinquishedDate.Visible = false;
labelRelinquishedDate.Visible = false;
}
}
private void textBoxUid_TextChanged(object sender, EventArgs e)
{
SqlCommand cmd1 = new SqlCommand("select top 1 * from dbMyBirds where db_Uid = '" + textBoxUid.Text + "'", connection);
cmd1.Parameters.AddWithValue("db_Uid", textBoxUid.Text);
SqlDataReader reader1;
connection.Open();
reader1 = cmd1.ExecuteReader();
if (reader1.Read())
{
labelResult.Text = "Found";
textBoxName.Text = reader1["db_Name"].ToString();
textBoxSpecies.Text = reader1["db_Species"].ToString();
comboBoxLegBandType.Text = reader1["db_LegBandType"].ToString();
textBoxLegBandID.Text = reader1["db_LegBandId"].ToString();
textBoxLegBandSize.Text = reader1["db_LegBandSize"].ToString();
comboBoxPrevOwner.Text = reader1["db_PrevOwner"].ToString();
textBoxLastOwnerName.Text = reader1["db_PrevOwnerName"].ToString();
textBoxLastOwnerFone.Text = reader1["db_PrevOwnerFone"].ToString();
textBoxLastOwnerAddr.Text = reader1["db_PrevOwnerAddr"].ToString();
comboBoxIsHybrid.Text = reader1["db_Hybrid"].ToString();
comboBoxRearedBy.Text = reader1["db_RearedBy"].ToString();
textBoxDisformaties.Text = reader1["db_Disformaties"].ToString();
comboBoxVitalStatus.Text = reader1["db_VitalStatus"].ToString();
dateTimeDateOfDeath.Text = reader1["db_DateDied"].ToString();
textBoxCauseOfDeath.Text = reader1["db_CauseOfDeath"].ToString();
comboBoxRetained.Text = reader1["db_Retained"].ToString();
dateTimeRelinquishedDate.Text = reader1["db_RelinquishedDate"].ToString();
dateTimeHatchDate.Text = reader1["db_HatchDate"].ToString();
dateTimeFledgeDate.Text = reader1["db_FledgeDate"].ToString();
comboBoxMaleParentHybrid.Text = reader1["db_MPisHybrid"].ToString();
textBoxMaleParentId.Text = reader1["db_MPUid"].ToString();
textBoxMaleParentSpecies.Text = reader1["db_MPSpecies"].ToString();
comboBoxHenParentHybrid.Text = reader1["db_FPisHybrid"].ToString();
textBoxHenParentId.Text = reader1["db_FPUid"].ToString();
textBoxHenParentSpecies.Text = reader1["db_FPSpecies"].ToString();
textBoxNotes.Text = reader1["db_Notes"].ToString();
}
else
{
resetInputs();
if (textBoxUid.Text == "")
{
labelResult.Text = "Live Search";
}
else
{
labelResult.Text = "Nothing Found";
}
}
connection.Close();
}
//Reset input fields if no results
private void resetInputs()
{
string dt2;
DateTime date2 = DateTime.Now;
dt2 = date2.ToShortDateString(); // display format: 15/07/2021
textBoxName.Text = "";
textBoxSpecies.Text = "";
comboBoxLegBandType.Text = "Select";
textBoxLegBandID.Text = "";
textBoxLegBandSize.Text = "";
comboBoxPrevOwner.Text = "Select";
textBoxLastOwnerName.Text = "";
textBoxLastOwnerFone.Text = "";
textBoxLastOwnerAddr.Text = "";
comboBoxIsHybrid.Text = "Select";
comboBoxRearedBy.Text = "Select";
textBoxDisformaties.Text = "";
comboBoxVitalStatus.Text = "Select";
dateTimeDateOfDeath.Text = dt2;
textBoxCauseOfDeath.Text = "";
comboBoxRetained.Text = "Select";
dateTimeRelinquishedDate.Text = dt2;
dateTimeHatchDate.Text = dt2;
dateTimeFledgeDate.Text = dt2;
comboBoxMaleParentHybrid.Text = "Select";
textBoxMaleParentId.Text = "";
textBoxMaleParentSpecies.Text = "";
comboBoxHenParentHybrid.Text = "Select";
textBoxHenParentId.Text = "";
textBoxHenParentSpecies.Text = "";
textBoxNotes.Text = "";
}
private void buttonInsert_Click(object sender, EventArgs e)
{
}
}
}
I have a field named country in Invoice.aspx form. I have the below code.
invoice.aspx
<asp:DropDownList ID="lstCountryy" runat="server" Width="216px" Height="27px" AutoPostback="false">
</asp:DropDownList>
invoice.aspx.cs
lstCountryy.SelectedValue = dtInquiry.Rows[0]["country"].ToString();
Page load:
protected void Page_Load(object sender, EventArgs e)
{
txtTotal.Attributes.Add("readonly", "readonly");
txtvatt.Attributes.Add("readonly", "readonly");//added by chetan
txtDiscount.Attributes.Add("readonly", "readonly");//added by chetan
txtAmountInWords.Attributes.Add("readonly", "readonly");
if (!IsPostBack)
{
loadInvoiceDetails();
//SetAllCountries();//added by chetan
if (lstCountryy.SelectedValue == "U.A.E" || lstCountryy.SelectedValue == "BAHRAIN" || lstCountryy.SelectedValue == "SAUDI ARABIA")
{
txtvat.Text = "";
txtvatt.Text = "";
txtBankCharge.Text = "";
txtDiscount.Text = "";
txtDiscountText.Text = "";
txtTotal.Text = "";
vattr.Style.Add("display", "float");
trdeclaration.Visible = false;
//txtvat.Enabled = true;
}
else
{
txtvat.Text = "";
txtvatt.Text = "";
txtBankCharge.Text = "";
txtDiscount.Text = "";
txtDiscountText.Text = "";
txtTotal.Text = "";
vattr.Style.Add("display", "none");
trdeclaration.Visible = true;
}
}
}
Bind dropdownlist:
protected void SetAllCountries()
{
try
{
string queryStrUserType = "SELECT country_id,country_name FROM crm_countries";
ClassDtBaseConnect clsDtResult = new ClassDtBaseConnect();
DataTable dt = clsDtResult.GetDataTable(queryStrUserType);
lstCountryy.DataSource = dt;
lstCountryy.DataValueField = "country_id";
lstCountryy.DataTextField = "country_name";
lstCountryy.DataBind();
lstCountryy.Items.Insert(0, "--Select--");
}
catch (Exception Ex)
{
}
}
dtInquiry is my Inquiry table in which country field is there and I am fetching the value from inquiry form to invoice form. I am not getting the selected value; it shows blank (""). I don't know what's wrong with that. I am a beginner in C#.
I was not getting the selected value.It should be like this: SetAllCountries Should be first and then loadinvoicedetails.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetAllCountries();
loadInvoiceDetails();
.....
.....
}
}
I have a MetroFramework.Controls.MetroGrid in my windows forms application. In frmPatientList_Shown I call a method loadPatientList(). I also add a DataGridViewLinkColumn after binding the dtb to the gridview.
Clicking the link opens a new form where I update Patient data, and on formEditPatient.FormClosed I call the loadPatientList() method again, This time the DataGridViewLinkColumn is being added twice. How can I prevent to Add the link twice ?
Here is my code:
private void frmPatientList_Shown(object sender, EventArgs e)
{
loadPatientList();
}
private void loadPatientList()
{
DataTable dtb = Patient.getPatientList();
bindToGrid(dtb);
}
private void bindToGrid(DataTable dtb)
{
dataGridView1.DataSource = null;
using (dtb)
{
dataGridView1.DataSource = dtb;
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns[0].Name = "PatientId";
dataGridView1.Columns[0].HeaderText = "ID";
dataGridView1.Columns[0].DataPropertyName = "PatientId";
// more code here.
}
DataGridViewLinkColumn EditLink = new DataGridViewLinkColumn();
EditLink.UseColumnTextForLinkValue = true;
EditLink.HeaderText = " Edit ";
EditLink.DataPropertyName = "lnkColumn";
EditLink.LinkBehavior = LinkBehavior.SystemDefault;
EditLink.Text = "Edit";
dataGridView1.Columns.Add(EditLink);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 8 && e.RowIndex >= 0)
{
using (frmEditPatient formEditPatient = new frmEditPatient(id))
{
formEditPatient.FormClosed += FormEditPatient_FormClosed;
formEditPatient.ShowDialog();
}
}
}
private void FormEditPatient_FormClosed(object sender, FormClosedEventArgs e)
{
loadPatientList();
}
Any help would be appreciated.
You check if the column exist,
bool hasEditColumn = false;
foreach (DataGridViewColumn item in dataGridView1.Columns)
{
if (item.GetType() == typeof(DataGridViewLinkColumn) && item.HeaderText == "Edit")
{
hasEditColumn = true;
break;
}
}
if (!hasEditColumn)
{
DataGridViewLinkColumn EditLink = new DataGridViewLinkColumn();
EditLink.UseColumnTextForLinkValue = true;
EditLink.HeaderText = "Edit";
EditLink.DataPropertyName = "lnkColumn";
EditLink.LinkBehavior = LinkBehavior.SystemDefault;
EditLink.Text = "Edit";
dataGridView1.Columns.Add(EditLink);
dataGridView1.Refresh();
}
In frmPatientList_Shown function you add the link
private void frmPatientList_Shown(object sender, EventArgs e)
{
DataGridViewLinkColumn EditLink = new DataGridViewLinkColumn();
EditLink.UseColumnTextForLinkValue = true;
EditLink.HeaderText = " Edit ";
EditLink.DataPropertyName = "lnkColumn";
EditLink.LinkBehavior = LinkBehavior.SystemDefault;
EditLink.Text = "Edit";
dataGridView1.Columns.Add(EditLink);
loadPatientList();
}
In bindToGrid function you do not add the link
private void bindToGrid(DataTable dtb)
{
dataGridView1.DataSource = null;
using (dtb)
{
dataGridView1.DataSource = dtb;
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns[0].Name = "PatientId";
dataGridView1.Columns[0].HeaderText = "ID";
dataGridView1.Columns[0].DataPropertyName = "PatientId";
// more code here.
}
//DataGridViewLinkColumn EditLink = new DataGridViewLinkColumn();
//EditLink.UseColumnTextForLinkValue = true;
//EditLink.HeaderText = " Edit ";
//EditLink.DataPropertyName = "lnkColumn";
//EditLink.LinkBehavior = LinkBehavior.SystemDefault;
//EditLink.Text = "Edit";
//dataGridView1.Columns.Add(EditLink);
}
I hope it will help you.
I'm new to asp.net and needs some help. I have a gridview with paging for every 20 records per page, I have a search button outside the gridview. What I need to do is when I click the search button, the results must be bind to gridview(which is happening now), however when the records are more than the pagesize and I need to go to the next page of the grid, the binding is lost and the binded records are the ones form the page on load event. below is my code sample.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
public void BindData()
{
{
List<EventFile> eventFile = new List<EventFile>();
eventFile = CoMailAssociationDAL.GetUploadFileUnAssigned(0, "", "", "U");
if (gvwAssociation.DataSource == null)
{
gvwAssociation.DataSource = eventFile;
gvwAssociation.DataBind();
}
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
int uFlag = 0;
string uploadFlag = this.ddlUploadDate.SelectedValue;
string fileName = this.txtSearchText.Text;
string uploadDt = this.txtDate.Text;
string status = this.ddlStatus.SelectedValue.ToString();
bt = true;
if (status == "Un-Assigned")
{
status = "U";
}
else if (status == "Assigned")
{
status = "A";
}
else
{
status = "B";
}
if ((uploadFlag == "On") && (uploadDt == ""))
{
uFlag = 0;
}
else if (uploadFlag == "On")
{
uFlag = 1;
}
else if (uploadFlag == "OnorBefore")
{
uFlag = 2;
}
else
{
uFlag = 3;
}
fileSearch = CoMailAssociationDAL.SearchFile(uFlag, fileName, uploadDt, status);
gvwAssociation.DataSource = fileSearch;
gvwAssociation.DataBind();
}
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//SaveSelectedValues();
gvwAssociation.PageIndex = e.NewPageIndex;
//BindData();
//PopulateSelectedValues();
}
First of all you should have the following event handler for paging
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwAssociation.PageIndex = e.NewPageIndex;
bindGridWithFilter();
}
Then, move your search/ filter logic within the search button to a private method (say "bindGridWithFilter")
TIP: Try to combine both BindData and bindGridWithFilter so when there's no filter you display all records
UPDATE
Here's some refactored code for you to get an idea what I meant above.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGridWithFilter();
}
}
protected void gvwAssociation_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvwAssociation.PageIndex = e.NewPageIndex;
bindGridWithFilter();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
bindGridWithFilter();
}
private void bindGridWithFilter()
{
List<EventFile> eventFile = new List<EventFile>();
eventFile = CoMailAssociationDAL.GetUploadFileUnAssigned(0, "", "", "U");
if (gvwAssociation.DataSource == null)
{
// If you don't have a filter you show all records
gvwAssociation.DataSource = eventFile;
gvwAssociation.DataBind();
}
else
{
// This is same as the logic in your search button
// display only the filtered records
int uFlag = 0;
string uploadFlag = this.ddlUploadDate.SelectedValue;
string fileName = this.txtSearchText.Text;
string uploadDt = this.txtDate.Text;
string status = this.ddlStatus.SelectedValue.ToString();
bt = true;
if (status == "Un-Assigned")
{
status = "U";
}
else if (status == "Assigned")
{
status = "A";
}
else
{
status = "B";
}
if ((uploadFlag == "On") && (uploadDt == ""))
{
uFlag = 0;
}
else if (uploadFlag == "On")
{
uFlag = 1;
}
else if (uploadFlag == "OnorBefore")
{
uFlag = 2;
}
else
{
uFlag = 3;
}
List<EventFile> fileSearch = CoMailAssociationDAL.SearchFile(uFlag, fileName, uploadDt, status);
gvwAssociation.DataSource = fileSearch;
gvwAssociation.DataBind();
}
}
This should work.
Need your help guys.
I have a web application which hangs after clicking a checkbox which is set to autopostback. This checkbox is supposed to do some process.
It didn't fire the OnPreLoad and the OnLoad events.
Below are the codes
protected override void BindReference()
{
BindComboBox(ref rcbPortfolioId, CNPL_Portfolio.GetPortfolioDicWithAll());
BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll());
BindComboBox(ref rcbNewAgencyId, CNPL_Agency.GetAgencyDicWithAll());
BindComboBox(ref rcbPreviousAgencyId, CNPL_Agency.GetAgencyDicWithAll());
BindComboBox(ref rcbAccountStatusId, CNPL_AccountStatus.GetStatusDic());
BindComboBox(ref rcbAgencyHeader, CNPL_Agency.GetAgencyDic());
}
protected override void SetViewStates()
{
ViewState["ETemp"] = eTemp;
ViewState["AgencyIDRgTemp"] = _AgencyIDRgTemp;
ViewState["PreviousIDRgTemp"] = _PreviousIDRgTemp;
ViewState["ProductIDRgTemp"] = _ProductIDRgTemp;
ViewState["IsRetainedRgTemp"] = _IsRetainedRgTemp;
}
protected override void GetViewStates()
{
if (ViewState["ETemp"] != null)
{
eTemp = (List<CNPL_EndorsementTemp>)ViewState["ETemp"];
}
if (ViewState["AgencyIDRgTemp"] != null)
{
_AgencyIDRgTemp = (int)ViewState["AgencyIDRgTemp"];
}
if (ViewState["PreviousIDRgTemp"] != null)
{
_PreviousIDRgTemp = (int)ViewState["PreviousIDRgTemp"];
}
if (ViewState["ProductIDRgTemp"] != null)
{
_ProductIDRgTemp = (int)ViewState["ProductIDRgTemp"];
}
if (ViewState["IsRetainedRgTemp"] != null)
{
_IsRetainedRgTemp = (bool)ViewState["IsRetainedRgTemp"];
}
}
protected void chkEndorseAuto_OnCheckChange(object sender, EventArgs e)
{
DirectDBAccess db = new DirectDBAccess();
SqlCommand cmd = new SqlCommand("dbo.Proc_UpdateIsIncludedEndorsementTemp");
Int32 _AgencyID=0;
Int32 _PreviousAgencyID=0;
Int32 _IsRetained=0;
Int32 _ProductID=0;
Int32 _IsIncluded=0;
Int32 _NewIsIncluded = 0;
CheckBox cBox = (sender as CheckBox);
GridDataItem item = (cBox.Parent.Parent as GridDataItem);
if (!Int32.TryParse(item["AgencyID"].Text, out _AgencyID))
throw new Exception("Endorsement: Error in parsing");
if (!Int32.TryParse(item["PreviousAgencyID"].Text, out _PreviousAgencyID))
throw new Exception("Endorsement: Error in parsing");
if (!Int32.TryParse(item["ProductID"].Text, out _ProductID))
throw new Exception("Endorsement: Error in parsing");
if (item["IsRetained"].Text.ToLower() == "true")
_IsRetained = 1;
else if (item["IsRetained"].Text.ToLower() == "false")
_IsRetained = 0;
else
throw new Exception("Endorsement: Error in parsing");
if (cBox.Checked)
{
_NewIsIncluded = 1;
_IsIncluded = 0;
}
else
{
_NewIsIncluded = 0;
_IsIncluded = 1;
}
cmd.CommandTimeout = 9500;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("#AgencyID",_AgencyID));
cmd.Parameters.Add(new SqlParameter("#PreviousAgencyID", _PreviousAgencyID));
cmd.Parameters.Add(new SqlParameter("#IsRetained", _IsRetained));
cmd.Parameters.Add(new SqlParameter("#ProductID", _ProductID));
cmd.Parameters.Add(new SqlParameter("#IsIncluded", _IsIncluded));
cmd.Parameters.Add(new SqlParameter("#NewIsIncluded", _NewIsIncluded));
db.Open();
db.CommandExecuteNonQuery(cmd,CommandType.StoredProcedure);
db.Close();
}
void rcbPortfolioId_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
Int32 _PortfolioID;
_PortfolioID = Int32.Parse(rcbPortfolioId.SelectedValue);
if(_PortfolioID >0)
BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll(_PortfolioID));
else
BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll());
}
private void InitializeEndorsementDate()
{
int curingDays;
if (!Int32.TryParse(CNPL_DataSettings.GetSettingValue("CuringPeriod").ToString(), out curingDays))
curingDays = 120;
rdpEndorsementDateFrom.SelectedDate = DateTime.Now;
rdpEndorsementDateTo.SelectedDate = DateTime.Now.AddDays(curingDays - 1);
}
private void InitializeGrids()
{
rgEndorsements.DataSource = new List<CNPL_EndorsementTemp>();
rgEndorsements.DataBind();
//Added by Ryan Estandarte 11/2/2010
rgEndorsements.AllowPaging = true;
rgEndorsements.PageSize = 10;
rgEndorsementTemp.DataSource = new List<CNPL_EndorsementTemp>();
rgEndorsementTemp.DataBind();
}
public Dictionary<int, string> PopulateRgAgencyId()
{
return CNPL_Agency.GetAgencyDic();
}
void btnSearch_Click(object sender, EventArgs e)
{
AssignAccountToEndorsementTemp();
RadAjaxManager1.Alert("finished automatic distribution");
}
private void BindRgEndorsements()
{
rgEndorsements.DataSource = CNPL_EndorsementTemp.GetGroupedEndorsementTemp();
rgEndorsements.DataBind();
}
private void ClearTotals()
{
rntbTotalAccounts.Text = "";
rntbTotalPrincipal.Text = "";
rntbTotalPenalty.Text = "";
rntbTotalInterest.Text = "";
rntbTotalOutstandingBalance.Text = "";
}
private void ShuffleAgencies(ref List<CNPL_Agency> agencyToShuffle)
{
int N = agencyToShuffle.Count;
Random random = new System.Random();
for (int index = 0; index < N; ++index)
{
int randomIndex = index + (int)(random.Next(N - index));
CNPL_Agency _agencyTemp = agencyToShuffle[randomIndex];
agencyToShuffle[randomIndex] = agencyToShuffle[index];
agencyToShuffle[index] = _agencyTemp;
}
}
private void AssignAccountToEndorsementTemp()
{
DirectDBAccess db = new DirectDBAccess();
SqlCommand cmd = new SqlCommand();
string sql;
InitializeGrids();
sql = "dbo.Proc_AssignAccountsForEndorsement";
cmd.CommandText = sql;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 59500;
cmd.Parameters.Add(new SqlParameter("#PortfolioID_Criteria",Int32.Parse(rcbPortfolioId.SelectedValue)));
cmd.Parameters.Add(new SqlParameter("#ProductID_Criteria",Int32.Parse(rcbProductId.SelectedValue)));
cmd.Parameters.Add(new SqlParameter("#NewAgencyID_Criteria",Int32.Parse(rcbNewAgencyId.SelectedValue)));
cmd.Parameters.Add(new SqlParameter("#PreviousAgencyID_Criteria",Int32.Parse(rcbPreviousAgencyId.SelectedValue)));
db.Open();
db.CommandExecuteNonQuery(cmd,CommandType.StoredProcedure);
db.Close();
BindRgEndorsements();
}
void rgEndorsements_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "btnDetails")
{
int pageSize = 10;
if (chkPagingManual.Checked == true)
{
rgEndorsementTemp.AllowPaging = true;
Int32.TryParse(rntbPageSizeManual.Text, out pageSize);
rgEndorsementTemp.PageSize = pageSize;
}
else
rgEndorsementTemp.AllowPaging = false;
_AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["AgencyId"].Text);
_PreviousIDRgTemp = Int32.Parse((e.Item as GridDataItem)["PreviousAgencyId"].Text);
_ProductIDRgTemp = Int32.Parse((e.Item as GridDataItem)["ProductID"].Text);
_IsRetainedRgTemp = Boolean.Parse((e.Item as GridDataItem)["IsRetained"].Text);
BindRgEndorsementTemp();
}
else if (e.CommandName == "btnChange")
{
IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
RadComboBox rcbAgencyId = (RadComboBox)(e.Item as GridDataItem).FindControl("rcbAgency");
int _AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
UpdateEndorsement(e.Item as GridDataItem);
Helper.SaveList(endorsementTemps,this.Web.CurrentUser.LoginName);
//rebind rgEndosements
BindRgEndorsements();
//rebind RgEndorsementTemp w/ respect to agencyid being edited
_AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["AgencyId"].Text);
_PreviousIDRgTemp = Int32.Parse((e.Item as GridDataItem)["PreviousAgencyId"].Text);
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
}
protected void chkEndorseAutoHeader_OnCheckChange(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
CheckBox chkHeader = sender as CheckBox;
foreach (GridDataItem item in rgEndorsements.Items)
{
chk = (CheckBox)item.FindControl("chkEndorseAuto");
chk.Checked = chkHeader.Checked;
}
IncludeAll(chkHeader.Checked);
}
private void IncludeAll(Boolean chk)
{
DirectDBAccess db = new DirectDBAccess();
string sql;
if(chk == true)
sql = "update CNPL_EndorsementTemp set IsIncluded='True'";
else
sql = "update CNPL_EndorsementTemp set IsIncluded='False'";
SqlCommand cmd = new SqlCommand(sql);
db.Open();
db.CommandExecuteNonQuery(cmd, CommandType.Text);
db.Close();
}
private IList<CNPL_EndorsementTemp> UpdateEndorsement(GridDataItem tempGridDataItem)
{
//update endorsementtemp to database
IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
RadComboBox rcbAgencyId = (RadComboBox)tempGridDataItem.FindControl("rcbAgency");
Int32 _AgencyID = Int32.Parse(tempGridDataItem["AgencyID"].Text);
Int32 _PreviousAgencyID = Int32.Parse(tempGridDataItem["PreviousAgencyID"].Text);
string _IsRetained = tempGridDataItem["IsRetained"].Text;
Int32 _ProductID = Int32.Parse(tempGridDataItem["ProductID"].Text);
string filter = string.Format("Where AgencyID={0} And PreviousAgencyID={1} And IsRetained='{2}' And ProductID={3}", _AgencyID, _PreviousAgencyID, _IsRetained, _ProductID);
endorsementTemps = CNPL_EndorsementTemp.GetAllWithFilter(filter);
foreach (CNPL_EndorsementTemp endorsementTemp in endorsementTemps)
{
endorsementTemp.AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
}
return endorsementTemps;
}
private IList<CNPL_EndorsementTemp> UpdateEndorsementAllChecked(GridDataItem tempGridDataItem)
{
//update endorsementtemp to database
IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
Int32 _AgencyID = Int32.Parse(tempGridDataItem["AgencyID"].Text);
Int32 _PreviousAgencyID = Int32.Parse(tempGridDataItem["PreviousAgencyID"].Text);
string filter = string.Format("Where AgencyID={0} And PreviousAgencyID={1}", _AgencyID, _PreviousAgencyID);
endorsementTemps = CNPL_EndorsementTemp.GetAllWithFilter(filter);
foreach (CNPL_EndorsementTemp endorsementTemp in endorsementTemps)
{
endorsementTemp.AgencyID = Int32.Parse(rcbAgencyUpdateAuto.SelectedValue);
}
return endorsementTemps;
}
void btnUpdateAutoAll_Click(object sender, EventArgs e)
{
List<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
//IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
foreach (GridDataItem item in rgEndorsements.Items)
{
CheckBox chk = new CheckBox();
chk = (CheckBox)item.FindControl("chkEndorseAuto");
if (chk.Checked == true)
{
endorsementTemps.AddRange(UpdateEndorsementAllChecked(item));
}
}
if (endorsementTemps.Count > 0)
Helper.SaveList(endorsementTemps, this.Web.CurrentUser.LoginName);
BindRgEndorsements();
_AgencyIDRgTemp = 0;
_PreviousIDRgTemp = 0;
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
void btnEndorse_Click(object sender, EventArgs e)
{
EndorseToAgencies();
RadAjaxManager1.Alert("finished endorsement");
}
private void EndorseToAgencies()
{
DirectDBAccess db = new DirectDBAccess();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "dbo.Proc_EndorseToAgencies";
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 59500;
cmd.Parameters.Add(new SqlParameter("#User", Web.CurrentUser.LoginName));
cmd.Parameters.Add(new SqlParameter("#EndorsementDateFrom", rdpEndorsementDateFrom.SelectedDate));
cmd.Parameters.Add(new SqlParameter("#EndorsementDateTo", rdpEndorsementDateTo.SelectedDate));
db.Open();
db.CommandExecuteNonQuery(cmd, CommandType.StoredProcedure);
db.Close();
BindRgEndorsements();
_AgencyIDRgTemp = 0;
_PreviousIDRgTemp = 0;
BindRgEndorsementTemp();
}
private IList<CNPL_EndorsementDetail> ConvertEndorsementTempToDetails()
{
IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
IList<CNPL_EndorsementDetail> details = new List<CNPL_EndorsementDetail>();
temps = CNPL_EndorsementTemp.GetAll();
details.Clear();
foreach (CNPL_EndorsementTemp temp in temps)
{
CNPL_EndorsementDetail detail = new CNPL_EndorsementDetail();
CNPL_Account _account = new CNPL_Account();
_account = CNPL_Account.GetByID(temp.AccountID);
detail.Account = _account;
detail.Account.IsCurrentlyEndorsed = true;
if (detail.Account.NewAgencyID != 0)
{
detail.Account.PreviousAgencyID = detail.Account.NewAgencyID;
}
detail.Account.EndorsementDateTo = rdpEndorsementDateTo.SelectedDate;
detail.Account.EndorsementDateFrom = rdpEndorsementDateFrom.SelectedDate;
detail.Account.NewAgencyID = temp.AgencyID;
detail.AccountID = temp.AccountID;
detail.AgencyID = temp.AgencyID;
detail.CreatedBy = this.Web.CurrentUser.LoginName;
detail.CreatedDate = DateTime.Now;
details.Add(detail);
}
return details;
}
void rgEndorsementTemp_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "btnChange")
{
RadComboBox rcbAgencyId = (RadComboBox)(e.Item as GridDataItem).FindControl("rcbAgency");
int _AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
UpdateEndorsementTemp(e.Item as GridDataItem);
BindRgEndorsements();
_AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["OldAgencyID"].Text);
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
}
private void BindRgEndorsementTemp()
{
rgEndorsementTemp.DataSource = CNPL_EndorsementTemp.GetDetailsEndorsementTemp(_AgencyIDRgTemp,_PreviousIDRgTemp,_ProductIDRgTemp,_IsRetainedRgTemp);
rgEndorsementTemp.DataBind();
}
private void UpdateEndorsementTemp(GridDataItem tempGridDataItem)
{
CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
Int32 _ID = Int32.Parse(tempGridDataItem["EndorsementTempID"].Text);
_EndorsementTemp = CNPL_EndorsementTemp.GetByID(_ID);
RadComboBox rcbAgencyId = (RadComboBox)tempGridDataItem.FindControl("rcbAgency");
_EndorsementTemp.AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
_EndorsementTemp.AccountID = Int32.Parse(tempGridDataItem["AccountID"].Text);
_EndorsementTemp.Save();
}
protected void chkEndorseManualHeader_OnCheckChange(object sender, EventArgs e)
{
CheckBox chk = new CheckBox();
CheckBox chkHeader = sender as CheckBox;
foreach (GridDataItem item in rgEndorsementTemp.Items)
{
chk = (CheckBox)item.FindControl("chkEndorseManual");
chk.Checked = chkHeader.Checked;
}
}
void rgEndorsementTemp_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
rgEndorsementTemp.DataSource = CNPL_EndorsementTemp.GetDetailsEndorsementTemp(_AgencyIDRgTemp, _PreviousIDRgTemp, _ProductIDRgTemp, _IsRetainedRgTemp);
}
void btnUpdateManualAll_Click(object sender, EventArgs e)
{
IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
foreach (GridDataItem item in rgEndorsementTemp.Items)
{
CheckBox chk = new CheckBox();
chk = (CheckBox)item.FindControl("chkEndorseManual");
if(chk.Checked == true)
{
CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
Int32 _ID = Int32.Parse(item["EndorsementTempID"].Text);
_EndorsementTemp = CNPL_EndorsementTemp.GetByID(_ID);
_EndorsementTemp.AgencyID = Int32.Parse(rcbAgencyHeader.SelectedValue);
_EndorsementTemp.AccountID = Int32.Parse(item["AccountID"].Text);
temps.Add(_EndorsementTemp);
}
}
if (temps.Count > 0)
Helper.SaveList(temps, this.Web.CurrentUser.LoginName);
BindRgEndorsements();
BindRgEndorsementTemp();
RadAjaxManager1.Alert("Updated");
}
private void GetAccountPerCollectorRatio()
{
accountCollectorRatios = CNPL_AccountCollectorRatio.GetAll();
}
void btnSearchManualAdd_Click(object sender, EventArgs e)
{
if (rbAccountNoMA.Checked == true)
{
if (txtAccountNoMA.Text.Length > 0)
accounts = CNPL_Account.GetAccountLikeAccountNo(txtAccountNoMA.Text);
else
RadAjaxManager1.Alert("Requires search parameter");
}
else if (rbAccountNameMA.Checked == true)
{
if(txtAccountNameMA.Text.Length > 0)
accounts = CNPL_Account.GetAccountLikeAccountName(txtAccountNameMA.Text);
else
RadAjaxManager1.Alert("Requires search parameter");
}
BindRgManualAdd();
}
private void BindRgManualAdd()
{
rgManualAdd.DataSource = accounts;
rgManualAdd.DataBind();
}
void rgManualAdd_ItemCommand(object source, GridCommandEventArgs e)
{
CNPL_Account _Account = CNPL_Account.GetByID(Int32.Parse((e.Item as GridDataItem)["AccountID"].Text));
if (e.CommandName == "btnAdd")
{
CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
List<CNPL_EndorsementTemp> _EndorsementTemps = (List<CNPL_EndorsementTemp>)CNPL_EndorsementTemp.GetAll();
_EndorsementTemp.AccountID = _Account.Id;
_EndorsementTemp.ProductID = _Account.ProductID;
_EndorsementTemp.CurrentBalance = _Account.CurrentBalance;
_EndorsementTemp.AgencyID = _Account.NewAgencyID; Int32.Parse((e.Item as GridDataItem)["NewAgencyID"].Text);
_EndorsementTemp.PreviousAgencyID = _Account.NewAgencyID; Int32.Parse((e.Item as GridDataItem)["PreviousAgencyID"].Text);
_EndorsementTemp.IsRetained = _Account.IsCurrentlyEndorsed==true?true:false;
_EndorsementTemp.IsIncluded = true;
if (_EndorsementTemps.Exists(delegate(CNPL_EndorsementTemp temp) { return temp.AccountID == _EndorsementTemp.AccountID; }))
{
RadAjaxManager1.Alert(_Account.AccountName + " already exists");
}
else
{
_EndorsementTemp.Save(Web.CurrentUser.LoginName);
BindRgEndorsements();
}
}
}
void chkUseManualAdd_CheckedChanged(object sender, EventArgs e)
{
if (!CNPL_EndorsementTemp.DeleteEndorsementTemp())
throw new Exception("endorsement: cannot clear temporary table");
if (chkUseManualAdd.Checked == true)
{
pnlManualAdd.Visible = true;
btnSearch.Enabled = false;
BindRgEndorsements();
BindRgManualAdd();
}
else
{
pnlManualAdd.Visible = false;
btnSearch.Enabled = true;
}
}
protected override void OnInit(EventArgs e)
{
try
{
rcbPortfolioId.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(rcbPortfolioId_SelectedIndexChanged);
btnSearch.Click += new EventHandler(btnSearch_Click);
btnEndorse.Click += new EventHandler(btnEndorse_Click);
tnUpdateManualAll.Click += new EventHandler(btnUpdateManualAll_Click);
rgEndorsements.ItemCommand += new GridCommandEventHandler(rgEndorsements_ItemCommand);
rgEndorsements.NeedDataSource += new GridNeedDataSourceEventHandler(rgEndorsements_NeedDataSource);
rgEndorsementTemp.ItemCommand += new GridCommandEventHandler(rgEndorsementTemp_ItemCommand);
rgEndorsementTemp.NeedDataSource += new GridNeedDataSourceEventHandler(rgEndorsementTemp_NeedDataSource);
rgEndorsements.ItemEvent += new GridItemEventHandler(rgEndorsements_ItemEvent);
btnSearchManualAdd.Click += new EventHandler(btnSearchManualAdd_Click);
rgManualAdd.ItemCommand += new GridCommandEventHandler(rgManualAdd_ItemCommand);
chkUseManualAdd.CheckedChanged += new EventHandler(chkUseManualAdd_CheckedChanged);
btnViewDistributed.Click += new EventHandler(btnViewDistributed_Click);
btnPullout.Click += new EventHandler(btnPullout_Click);
base.OnInit(e);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
protected void UpdateAgency(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
int newAgencyID = 0;
RadComboBox newAgencyDropdown = sender as RadComboBox;
foreach (GridDataItem item in rgEndorsements.Items)
{
newAgencyDropdown = (RadComboBox)item.FindControl("rcbAgency");
Int32 _AgencyID = Int32.Parse(item["AgencyID"].Text);
newAgencyID = int.Parse(newAgencyDropdown.SelectedValue);
if (_AgencyID != newAgencyID)
{
Int32 _PreviousAgencyID = Int32.Parse(item["PreviousAgencyID"].Text);
string _IsRetained = item["IsRetained"].Text;
Int32 _ProductID = Int32.Parse(item["ProductID"].Text);
DirectDBAccess db = new DirectDBAccess();
string sqlEndorse = string.Format("UPDATE CNPL_EndorsementTemp SET AgencyID={0} Where AgencyID={1} And PreviousAgencyID={2} And IsRetained='{3}' And ProductID={4}", newAgencyID, _AgencyID, _PreviousAgencyID, _IsRetained, _ProductID);
SqlCommand cmd = new SqlCommand(sqlEndorse);
db.Open();
db.CommandExecuteNonQuery(cmd, CommandType.Text);
db.Close();
break;
}
}
BindRgEndorsements();
}
protected override void OnUnload(EventArgs e)
{
try
{
base.OnUnload(e);
Locker.inUse = false;
Locker.isCompleted = true;
Locker.user = "";
}
catch (Exception ex)
{
string message = ex.Message;
}
}
protected override void OnLoad(EventArgs e)
{
try
{
Server.ScriptTimeout = 9500;
if (Locker.inUse == true && Locker.isCompleted == false && Locker.user.ToLower() != this.Web.CurrentUser.LoginName.ToLower())
{
Response.Redirect("error.aspx?innerException=Another User is already accessing endorsement&pageFrom=Endorsement To Agency"); //throw new Exception("Another user is already processing endorsement");
}
Locker.inUse = true;
Locker.isCompleted = false;
Locker.user = this.Web.CurrentUser.LoginName;
security = new Security(this.Web.CurrentUser);
userGroups = security.GetUserGroups();
if (userGroups.Contains(SecurityGroups.Star))
{
;
}
else if (userGroups.Contains(SecurityGroups.Agency))
{
Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
}
else if (userGroups.Contains(SecurityGroups.TeamCollector))
{
Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
}
else
Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
if (!Page.IsPostBack)
{
BindReference();
InitializeGrids();
InitializeEndorsementDate();
rbAccountNoMA.Checked = true;
chkUseManualAdd.Checked = false;
pnlManualAdd.Visible = false;
}
else
{
GetViewStates();
}
base.OnLoad(e);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
protected override void OnPreRender(EventArgs e)
{
try
{
ComputeEndorsementTotals();
SetViewStates();
base.OnPreRender(e);
}
catch (Exception ex)
{
string message = ex.Message;
}
}
}
There is an error somewhere in your OnInit
Try placing try catch blocks around each step and step into (not over) each function in there to see if you have any problems.
My guess is you have a try...catch with an empty catch statement - otherwise you'd have an exception to deal with.
We really need to see the code behind, its probably obvious to some of us here when we see the code.
I found the answer to my problem.
There's one event that is not used, and it is this.
rgEndorsements.ItemEvent += new GridItemEventHandler(rgEndorsements_ItemEvent);
It seems that we must check if all the events that are "instantiated" are being used. Thanks for your suggestions! Highly appreciate it.