|
-
July 5th, 2009, 01:20 AM
#1
Accessibility of class in multiple forms
Code:
class cConnection
{
string MiningConString = @"data source=" + AppDomain.CurrentDomain.BaseDirectory + "miningdata.sdf";
public SqlCeConnection CN;
public SqlCeCommand Cmd;
public void OpenCon()
{
CN = new SqlCeConnection(MiningConString);
CN.Open();
Cmd = new SqlCeCommand();
Cmd.Connection = CN;
}
public void CloseCon()
{
Cmd.Dispose();
CN.Close();
CN.Dispose();
}
}
public class cSetting
{
public int ChatboxBottom = 0;
public int DeedBottom = 0;
public int MapSize = 1000;
public void GetSetting()
{
DataSet ds = new DataSet();
SqlCeDataAdapter adapter = new SqlCeDataAdapter();
DataTable dt;
cConnection CN = new cConnection();
CN.OpenCon();
String SQL = "Select * from tblSettings";
CN.Cmd.CommandText = SQL;
adapter.SelectCommand = CN.Cmd;
adapter.Fill(ds);
dt = ds.Tables[0];
String SettingName;
foreach (DataRow da in dt.Rows)
{
SettingName = da["settingname"].ToString();
switch (SettingName)
{
case "Chatbox bottom":ChatboxBottom = (int)da["intvalue"]; break;
case "Deed bottom": DeedBottom = (int)da["intvalue"]; break;
case "Map size (meters)": MapSize = (int)da["intvalue"]; break;
}
}
CN.CloseCon();
}
}
public partial class frmMain : Form
{
public cSetting Setting = new cSetting();
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
Setting.GetSetting();
}
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
frmSettings frmS = new frmSettings();
frmS.Show();
}
}
public partial class frmSettings : Form
{
public frmSettings()
{
InitializeComponent();
}
private void frmSettings_Load(object sender, EventArgs e)
{
//do something with frmMain.Setting
}
}
How can I access frmMain.Setting in frmSettings (and is the class structure of my program right or could it be coded better)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|