Log in

View Full Version : forms


adamdavies
02-23-2004, 03:21 AM
I am using C# & SQL CE. Im finding my forms loading are extremely slow.
Also i would like the forms to load so that you cannot see the GUI being drawn.

An example of how a form loads.
I do an update on the SQL DB before i close the form i am currently leaving. The DB record is all ready created so only an update is needed.
On the new form that is being loaded i do a check to see whether any data exsists in the DB that has been previously entered for that particular form.
I am not using indexes as there'll only be around 5 records in the DB at one time.

EXAMPLE CODE:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Resources;
using System.IO;
using System.Data;
using System.Data.SqlServerCe;
using patientREADYmobile.Common;
using patientREADYmobile.Business;
using System.Data.Common;
using System.Text.RegularExpressions;
using System.Xml;
using DateTimePickerControl;


namespace patientREADYmobile
{
/// <summary>
/// Summary description for PInfoFrm.
/// </summary>
public class PInfoFrm : System.Windows.Forms.Form
{
public static string adddetails;
private const string m_strFileName = "\\Program Files\\patientREADYmobile\\Configurations.xml";
static public string MaleOrFemale;
static public string Male = "M";
static public string Female = "F";
static public string DOB;
static public string PchkInterpretor;
static public string PchkAborTSI;
static public string YesNo = "Y";
static public string todaydate;
static public string TYearUpDown;
static public int IAgeUpDown;
private PictureButton btnExpand;
private Icon iconOpened;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage PInfo_1Tab;
private System.Windows.Forms.RadioButton btnF;
private System.Windows.Forms.RadioButton btnM;
private System.Windows.Forms.Label AgeLbl;
private System.Windows.Forms.Label DOBLbl;
private System.Windows.Forms.TextBox MiddleNameTxt;
private System.Windows.Forms.Label MiddleNameLbl;
private System.Windows.Forms.TextBox txtGivenName;
private System.Windows.Forms.TextBox txtFamilyName;
private System.Windows.Forms.ComboBox cmbTitle;
private System.Windows.Forms.Label GivenNameLbl;
private System.Windows.Forms.Label FamilyNameLbl;
private System.Windows.Forms.Label TitleLbl;
private System.Windows.Forms.TabPage PInfo_2Tab;
private System.Windows.Forms.CheckBox chkInterpretor;
private System.Windows.Forms.CheckBox chkAborTSI;
private System.Windows.Forms.Label StateLbl;
private System.Windows.Forms.ComboBox StatecomboBox1;
private System.Windows.Forms.TextBox NumStTxt;
private System.Windows.Forms.Label NumStLbl;
private System.Windows.Forms.Label TownSubLbl2;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.NumericUpDown MonthUpDown;
private System.Windows.Forms.NumericUpDown DayUpDown;
private System.Windows.Forms.NumericUpDown UnderUpDown;
private System.Windows.Forms.Label UnderLbl;
private System.Windows.Forms.NumericUpDown AgeUpDown;
private System.Windows.Forms.Label YearLbl;
private System.Windows.Forms.Label MonthLbl;
private System.Windows.Forms.Label DayLbl;
private System.Windows.Forms.NumericUpDown YearUpDown;
private System.Windows.Forms.Label LanguageLbl;
private System.Windows.Forms.ComboBox LanguageCombo;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.TextBox TownSubTxt;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private System.Windows.Forms.RadioButton LocRadio1;
private System.Windows.Forms.RadioButton LocRadio2;
private System.Windows.Forms.Label DetailsLbl;


public PInfoFrm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

InitializeControls();

//
// TODO: Add any constructor code after

}
private void InitializeControls()
{

ResourceManager resMan = new ResourceManager("patientREADYmobile.localimages",this.GetType().Assembly);
iconOpened = ((System.Drawing.Icon)(resMan.GetObject("i_folder_opened")));

//
// btnExpand
//
this.btnExpand = new PictureButton();
btnExpand.BackColor = System.Drawing.SystemColors.Control;
btnExpand.Icon=iconOpened;
btnExpand.Location = new System.Drawing.Point(210,0);
btnExpand.Size = new System.Drawing.Size(32, 23);
btnExpand.Click += new System.EventHandler(this.btnExpand_Click);
btnExpand.Left=210;
this.Controls.Add(btnExpand);
btnExpand.BringToFront();

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//LOAD ALL FORM TOOLS

}
#endregion


private void PInfoFrm_Load(object sender, System.EventArgs e)
{
//Populate ComboBoxes
XmlTextReader ComboReader = null;
ComboReader = new XmlTextReader (m_strFileName);
while (ComboReader.Read())
{
if (ComboReader.NodeType == XmlNodeType.Element)
{
if (ComboReader.LocalName.Equals("Languages"))
{
LanguageCombo.Items.Add(ComboReader.ReadString());
}

}
}
SqlCeConnection cn = null;
try
{

cn = new SqlCeConnection("Data Source = \\Program Files\\Database\\patientREADYmobile.sdf; Password=axisaxis");
cn.Open();
SqlCeCommand cmd = cn.CreateCommand();
//Select everything from the table.
cmd.CommandText = "SELECT * FROM tblPatientDetails where RecordNum = '"+ Tab.RecordNumber +"'";
SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);

for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
Tab.RecordNum = ds.Tables[0].Rows[i]["RecordNum"].ToString();
}

if (Tab.RecordNumber == Tab.RecordNum)
{
for(int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
DOB = ds.Tables[0].Rows[j]["DOB"].ToString();
PchkInterpretor = ds.Tables[0].Rows[j]["Interpreter"].ToString();
PchkAborTSI = ds.Tables[0].Rows[j]["AborTSI"].ToString();
MaleOrFemale = ds.Tables[0].Rows[j]["MaleFemale"].ToString();
}
txtGivenName.DataBindings.Add("Text", ds.Tables[0], "FName");
cmbTitle.DataBindings.Add("Text", ds.Tables[0], "Title");
txtFamilyName.DataBindings.Add("Text", ds.Tables[0], "SName");
NumStTxt.DataBindings.Add("Text", ds.Tables[0], "Address");
TownSubTxt.DataBindings.Add("Text", ds.Tables[0], "TownSuburb");
StatecomboBox1.DataBindings.Add("Text", ds.Tables[0], "State");
AgeUpDown.DataBindings.Add("Text", ds.Tables[0], "Age");
UnderUpDown.DataBindings.Add("Text", ds.Tables[0], "Month");
LanguageCombo.DataBindings.Add("Text", ds.Tables[0], "Language");
MiddleNameTxt.DataBindings.Add("Text", ds.Tables[0], "Middle");

if (PchkInterpretor == YesNo)
{
chkInterpretor.Checked = true;
}
if (PchkAborTSI == YesNo)
{
chkAborTSI.Checked = true;
}
if (MaleOrFemale == Male)
{
btnM.Checked = true;
}
if (MaleOrFemale == Female)
{
btnF.Checked = true;
}
if (DOB == "")
{
}
else
{
Regex r = new Regex("/"); // Split DOB
string[] s = r.Split(DOB);

DayUpDown.Text = s[0];
MonthUpDown.Text = s[1];
YearUpDown.Text = s[2];
}
}
else
{
cn.Close();
}

}
catch(SqlCeException sqlex)
{
foreach(SqlCeError sqlError in sqlex.Errors)
{
MessageBox.Show(sqlError.Message);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if(cn.State!=ConnectionState.Closed)
{
cn.Close();
}
}

tabControl1.SelectedIndex = Tab.tabctrl;
DetailsLbl.Text = Tab.PatientDetail;
}


//Home Button
private void btnExpand_Click(object sender, System.EventArgs e)
{//Main Menu
EDITDB();
MenuFrm newForm = new MenuFrm();
newForm.Show();
this.Close();
}


public void EDITDB()
{//Update Database

PHCREdit phcrEdit = new PHCREdit();
phcrEdit.Update(Tab.RecordNumber,this.cmbTitle.Text,this.txtFamilyName.Text,this.txtGivenName.Text,this.MiddleNameTxt.Text,this.NumStTxt.Text,this.TownSubTxt.Text,this.StatecomboBox1.Text,MaleOrFemale,DOB,this.AgeUpDown.Text,this.UnderUpDown.Text,PchkInterpretor,PchkAborTSI,this.LanguageCombo.Text);
}

private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{//Toolbar
EDITDB();
if(e.Button == this.toolBarButton1)
{
PHCR_Info PHCR_InfoForm = new PHCR_Info();
PHCR_InfoForm.ShowDialog();
this.Close();
}
else if(e.Button == this.toolBarButton2)
{
TimesFrm TimesForm = new TimesFrm();
TimesForm.ShowDialog();
this.Close();
}
else if(e.Button == this.toolBarButton3)
{
TransportInfoFrm TransportInfoForm = new TransportInfoFrm();
TransportInfoForm.ShowDialog();
this.Close();
}


}

Thanks
Adam