2013-05-02 86 views
2
  1. 我想在windows應用程序的5-6窗體中創建插入數據。
  2. 每個表格至少包含15-20個控件。所有表格屬於 不同的表格。但有些相同。
  3. 我要創建的存儲「下一步」命名的每個窗體上按鈕,這樣 當我上單擊下一步按鈕全部填滿該按鈕的信息得到儲存一些地方
    並以這種方式儲存的最後信息後按鈕提交按鈕是 拖動,點擊提交按鈕,所有的數據被保存到數據庫中。
  4. 請告訴我如何存儲先前表單中插入的數據,並在提交按鈕的單擊事件中調用它。

現在我已經在同一頁上的所有控件,我已經使用這些代碼插入。如何在winforms c#中將數據從一種形式傳輸到另一種形式?

private void submit_addbtn_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       //personal data insert 
       Personal per = new Personal(); 
       per.Name = nametxt.Text; 
       per.FatherName = f_nametxt.Text; 
       per.MotherName = m_nametxt.Text; 
       per.Gotra = gotra_txt.Text; 
       per.Panth = panthcb.Text; 
       per.FamilyHead = fhntext.Text; 
       per.Educationlvl = edulvlcb.Text; 
       per.Education = educb.Text; 
       per.Blood = bloodcb.Text; 
       per.Gender = genderlist.Text; 
       per.Marrital = MarritalStatus; 
       per.DateOfBirth = dobdtp.Text; 
       if (new InsertAction().Insertpersonal(per)) 
       { 
        MessageBox.Show("Personal Insertion Happen "); 
       } 
       else 
       { 
        MessageBox.Show(" Personal Insertion does not Happen "); 
       } 

       // spouse data insert 
       Spouse sps = new Spouse(); 
       sps.Spousename = s_nametxt.Text; 
       sps.Spouseeducationlvl = s_edulvlcb.Text; 
       sps.Spouseeducation = s_educb.Text; 
       sps.Spouseblood = s_bgcb.Text; 
       sps.Spousedob = s_dobdtp.Text; 
       if (new InsertAction().Insertspouse(sps)) 
       { 
        MessageBox.Show(" Spouse Insertion Happen "); 
       } 
       else 
       { 
        MessageBox.Show(" Spouse Insertion does not Happen "); 
       } 

       // Resident data insert 
       Ressident resi = new Ressident(); 
       resi.RessiHnumber = ressi_numtxt.Text; 
       resi.RessihCmplx = ressi_complextxt.Text; 
       resi.RessiStrt = ressi_streettxt.Text; 
       resi.RessiLandmrk = ressi_landtxt.Text; 
       resi.RessiArea = ressi_areatxt.Text; 
       resi.RessiCity = ressi_citytxt.Text; 
       resi.RessiPhone = Convert.ToInt64(ressi_phnotxt.Text); 
       resi.RessiMobile = Convert.ToInt64(mobi_notxt.Text); 
       if (new InsertAction().Insertressident(resi)) 
       { 
        MessageBox.Show(" Ressident Insertion Happen "); 
       } 
       else 
       { 
        MessageBox.Show(" Ressident Insertion does not Happen "); 
       } 
       //occupation data insert 
       Occupation ocp = new Occupation(); 
       ocp.Occuptype = occup_typetxt.Text; 
       ocp.Occupadd = office_addresstxt.Text; 
       ocp.Occupnature = occup_naturecb.Text; 
       ocp.Occupphone = Convert.ToInt64(office_phno1txt.Text); 
       ocp.Occupmobile = Convert.ToInt64(office_mobnotxt.Text); 
       if (new InsertAction().Insertoccupation(ocp)) 
       { 
        MessageBox.Show(" Occupation Insertion Happen "); 
       } 
       else 
       { 
        MessageBox.Show(" Occupation Insertion does not Happen "); 
       } 


      } 

請幫幫我。 謝謝。

+0

[從另一種形式的Winforms傳遞值]的可能重複(HTTP://計算器。com/questions/9073267/passing-values-from-another-form-winforms) – 2013-05-02 15:29:31

+0

您也可以創建與您的表單相關的5-6個ClassObjects(每個表單一個類)並且與公共定義(set; get;)相關到每個表單上的每個對象。每次「下一步」單擊後,您可以保留關於該表單的所有屬性在它的classObject.I希望這可以幫助您 – Fuad 2013-05-12 07:37:11

回答

4

對於兩種形式之間發送的值,可能會

1->在第二形式的發送構造的值。您可以創建一個paramterized構造,當你初始化形式發送的值:

Form1 obj = new Form1(Object); 

2->您可能需要參考您的第一個形式,第二種形式。

在第二種形式,

public Form1 objForm1; 

在第一種形式

Form2 objForm2=new Form2(); 
Form2.objForm1=this; 

,然後你可以使用窗體2的objForm1指Form1的文本框或任何控制。

編輯:

考慮您想從Form1發送所有值Form2

在你的第二個形式,你必須有一個指的是上一個表單類型Form1的一個變量。因此,在第二個形式,

public Form1 objForm1; 

,然後你需要將Form1的當前實例發送到Form2

Form2 objForm2=new Form2(); 
Form2.objForm1=this; 

即您在創建窗體2指Form1的這種情況下,objForm1。

現在,在窗體2你可以使用任何Form 1的控制或可變作爲,

Form1.TextBox1Form1.Variable

+0

嘿,請告訴我,我應該怎麼做表單1然後第二次比第三。請每張表格至少填寫2-3行代碼,這樣才能讓我更清楚..請 – user2327043 2013-05-02 15:48:07

+0

http://www.c-sharpcorner.com/UploadFile/thiagu304/passdata05172006234318PM/passdata.aspx – user2327043 2013-05-02 16:09:57

+0

我已經去了通過它bt是這種情況,當我們只需要通過值bt如何處理多個值 – user2327043 2013-05-02 16:11:29

相關問題