Programmer:Create BCE.Data.DBSetting with Database Info: Difference between revisions
Content added Content deleted
No edit summary |
mNo edit summary |
||
Line 9: | Line 9: | ||
<syntaxhighlight lang="csharp"> |
<syntaxhighlight lang="csharp"> |
||
private DevExpress.XtraEditors.LookUpEdit lueDatabase = new DevExpress.XtraEditors.LookUpEdit(); |
private DevExpress.XtraEditors.LookUpEdit lueDatabase = new DevExpress.XtraEditors.LookUpEdit(); |
||
//Object mydbInfo is optional, if the setting of database info is directly write to file or database |
//Object mydbInfo is optional, if the setting of database info is directly write to file or database |
||
private SelectedDatabaseInfo mydbInfo; |
private SelectedDatabaseInfo mydbInfo; |
||
Line 16: | Line 17: | ||
:You may use other control to get user selection. Below example is using LookupEdit of DevExpress control. |
:You may use other control to get user selection. Below example is using LookupEdit of DevExpress control. |
||
:Highlighted lines are the key to obtain Database Info that has been maintained in AutoCount Accounting 1.8. |
:Highlighted lines are the key to obtain Database Info that has been maintained in AutoCount Accounting 1.8. |
||
<syntaxhighlight lang="csharp" highlight=" |
<syntaxhighlight lang="csharp" highlight="4-7"> |
||
internal void InitiateDatabaseInfoLookup(System.Windows.Forms.Control parent) |
internal void InitiateDatabaseInfoLookup(System.Windows.Forms.Control parent) |
||
{ |
{ |
||
//Get the database info that has been maintained in AutoCount Accounting |
|||
DataTable dtDBInfo = |
DataTable dtDBInfo = |
||
BCE.AutoCount.DatabaseManagement.Default.DatabaseManager |
BCE.AutoCount.DatabaseManagement.Default.DatabaseManager |
Revision as of 10:32, 11 January 2018
This example uses DevExpress components. |
When create a form Setting for user to maintain which Database to link/integrate, often we do not know where to obtain the account book setting in AutoCount Accounting. This example shows how to get Database Info that is maintained and stored in AutoCount Accounting.
1. Create a DevExpress Lookup Edit object in the class as private
private DevExpress.XtraEditors.LookUpEdit lueDatabase = new DevExpress.XtraEditors.LookUpEdit();
//Object mydbInfo is optional, if the setting of database info is directly write to file or database
private SelectedDatabaseInfo mydbInfo;
2. Call a method to Load the Lookup Edit with data of Database Info.
- You may use other control to get user selection. Below example is using LookupEdit of DevExpress control.
- Highlighted lines are the key to obtain Database Info that has been maintained in AutoCount Accounting 1.8.
internal void InitiateDatabaseInfoLookup(System.Windows.Forms.Control parent)
{
//Get the database info that has been maintained in AutoCount Accounting
DataTable dtDBInfo =
BCE.AutoCount.DatabaseManagement.Default.DatabaseManager
.DatabaseInfoTable.DefaultView.ToTable(
false, new string[] { "CompanyName", "Remark", "DatabaseName", "ServerName" });
lueDatabase.Properties.DataSource = dtDBInfo;
lueDatabase.Properties.ValueMember = "DatabaseName";
lueDatabase.Properties.DisplayMember = "CompanyName";
lueDatabase.Properties.NullText = "";
lueDatabase.Location = new System.Drawing.Point(10, 10);
lueDatabase.Size = new System.Drawing.Size(300, lueDatabase.Size.Height);
parent.Controls.Add(lueDatabase);
}
3. Create a class to store Selected Database Info [Optional, you may direct save the value to file or database]
internal class SelectedDatabaseInfo
{
public string CompanyName { get; set; }
public string Remark { get; set; }
public string DBName { get; set; }
public string SvrName { get; set; }
}
4. On Form closing or when perform saving, store the database info.
- Sample code here will store in an object of SelectedDatabaseInfo.
private void OnFormCloseOrOnSaveSetting()
{
DataRowView row = lueDatabase.GetSelectedDataRow() as DataRowView;
if (row != null)
{
mydbInfo = new SelectedDatabaseInfo();
mydbInfo.CompanyName = row["CompanyName"].ToString();
mydbInfo.Remark = row["Remark"].ToString();
mydbInfo.DBName = row["DatabaseName"].ToString();
mydbInfo.SvrName = row["ServerName"].ToString();
}
}
5. Write your algorithm to save the selected Database Info for linking/integration.
6. Create BCE.Data.DBSetting object, with the selected database info. The return value of DBSetting may be null, if connection info is wrong.
internal BCE.Data.DBSetting GetConnectionToAutoCount(SelectedDatabaseInfo dbInfo)
{
if (dbInfo == null)
{
//throw or log error.
}
return new BCE.Data.DBSetting(BCE.Data.DBServerType.SQL2000, dbInfo.SvrName, dbInfo.DBName);
}
Go to top
|
Resources For AutoCount Software Developers
|