回覆列表
  • 1 # 使用者4922042290293

    usingSystem;  usingSystem.Drawing;  usingSystem.Collections;  usingSystem.ComponentModel;  usingSystem.Windows.Forms;    namespacecjgl.Report  {  ///<summary>  ///DataWindowTest的摘要說明。  ///</summary>  publicclassDataWindowTest:System.Windows.Forms.Form  {  privateSybase.DataWindow.DataWindowControldw;  privateSybase.DataWindow.TransactionTrans;  privateSystem.Windows.Forms.ButtonbtnRetrieve;  privateSystem.Windows.Forms.ButtonbtnDelete;  privateSystem.Windows.Forms.ButtonbtnInsert;  privateSystem.Windows.Forms.ButtonbtnSave;  privateSystem.ComponentModel.IContainercomponents;    publicDataWindowTest()  {  //  //Windows窗體設計器支援所必需的  //  InitializeComponent();    //  //TODO:在InitializeComponent呼叫後新增任何建構函式程式碼  //      }    ///<summary>  ///清理所有正在使用的資源。  ///</summary>  protectedoverridevoidDispose(booldisposing)  {  if(disposing)  {  if(components!=null)  {  components.Dispose();  }  }  base.Dispose(disposing);  }    #regionWindows窗體設計器生成的程式碼  ///<summary>  ///設計器支援所需的方法-不要使用程式碼編輯器修改  ///此方法的內容。  ///</summary>  privatevoidInitializeComponent()  {  this.components=newSystem.ComponentModel.Container();  this.btnRetrieve=newSystem.Windows.Forms.Button();  this.btnDelete=newSystem.Windows.Forms.Button();  this.btnInsert=newSystem.Windows.Forms.Button();  this.dw=newSybase.DataWindow.DataWindowControl();  this.Trans=newSybase.DataWindow.Transaction(this.components);  this.btnSave=newSystem.Windows.Forms.Button();  this.SuspendLayout();  //  //btnRetrieve  //  this.btnRetrieve.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right)));  this.btnRetrieve.Location=newSystem.Drawing.Point(360,2Array7);  this.btnRetrieve.Name="btnRetrieve";  this.btnRetrieve.TabIndex=1;  this.btnRetrieve.Text="Retrieve";  this.btnRetrieve.Click+=newSystem.EventHandler(this.btnRetrieve_Click);  //  //btnDelete  //  this.btnDelete.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right)));  this.btnDelete.Location=newSystem.Drawing.Point(260,2Array6);  this.btnDelete.Name="btnDelete";  this.btnDelete.TabIndex=2;  this.btnDelete.Text="Delete";  this.btnDelete.Click+=newSystem.EventHandler(this.btnDelete_Click);  //  //btnInsert  //  this.btnInsert.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right)));  this.btnInsert.Location=newSystem.Drawing.Point(152,2Array5);  this.btnInsert.Name="btnInsert";  this.btnInsert.TabIndex=3;  this.btnInsert.Text="Insert";  this.btnInsert.Click+=newSystem.EventHandler(this.btnInsert_Click);  //  //dw  //  this.dw.Anchor=((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top|System.Windows.Forms.AnchorStyles.Bottom)  |System.Windows.Forms.AnchorStyles.Left)  |System.Windows.Forms.AnchorStyles.Right)));  this.dw.DataWindowObject="dw_customer";  this.dw.LibraryList="D:\\ProgramFiles\\Sybase10\\DataWindowBuilder1.0\\dwb100.pbl";  this.dw.Location=newSystem.Drawing.Point(5,5);  this.dw.Name="dw";  this.dw.ScrollBars=System.Windows.Forms.ScrollBars.Both;  this.dw.Size=newSystem.Drawing.Size(432,280);  this.dw.TabIndex=4;  this.dw.Text="dataWindowControl1";  this.dw.TypeOfDataWindow=Sybase.DataWindow.DataWindowType.Grid;  //  //Trans  //  this.Trans.Database="asademoArray.dba";  this.Trans.Dbms=Sybase.DataWindow.DbmsType.OleDb;  this.Trans.DbParameter="PROVIDER=\’ASAProv.Array0\’";  this.Trans.Password="sql";  this.Trans.ServerName="asademoArray";  this.Trans.UserID="dba";  //  //btnSave  //  this.btnSave.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom|System.Windows.Forms.AnchorStyles.Right)));  this.btnSave.Location=newSystem.Drawing.Point(46,2Array6);  this.btnSave.Name="btnSave";  this.btnSave.TabIndex=5;  this.btnSave.Text="&Save";  this.btnSave.Click+=newSystem.EventHandler(this.btnSave_Click);  //  //DataWindowTest  //  this.AutoScaleBaseSize=newSystem.Drawing.Size(6,14);  this.ClientSize=newSystem.Drawing.Size(444,333);  this.Controls.Add(this.btnSave);  this.Controls.Add(this.dw);  this.Controls.Add(this.btnInsert);  this.Controls.Add(this.btnDelete);  this.Controls.Add(this.btnRetrieve);  this.Name="DataWindowTest";  this.Text="利用DataWindow.NET設計";  this.ResumeLayout(false);    }  #endregion    privatevoidbtnRetrieve_Click(objectsender,System.EventArgse)  {  try  {  if(!Trans.IsConnected)  {  Trans.Connect();  }  dw.SetTransObject(Trans);  dw.Retrieve();    }  catch(Sybase.DataWindow.DbErrorExceptionee)  {  MessageBox.Show("資料庫連接出錯!"+ee.SqlErrorText);  return;  }  }    privatevoidbtnInsert_Click(objectsender,System.EventArgse)  {  //插入一行  intinsertRow=dw.InsertRow(0);  dw.Scroll(insertRow);  //賦初值  dw.SetItemDouble(insertRow,"id",ArrayArrayArrayArray);  dw.SetItemString(insertRow,"fName","Huang");  dw.SetItemString(insertRow,"lName","Yong");  dw.SetItemString(insertRow,"address","ChangSha");  dw.SetItemString(insertRow,"city","ChangSha");  }    privatevoidbtnDelete_Click(objectsender,System.EventArgse)  {  dw.DeleteRow(dw.CurrentRow);  }    privatevoidbtnSave_Click(objectsender,System.EventArgse)  {  try  {  dw.Update();  Trans.Commit();  }  catch(Sybase.DataWindow.DbErrorExceptionee)  {  MessageBox.Show("更新不成功!原因:"+ee.SqlErrorText);  Trans.Rollback();  }  catch(Sybase.DataWindow.DataWindowNotCreatedExceptionee)  {  MessageBox.Show("資料視窗還沒有建立!");  Trans.Rollback();  }  catch(Sybase.DataWindow.MethodFailureExceptionee)  {  MessageBox.Show("更新不成功!原因:"+ee.Message.ToString());  Trans.Rollback();  }  }    }  }  透過PB,或DataWindowBuilder建立PBL庫和DataWindow物件後,就像在PB中操作一樣,指定PBL庫位置和DataWindow控制元件相關連DataWindow物件,就可對DataWindow進行相關的操作如dw.SetTransObject(Trans);dw.Retrieve();

  • 中秋節和大豐收的關聯?
  • 二十一二歲了,對未來沒有一點想法,該怎麼辦?