private void Cbnum_selectedindexchanged (object sender, EventArgs e)
{
Fieldlistlug.clear ();//continue to clear fields
if (Cbtype.text = = a)//select a
{
String killedstring = "";
killedstring = "id,lugnumber,q1,q2,dnx,dnd,th,kg";
DataTable tbsize =getaccessdata ("y_support_lug_4712_3_2007_a");
Fieldlistlug = Tbsize.getfieldlist (killedstring);
String TypeName = "y_support_lug_4712_3_2007_a";//query Table A
string where = string. Format ("Lugnumber = {0}",
Cbnum.text);//define query criteria
Tbvalue = Getaccessdata (TypeName, Fieldlistlug, where);//Isolate the required table
}
else if (Cbtype.text = = b)//select B
{
String killedstring = "";//define Remove field
killedstring = "id,lugnumber,q1,q2,dnx,dnd,th,kg";//Remove some useless fields
DataTable tbsize = Getaccessdata ("y_support_lug_4712_3_2007_a");//Lookup table
Fieldlistlug = Tbsize.getfieldlist (killedstring);//Get the field list after removal
String TypeName = "Y_support_lug_4712_3_2007_b";//define Query table
string where = string. Format ("Lugnumber = {0}",
Cbnum.text);//define Conditions
Tbvalue = Getaccessdata (TypeName, Fieldlistlug, where);//Isolate the required table data after removing useless information
}
else if (Cbtype.text = = c)//select C
{
String killedstring = "";
killedstring = "id,lugnumber,q1,q2,dnx,dnd,th,kg";
DataTable tbsize = Getaccessdata ("y_support_lug_4712_3_2007_a");
Fieldlistlug = Tbsize.getfieldlist (killedstring);
String TypeName = "Y_support_lug_4712_3_2007_c";
string where = string. Format ("Lugnumber = {0}",
Cbnum.text);
Tbvalue = Getaccessdata (TypeName, Fieldlistlug, where);
}
}
private void Button1_Click (object sender, EventArgs e)
{
Supportlug Lug = new PV. Supportlug ();//Instantiate Lug object
if (TbValue.Rows.Count > 1)
MessageBox.Show ("The number of support lines is wrong!") If there are multiple rows of data in the table, the error is determined.
Point3D pt = ed. GetPoint ();//get user pick points
if (pt = = null)
Return
Lug.pinsertmain = pt;//Sets the user selection point to the insertion point
foreach (String str in fieldlistlug)//Cyclic Assignment object
{
Try
{
Object obj = tbvalue.rows[0][str];//out the objects in the data table.
String fieldvalue = obj. ToString ();
Lug.gettype (). GetProperty (str). SetValue (Lug, obj, null);//Assigning an object to a field
}
catch (SystemException ex)//If the error shows missing fields
{
Ed. Writemessage ("\ n" + str + "XXX" + tbvalue.rows[0][str]);
Ed. Writemessage ("\ nthe error line starts \ n:" + ex.) Stacktrace.tostring ());//contains an error statement and an error line
Ed. Writemessage ("\ntargetsite:" + ex.) Targetsite.tostring ());
Return
}
catch (Autodesk.AutoCAD.Runtime.Exception Exx)
{
Ed. Writemessage ("\ n error Line start:" + Exx.) Message.tostring ());
Ed. Writemessage ("\nsource:" + Exx. Source.tostring ());
Ed. Writemessage ("\nstacktrace:" + Exx. Stacktrace.tostring ());
Return
}
}
Lug.db = db;//Defining the Graphics database
using (Transaction trans = db). Transactionmanager.starttransaction ())//Add things
{
Lug.draw ();//Draw a diagram
Trans.commit ();//Submit
}
}
Constructs from form obtains the database data, removes the useless information in the database, assigns the value to the field, finally draws the diagram