Using system.drawing; using system.collections; using system.windows.form; using system.data; using system.data.sqlclient;
A summary description description of Namespace mstdetail {///
DataSet TotalData; bindingmanagerbase bm; int = 0; DataSet1 DS1 = New DataSet1 ();
private System.Windows.Forms.GroupBox groupBox; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label3; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button3; private System.Windows.Forms.Button button4; private System.Windows.Forms.DataGrid dataGrid2; private System.Windows.Forms.DataGrid dataGrid3; private System.Windows.Forms.Button button5; private System.Windows.Forms.Button button6; private System.Windows.Forms.Button button7; private System.Windows.Forms.Button button8; private System.Windows.Forms.Button button9; private System.Windows.Forms.Button button10; private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1; // DataSet DS = New Dataset ();
///
///
#Region Windows Form Designer Generated Code ///
/// summary> private void initializecomponent () {this.groupbox = new system.windows.forms.groupbox (); this.Label3 = new system.windows.forms.Label (); this.label2 = new system. Windows.Forms.Label (); this.label1 = new system.windows.forms.label (); this.textBox3 = new system.windows.forms.textbox (); this.textbox2 = new system.windows.Forms.TextBox (); This.button1 = new system.windows.Forms.Button (); this .form2 = new system.windows.Forms.Button (); this. button3 = new System.Windows.Forms.Button (); this.button4 = new System.Windows.Forms.Button (); this.dataGrid2 = new System.Windows.Forms.DataGrid (); this.dataGrid3 = new System. Windows.Forms.DataGrid (); this.button5 = new system.windows.Forms.Button () (); this.button6 = new system.windows.Forms.Button (); this.button7 = new system.windows.Forms.Button (); This.button8 = new system.windows.Forms.Button (); this.button9 = new system.windows.Forms.Button (); this.button10 = new System.Windows.Forms.Button (); this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer (); this.groupBox.SuspendLayout (); ((System.ComponentModel.ISupportInitialize) (this.dataGrid2 ))). Begininit (); (this.DataGrid3)). BeginInit (); this.suspendlayout ();
// // groupbox // this.groupbox.controls.addrange (new system.windows.forms.control [] {this.label3, this.label2, this.label1, this.textbox3, this.textbox2, this.textbox1} This.groupbox.location = new system.drawing.point (8, 40); this.groupbox.name = "groupbox"; this.groupbox.size = new system.drawing.size (728, 56); this. Groupbox.tabindex = 0; this.groupbox.tabstop = false; /// Label3 // this.label3.Location = new system.drawing.point (480, 24); this.label3.name = "label3"; this .label3.tabindex = 5; this.label3.text = "status"; this.label3.textalign = system.drawing.contentAlignment.topright; // // label2 // this.label2.location = new system.drawing.point = new system.drawing.point (8, 24); this.label2.name = "label2"; this.label2.tabindex = 4; this.label2.text = "Company number"; this.Label2.TextAlign = system.drawing.contentAlignment.toprig ht; // // label1 // this.label1.Location = new system.drawing.point (240, 24); this.label1.name = "label1"; this.label1.tabindex = 3; this.label1.text = "Company Name"; this.label1.textalign = system.drawing.contentalignment.topright; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // TEXTBOX3.LOCATION = New System.drawing.Point (592, 24); this.TextBox3.name = "textBox3"; this.textBox3.Tabindex = 2; this.textBox3.tag = "status"; this.textbox3.text = ""; /// textbox2 // this.TextBox2 .Enabled = false;
This.TextBox2.Location = new system.drawing.point (352, 24); this.TextBox2.name = "textbox2"; this.TextBox2.tabindex = 1; this.TextBox2.tag = "CompanyName"; this.TextBox2. Text = ""; // // textBox1 // this.textBox1.enabled = false; this.textbox1.location = new system.drawing.point (112, 24); this.TextBox1.name = "textbox1"; this. TEXTBOX1.TABINDEX = 0; this.textBox1.tag = "support"; this.textbox1.text = ""; /// Button1 // this.button1.location = new system.drawing.point (8, 8); This.button1.name = "button1"; this.button1.size = new system.drawing.size (48, 23); this.button1.tabindex = 1; this.button1.text = "the most"; this.Button1. Click = new system.eventhandler (this.button1_click); // // button2 // this.button2.location = new system.drawing.point (64, 8); this.button2.name = "button2"; this. Button2.size = new system.drawing.size (48, 23); this.button2.tabindex = 2; this.button2.text = "forward"; this.button2.click = new system.e VENTHANDLER (this.button2_click); // // Button3 // this.button3.location = new system.drawing.point (120, 8); this.button3.name = "button3"; this.button3.size = new system .Drawing.size (48, 23); this.button3.tabindex = 3; this.button3.text = "back"; this.button3.click = new system.eventhandler (this.button3_click); //// Button4 // this.button4.location = new system.drawing.point (176, 8); this.button4.name = "button4"; this.button4.size = new system.drawing.size (48, 23);
This.button4.tabindex = 4; this.button4.text = "last"; this.button4.click = new system.eventhandler (this.button4_click); // // DataGrid2 // this.DataGrid2.DataMember = "" ; this.dataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText; this.dataGrid2.Location = new System.Drawing.Point (368, 104); this.dataGrid2.Name = "dataGrid2"; this.dataGrid2.Size = new System.Drawing.Size (360, 96); this.dataGrid2.TabIndex = 6; // // dataGrid3 // this.dataGrid3.DataMember = ""; this.dataGrid3.HeaderForeColor = System.Drawing.SystemColors.ControlText; this .dataGrid3.location = new system.drawing.point (8, 104); this.dataGrid3.name = "dataGrid3"; this.DataGrid3.size = new system.drawing.size (352, 96); this.DataGrid3.tabindex = 7; // // button5 // this.button5.location = new system.drawing.point (272, 8); this.button5.name = "button5"; this.button5.size = new system.drawing.size (48, 23); this.button5.tabindex = 8; this.button5.text = "New"; this.button5.click = new system.eventhandler (this.button5_click); // // button6 // this.button6.location = new system.drawing.point (328, 8); this.button6 .Name = "button6"; this.button6.size = new system.drawing.size (48, 23); this.button6.tabindex = 9; this.button6.text = "modification"; this.button6.click = New system.eventhandler (this.button6_click); // // Button7 // this.button7.location = new system.drawing.point (384, 8); this.button7.name = "button7"; this.button7.size =
New system.drawing.size (48, 23); this.button7.tabindex = 10; this.button7.text = "invalid"; this.button7.click = new system.eventhandler (this.button7_click); // / / Button8 // this.button8.enabled = false; this.button8.location = new system.drawing.point (440, 8); this.button8.name = "button8"; this.button8.size = new system.drawing .Size (48, 23); this.button8.tabindex = 11; this.button8.text = "Delete"; this.button8.click = new system.eventhandler (this.button8_click); // // Button9 // This.Button9.Location = new system.drawing.point (496, 8); this.button9.name = "button9"; this.button9.size = new system.drawing.size (48, 23); this.button9. Tabindex = 12; this.button9.text = "OK"; this.button9.click = new system.eventhandler (this.button9_click); // // button10 // this.button10.location = new system.drawing.point (552, 8); this.button10.name = "button10"; this.button10.size = new system.drawing.size (48, 23); this.button10.tabindex = 13; this.button10.Text = "Cancel"; this.button10.Click = new System.EventHandler (this.button10_Click); // // crystalReportViewer1 // this.crystalReportViewer1.ActiveViewIndex = -1; this.crystalReportViewer1.Location = new System.Drawing.Point (8, 208); this.crystalReportViewer1.Name = "crystalReportViewer1"; this.crystalReportViewer1.ReportSource = null; this.crystalReportViewer1.Size = new System.Drawing.Size (720, 296); this.crystalReportViewer1 . TabINDEX = 14; // // Form1 // this.autoscalebasesize =
new System.Drawing.Size (6, 14); this.ClientSize = new System.Drawing.Size (736, 517); this.Controls.AddRange (new System.Windows.Forms.Control [] {this.crystalReportViewer1, this .button10, this.button9, this.button8, this.button7, this.button6, this.button5, this.dataGrid3, this.dataGrid2, this.button4, this.button3, this.button2, this.button1, this.groupbox }); This.name = "form1"; this.text = "form1"; this.load = new system.eventhandler (this.form1_load); this.groupBox.ResumeLayout (false); ((System.componentModel.isupportInitialize) (this.DataGrid2))))))))))). Endinit (); ("this.DataGrid3)). endinit (); this.ResumeLayout (false);} #ENDREGION
///
public ArrayList Adapters {get {SqlConnection myCn = new SqlConnection (cString); ArrayList SqlDataAdapters = new ArrayList (TableNameTotal.Length); for (int i = 0; i Return SqldataAdapters;}} public DataSet ExecuteTotalData () {SqlConnection myCn = new SqlConnection (cString); try {for (int i = 0; i public bool UpdateDB (DataSet TotalDS) {SqlConnection myCn = new SqlConnection (cString); try {for (int i = 0; i Return true;} catch (exception ex) {messagebox.show (ex.Message, "system"); return false;} finally {mycn.close ();}} Private void form1_load (object sender, system.eventargs e) {this.refreshDataSource (); Private void refreshDataSource () {this.totaldata = new dataset (); TotalData = this.executeTotAldata (); this.bindcontrol (); this.binddataGrid (); this.bm = this.BindingContext [this.TotalData.Tables [ "Suppliers"]]; this.PosRefreshButton (); this.OpRefreshBtn ( "Default");} private void BindControl () {foreach (Control ctl in this.groupBox .Controls) {if (ctl.tag! = Null) {CTL.DATABINDINGS.CLEAR ();}} Foreach (Control CTL in this.groupbox.controls) {if (ctl.tag! = null) {CTL.DATABINDINGS.ADD (New Binding ("Text", TotalData.Tables ["Suppliers"], CTL.Tag.toString ( )))))); . Private void BindDataGrid () {DataColumn parentColumn = TotalData.Tables [ "Suppliers"] Columns [ "SupplierID"];. DataColumn childColumn = TotalData.Tables [ "Products"] Columns [ "SupplierID"]; TotalData.Relations.Add ( "ParentToChild", parentColumn, childColumn);. DataColumn pColumn = TotalData.Tables [ "Suppliers"] Columns [ "SupplierID"];. DataColumn cColumn = TotalData.Tables [ "SP"] Columns [ "SupplierID"]; TotalData.Relations .Add ("parentchild", pcolumn, ccolumn); this.DataGrid2.datasource = (data) totaldata.tables ["suppliers"]; this.dataGrid2.datamember = "parentstochild"; THISDATAGRID3.DATASOURCE = (DATATABLE) TotalData.tables ["suppliers"]; this.dataGrid3.datamember = "parentchild"; this.dataGrid2.AllowNavigation = false; this.dataGrid3.AllowNavigation = false;} private void button1_Click (object sender, System.EventArgs e) {this.bm.Position = 0; this.PosRefreshButton ();} Private void PosrefreshButton () {if (this.bm.position == 0) {this.button1.enabled = false; this.button2.enabled = false; this.button3.enabled = true; this.button4.enabled = true; } Else {ix (this.bm.position == this.totaldata.tables ["suppliers"]. Rows.count - 1) {this.button1.enabled = true; this.button2.enabled = true; this.button3. Enabled = false; this.button4.enabled = false;} else {this.button1.enabled = true; this.button2.enabled = true; this.button3.enabled = true;}}}} private void button2_Click (object sender, System.EventArgs e) {this.bm.Position - = 1; this.PosRefreshButton ();} private void button3_Click (object sender, System.EventArgs e) {this.bm.Position = 1 This.posrefreshbutton (); Private void button4_click (object sender, system.eventargs e) {this.bm.position = this.totaldata.tables ["suppliers"]. Rows.count - 1; this.posrefreshbutton ();} Private void button5_click (object sender, system.eventargs e) {this.bm.addnew (); this.textBox3.text = "normal"; this.opRefreshtext ("add"); This.opRefreshbtn ("Add"); this.ctlposbutton (false); private void OpRefreshText (string str) {switch (str) {case "Add": this.textBox1.Enabled = true; this.textBox2.Enabled = true; this.textBox3.Enabled = false; break; case "Modify": this .TextBox1.enabled = false; this.textBox2.enabled = true; this.textBox3.enabled = false; break; case "ok": this.textBox1.enabled = false; this.textbox2.enabled = false; this.textbox3. Enabled = false; break; case "cancel": this.textBox1.enabled = false; this.textBox2.enabled = false; this.textBox3.enabled = false; break; case "discard": this.textbox1.enabled = false; This.TextBox2.enabled = false; this.textBox3.enabled = false; break; default: this.textBox1.enabled = false; this.textbox2.enabled = false; this.textbox3.enabled = false; Break;} } Private void OpRefreshbtn (String Str) {SWITCH (STR) {CASE "add": this.button5.enabled = false; this.button6.enabled = false; this.button7.enabled = false; this.button9.enabled = true; This.Button10.enabled = true; break; case "modify": this.button5.enabled = false; this.button6.enabled = false; this.button7.enabled = false; this.button9.enabled = true; this.button10 .Nabled = true ;; this.button5.enabled = true; this.button6.enabled = true; this.button7.enabled = true; this.button9.enabled = false; this.button10.enabled = False; Break; Case "CANCEL": this.button5.enabled = true; this.button6.enabled = true; this.button7.enabled = true; this.button9.enabled = false; this.button10.enabled = false; Break Case "discard": this.button5.enabled = true; this.button6.enabled = true; this.button7.enabled = true; this.button9.enabled = false; TH Is.Button10.enabled = false; break; default: this.button5.enabled = true; this.button6.enabled = true; this.button7.enabled = true; this.button9.enabled = false; this.button10.enabled = False; Break;}} Private void button6_click (object sender, system.eventargs e) {this.oprefreshtext ("modify"); this.opRefreshbtn ("modify"); this.ctlposbutton (false);} private void button10_Click (object sender, System.EventArgs e) {this.OpRefreshText ( "Cancel"); this.OpRefreshBtn ( "Cancel"); this.bm.CancelCurrentEdit (); this.CtlPosButton (true); this.PosRefreshButton ( );} private void button7_Click (object sender, System.EventArgs e) {if ((MessageBox.Show ( "Discard the record", "Longrist_IRS", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes )) {This.oldposition = this.bm.position; this.opRefreshtext ("discard"); this.TextBox3.text = "discard"; this.discarddataGrid (this.totaldata); this.Updatedb (this.totaldata); RefreshDataSource (); this.opRefreshbtn ("discard"); this.ctlposbutton (TRUE); if (this.Bm.position = this.oldposition -1;} else {this.bm .Position = this.oldPosition;} this.posrefreshbutton (); if (this.textbox1.text == ") {this.button6.enabled = false; this.button7.enabled = false; } Private void button9_click (object sender, system.eventargs e) {this.bm.endcurrentedit (); this.oldposition = this.bm.position; this.updatedb (this.totaldata); this.opRefreshtext ("ok"); this .Oprefreshbtn ("ok"); this.refreshDataSource (); this.ctlposbutton (TRUE); this.bm.position = this.oldposition; this.posrefreshbutton ();} Private Void DiscardDataGrid (DataTable DTALDS) {DataTable DTALDS.TABLES {DATAROW [] DRS = DT.SELECT ("SupplierID = '" this.textBox1.text "'); if (Drs.Length> 0) {Foreach (DATAROW DR IN DRS) {DR ["status"] = "discard";}}}} private void button8_click (object sender, system.eventargs e) {//iff ((MessageBox.show ("Del the record "," Longrist_IRS ", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)) // {// this.bm.RemoveAt (this.bm.Position); // this.DiscardDataGrid (THIS. TOTALDATA); //}} Private void ctlposbutton (BOOL Enable) {IF (enable) {this.button1.enabled = true; this.button2.enabled = true; this.button3.enabled = true; excitation;} else {THIS. Button1.enabled = false; this.button2.enabled = false; this.button3.enabled = false; this.button4.enabled = false;}}}}}