Re: What a strange problem... by mathon
mathon
Thu Nov 11 09:23:03 CST 2004
Hello,
this is the code of the form, which displays in a picturebox a little map.
The strange thing is that the ObjectDisposeException only occurs when the SIP
is enabled..? (I omit the fields and begin the post with the constructor of
the Map class)
public Map()
{
this.dataSource = "\\Program Files\\MobileHelpDesk.sdf";
this.strConn = "Data Source = " + dataSource;
this.connection = new SqlCeConnection("Data Source = " + dataSource);
InitializeComponent();
btnBackButton = new ImageButton();
btnBackButton.Image = new Bitmap("\\My Documents\\ArrowLeft.bmp");
btnBackButton.Location = new Point(155, 38);
btnBackButton.Size = new Size(26, 26);
this.Controls.Add(btnBackButton);
btnBackButton.Click+=new EventHandler(this.btnBackButton_Click);
textBox1.Text="";
}
private void btnBackButton_Click(object sender, EventArgs e)
{
Details details = new Details();
details.Show();
this.Close();
this.Dispose();
}
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()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label22 = new System.Windows.Forms.Label();
this.label24 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SaveMap = new System.Windows.Forms.Button();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.panel1 = new System.Windows.Forms.Panel();
this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
this.button1 = new System.Windows.Forms.Button();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Size = new System.Drawing.Size(640, 480);
//
// label22
//
this.label22.Font = new System.Drawing.Font("Verdana", 12F,
((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold |
System.Drawing.FontStyle.Italic))));
this.label22.ForeColor = System.Drawing.Color.DarkOrange;
this.label22.Location = new System.Drawing.Point(8, 8);
this.label22.Size = new System.Drawing.Size(144, 20);
this.label22.Text = "Map";
//
// label24
//
this.label24.Font = new System.Drawing.Font("Verdana", 8.25F,
System.Drawing.FontStyle.Regular);
this.label24.Location = new System.Drawing.Point(184, 48);
this.label24.Size = new System.Drawing.Size(40, 16);
this.label24.Text = "Back";
//
// textBox1
//
this.textBox1.BackColor = System.Drawing.Color.Lavender;
this.textBox1.Location = new System.Drawing.Point(16, 248);
this.textBox1.Text = "textBox1";
//
// SaveMap
//
this.SaveMap.Location = new System.Drawing.Point(152, 248);
this.SaveMap.Text = "SaveMap";
this.SaveMap.Click += new System.EventHandler(this.SaveMap_Click);
//
// panel1
//
this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(16, 80);
this.panel1.Size = new System.Drawing.Size(208, 152);
//
// hScrollBar1
//
this.hScrollBar1.Location = new System.Drawing.Point(16, 232);
this.hScrollBar1.Maximum = 91;
this.hScrollBar1.Size = new System.Drawing.Size(208, 13);
this.hScrollBar1.ValueChanged += new System.EventHandler
this.hScrollBar1_ValueChanged);
//
// vScrollBar1
//
this.vScrollBar1.Location = new System.Drawing.Point(224, 80);
this.vScrollBar1.Maximum = 91;
this.vScrollBar1.Size = new System.Drawing.Size(13, 152);
this.vScrollBar1.ValueChanged += new
System.EventHandler(this.vScrollBar1_ValueChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 48);
this.button1.Text = "Delete";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Map
//
this.BackColor = System.Drawing.Color.LightBlue;
this.ClientSize = new System.Drawing.Size(250, 270);
this.Controls.Add(this.button1);
this.Controls.Add(this.vScrollBar1);
this.Controls.Add(this.hScrollBar1);
this.Controls.Add(this.panel1);
this.Controls.Add(this.SaveMap);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label24);
this.Controls.Add(this.label22);
this.Menu = this.mainMenu1;
this.Text = "Map";
this.Load += new System.EventHandler(this.Map_Load);
}
#endregion
private void Map_Load(object sender, System.EventArgs e)
{
LoadMap();
}
private void BindImage(object sender, ConvertEventArgs e)
{
e.Value = new Bitmap(new MemoryStream((byte[])e.Value));
}
private void SaveMap_Click(object sender, System.EventArgs e)
{
try
{
string email = Details.getEmailClient();
SqlCeCommand command = new SqlCeCommand();
connection.Open();
command.Connection = connection;
command.CommandText = "UPDATE Client SET Map=? WHERE Email=?";
command.Parameters.Add( "@Map", SqlDbType.Image);
command.Parameters.Add( "@Email", SqlDbType.NVarChar);
//Stream str =
Assembly.GetExecutingAssembly().GetManifestResourceStream("MobileHelpDesk.images."+textBox1.Text+".bmp");
Stream str =
Assembly.GetExecutingAssembly().GetManifestResourceStream("MobileHelpDesk.images.obere_augartenstraÃ?e.bmp");
byte[] data = new byte[str.Length];
str.Read(data, 0, (int)str.Length);
SqlBinary sBin = new SqlBinary(data);
command.Parameters[0].Size = sBin.Length;
command.Parameters[0].Value = sBin;
command.Parameters[1].Size = email.Length;
command.Parameters[1].Value = email;
command.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Map was saved!");
LoadMap();
textBox1.Text="";
}
catch(SqlCeException exSql)
{
connection.Close();
Replication.ShowSqlCeErrors(exSql);
}
catch (Exception ex)
{
connection.Close();
MessageBox.Show(ex.Message.ToString());
}
}
private void LoadMap()
{
try
{
string email = Details.getEmailClient();
SqlCeCommand command = new SqlCeCommand();
connection.Open();
command.Connection = connection;
command = connection.CreateCommand();
command.CommandText = "SELECT * FROM Client WHERE Email=?";
command.Parameters.Add("@Email", email);
SqlCeDataAdapter da = new SqlCeDataAdapter(command);
ds = new DataSet();
da.Fill(ds, "Client");
Binding b = new Binding("Image", ds.Tables["Client"], "Map");
b.Format += new ConvertEventHandler(BindImage);
pictureBox1.DataBindings.Add(b);
connection.Close();
}
catch(SqlCeException exSql)
{
connection.Close();
Replication.ShowSqlCeErrors(exSql);
}
catch (Exception ex)
{
connection.Close();
//MessageBox.Show("No map was saved for this client!");
MessageBox.Show(ex.Message.ToString());
}
}
private void vScrollBar1_ValueChanged(object sender, System.EventArgs e)
{
this.pictureBox1.Top = -(this.vScrollBar1.Value*5);
}
private void hScrollBar1_ValueChanged(object sender, System.EventArgs e)
{
this.pictureBox1.Left = -(this.hScrollBar1.Value*5);
}
Anybody an idea where the error is?:(
mathon