السلام عليكم كيف حال الجميع ؟
لقد اتعبتني الفكرة لكن اريد تنفيذها او اي طريقة تروها مناسبة دلوني عليها
الفكرة هي كالأتي
عندي مجوعة من تكست بوكس و داتا قريدفيو اردت ان اضيف كل مرة داتا قريد جديدة في نفس الفورم و يتم ملأها من طرف التكست بوكس لكن بمعلومات مختلفة
قمت بإضافة التاب كونترول و كل مرة يتم فتح صفحة جديدة لكن كيف يمكن إستنساخ الداتا قريد في صفحة و جديدة و كيف يمكن اخلي التكست يضيف في الدتاقريد الجديدة و كيف تتم مثلا عملية الحفظ في قاعدة البيانات حسب الصفحة المفتوحة
وعليكم السلام...
هتنشئ جملة الاتصال عادي وكل داتا هيتم التعامل معها علي حسب الجدول ويجب الا تتشابه المدخلات مثل
Dim ds as New Dataset
فلا تكررها لكيلا يؤثر علي جدول أخر.
المشكلة ليست في إنشاء جملة الإتصال اخي اسامة
هو كيف تتم عملية الإضافة من التكست بوكس الى الداتا قريد الموجودة في الصفحة المفتوحة في تاب كونترول
و كيف يتم معرفة الداتا قريد لنحفظ بياناتها الى الداتابيز
السلام عليكم
لم تفهموا قصدي يا جماعة الخير
عندي مجموعة من التكست بوكس و عندي داتاقريد مجهزة في التاب كونترول
المطلوب هو عند الضغط على زر إضافة يتم فتح صفحة جديدة في التاب كونترول و يتم وضع فيها نفس الداتاقريد
المطلوب الثاني : هو عند نقل البيانات من التكست الى الداتاقريد يجب ان تنقل في الداتاقريد الموجودة في صفحة التاب كونترول المفتوحة (الحالية)
المطلوب الثالث : عند عملية الحفظ المعلومات يجب ان تحفظ المعلومات الموجودة في الداتاقريد الموجودة في صفحة التاب كونترول المفتوحة
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication1 { public partial class Form1 : Form {
DataGridViewTextBoxColumn product = new DataGridViewTextBoxColumn() { Name = "product", HeaderText = "المنتوج" }; DataGridViewTextBoxColumn price = new DataGridViewTextBoxColumn() { Name = "price", HeaderText = "الثمن" }; DataGridViewTextBoxColumn qty = new DataGridViewTextBoxColumn() { Name = "qty", HeaderText = "الكمية" }; dataGridView.Columns.AddRange(new DataGridViewColumn[] { product, price, qty });
return dataGridView; }
}
}
وهذا الكود بناء على تغيير كلامك وطلبك للكود بلغة البيسيك بالرغم من كونه في قسم اسئلة C#.NET
اولا ملف التصميم Form1.Designer.vb
PHP كود :
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub
'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.button3 = New System.Windows.Forms.Button() Me.comboBox_CustomName = New System.Windows.Forms.ComboBox() Me.button_Save = New System.Windows.Forms.Button() Me.textBox_QTY = New System.Windows.Forms.TextBox() Me.textBox_Price = New System.Windows.Forms.TextBox() Me.textBox_Product = New System.Windows.Forms.TextBox() Me.label3 = New System.Windows.Forms.Label() Me.panel1 = New System.Windows.Forms.Panel() Me.label5 = New System.Windows.Forms.Label() Me.label2 = New System.Windows.Forms.Label() Me.label1 = New System.Windows.Forms.Label() Me.button_AddToDGV = New System.Windows.Forms.Button() Me.tabControl1 = New System.Windows.Forms.TabControl() Me.panel1.SuspendLayout() Me.SuspendLayout() ' 'button3 ' Me.button3.Enabled = False Me.button3.Location = New System.Drawing.Point(282, 175) Me.button3.Name = "button3" Me.button3.Size = New System.Drawing.Size(150, 33) Me.button3.TabIndex = 7 Me.button3.Text = "إضافة عملية بيع جديدة" Me.button3.UseVisualStyleBackColor = True ' 'comboBox_CustomName ' Me.comboBox_CustomName.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.comboBox_CustomName.FormattingEnabled = True Me.comboBox_CustomName.Location = New System.Drawing.Point(6, 10) Me.comboBox_CustomName.Name = "comboBox_CustomName" Me.comboBox_CustomName.Size = New System.Drawing.Size(170, 21) Me.comboBox_CustomName.TabIndex = 1 ' 'button_Save ' Me.button_Save.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.button_Save.Location = New System.Drawing.Point(542, 175) Me.button_Save.Name = "button_Save" Me.button_Save.Size = New System.Drawing.Size(110, 23) Me.button_Save.TabIndex = 6 Me.button_Save.Text = "حفظ" Me.button_Save.UseVisualStyleBackColor = True ' 'textBox_QTY ' Me.textBox_QTY.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.textBox_QTY.Location = New System.Drawing.Point(96, 89) Me.textBox_QTY.Name = "textBox_QTY" Me.textBox_QTY.Size = New System.Drawing.Size(100, 20) Me.textBox_QTY.TabIndex = 7 ' 'textBox_Price ' Me.textBox_Price.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.textBox_Price.Location = New System.Drawing.Point(96, 63) Me.textBox_Price.Name = "textBox_Price" Me.textBox_Price.Size = New System.Drawing.Size(100, 20) Me.textBox_Price.TabIndex = 5 ' 'textBox_Product ' Me.textBox_Product.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.textBox_Product.Location = New System.Drawing.Point(6, 37) Me.textBox_Product.Name = "textBox_Product" Me.textBox_Product.Size = New System.Drawing.Size(190, 20) Me.textBox_Product.TabIndex = 3 ' 'label3 ' Me.label3.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.label3.AutoSize = True Me.label3.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold) Me.label3.Location = New System.Drawing.Point(209, 88) Me.label3.Name = "label3" Me.label3.Size = New System.Drawing.Size(50, 19) Me.label3.TabIndex = 6 Me.label3.Text = "الكمية :" ' 'panel1 ' Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.panel1.Controls.Add(Me.comboBox_CustomName) Me.panel1.Controls.Add(Me.textBox_QTY) Me.panel1.Controls.Add(Me.textBox_Price) Me.panel1.Controls.Add(Me.textBox_Product) Me.panel1.Controls.Add(Me.label3) Me.panel1.Controls.Add(Me.label5) Me.panel1.Controls.Add(Me.label2) Me.panel1.Controls.Add(Me.label1) Me.panel1.Controls.Add(Me.button_AddToDGV) Me.panel1.Location = New System.Drawing.Point(12, 12) Me.panel1.Name = "panel1" Me.panel1.Size = New System.Drawing.Size(264, 157) Me.panel1.TabIndex = 4 ' 'label5 ' Me.label5.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.label5.AutoSize = True Me.label5.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold) Me.label5.Location = New System.Drawing.Point(182, 9) Me.label5.Name = "label5" Me.label5.Size = New System.Drawing.Size(77, 19) Me.label5.TabIndex = 0 Me.label5.Text = "إسم الزبون :" ' 'label2 ' Me.label2.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.label2.AutoSize = True Me.label2.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold) Me.label2.Location = New System.Drawing.Point(213, 62) Me.label2.Name = "label2" Me.label2.Size = New System.Drawing.Size(46, 19) Me.label2.TabIndex = 4 Me.label2.Text = "الثمن :" ' 'label1 ' Me.label1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.label1.AutoSize = True Me.label1.Font = New System.Drawing.Font("Times New Roman", 12.0!, System.Drawing.FontStyle.Bold) Me.label1.Location = New System.Drawing.Point(202, 36) Me.label1.Name = "label1" Me.label1.Size = New System.Drawing.Size(57, 19) Me.label1.TabIndex = 2 Me.label1.Text = "المنتوج :" ' 'button_AddToDGV ' Me.button_AddToDGV.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) Me.button_AddToDGV.Location = New System.Drawing.Point(3, 123) Me.button_AddToDGV.Name = "button_AddToDGV" Me.button_AddToDGV.Size = New System.Drawing.Size(173, 29) Me.button_AddToDGV.TabIndex = 8 Me.button_AddToDGV.Text = "إضافة الى الجدول" Me.button_AddToDGV.UseVisualStyleBackColor = True ' 'tabControl1 ' Me.tabControl1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.tabControl1.Location = New System.Drawing.Point(282, 12) Me.tabControl1.Name = "tabControl1" Me.tabControl1.RightToLeftLayout = True Me.tabControl1.SelectedIndex = 0 Me.tabControl1.Size = New System.Drawing.Size(370, 157) Me.tabControl1.TabIndex = 5 ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(664, 218) Me.Controls.Add(Me.button3) Me.Controls.Add(Me.button_Save) Me.Controls.Add(Me.panel1) Me.Controls.Add(Me.tabControl1) Me.Name = "Form1" Me.RightToLeft = System.Windows.Forms.RightToLeft.Yes Me.RightToLeftLayout = True Me.Text = "Form1" Me.panel1.ResumeLayout(False) Me.panel1.PerformLayout() Me.ResumeLayout(False)
End Sub Private WithEvents button3 As System.Windows.Forms.Button Private WithEvents comboBox_CustomName As System.Windows.Forms.ComboBox Private WithEvents button_Save As System.Windows.Forms.Button Private WithEvents textBox_QTY As System.Windows.Forms.TextBox Private WithEvents textBox_Price As System.Windows.Forms.TextBox Private WithEvents textBox_Product As System.Windows.Forms.TextBox Private WithEvents label3 As System.Windows.Forms.Label Private WithEvents panel1 As System.Windows.Forms.Panel Private WithEvents label5 As System.Windows.Forms.Label Private WithEvents label2 As System.Windows.Forms.Label Private WithEvents label1 As System.Windows.Forms.Label Private WithEvents button_AddToDGV As System.Windows.Forms.Button Private WithEvents tabControl1 As System.Windows.Forms.TabControl
End Class
ثانيا ملف الكود Form1.vb
PHP كود :
Imports System.Text
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Try InputLanguage.CurrentInputLanguage = InputLanguage.InstalledInputLanguages.Cast(Of InputLanguage)().Where(Function(lang) lang.Culture.EnglishName.ToLower.StartsWith("ar")).FirstOrDefault Catch ex As Exception End Try End Sub
Private Sub comboBox_CustomName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboBox_CustomName.SelectedIndexChanged If comboBox_CustomName.SelectedIndex <> -1 Then Dim customerName As String = comboBox_CustomName.Text.Trim() Dim tb As TabPage = tabControl1.TabPages(customerName) tabControl1.SelectedTab = tb End If End Sub
Private Sub button_AddToDGV_Click(sender As Object, e As EventArgs) Handles button_AddToDGV.Click
Dim customerName As String = comboBox_CustomName.Text.Trim
comboBox_CustomName.SelectedIndex = comboBox_CustomName.FindStringExact(customerName, 0) If (comboBox_CustomName.SelectedIndex = -1) Then If NewCustomer() = False Then Return comboBox_CustomName.Items.Add(customerName) End If
Dim tb As TabPage = tabControl1.TabPages(customerName) tabControl1.SelectedTab = tb
Dim product As String = textBox_Product.Text.Trim If (product.Equals("")) Then MessageBox.Show("أكتب اسم المنتوج") Return End If
Dim price As Double Dim qty As Integer Try price = Convert.ToDouble(textBox_Price.Text) qty = Convert.ToInt32(textBox_QTY.Text)
Catch ex As Exception MessageBox.Show("تأكد من البيانات") Return End Try
Dim dgv As DataGridView = TryCast(tb, TabPage).Controls(0) dgv.Rows.Add(product.ToString(), price.ToString(), qty.ToString) dgv.FirstDisplayedScrollingRowIndex = dgv.Rows.Count - 1 dgv.Rows(dgv.Rows.Count - 1).Cells(0).Selected = True
Private Sub button_Save_Click(sender As Object, e As EventArgs) Handles button_Save.Click If tabControl1.SelectedTab Is Nothing Then Return
Dim tb As TabPage = tabControl1.SelectedTab Dim dgv As DataGridView = TryCast(tb, TabPage).Controls(0)
Dim customerName As String = tb.Text
' dgv = الداتاجريد Dim builder As StringBuilder = New StringBuilder builder.AppendLine(customerName)
For Each row As DataGridViewRow In dgv.Rows builder.AppendLine( _ row.Cells(0).Value.ToString & _ " [" + row.Cells(2).Value.ToString() + "] = " & _ row.Cells(1).Value.ToString) Next
Dim customerName As String = comboBox_CustomName.Text.Trim If customerName.Equals(String.Empty) Then MessageBox.Show("أكتب اسم الزبزن") Return False End If
Dim tb As New TabPage() With {.Name = customerName, .Text = customerName} tb.Text = customerName tb.Controls.Add(NewDataGridView()) Me.tabControl1.TabPages.Add(tb) Me.tabControl1.SelectedTab = tb Return True End Function
Private Function NewDataGridView() As DataGridView
Dim dataGridView As New DataGridView() With { _ .Dock = DockStyle.Fill, _ .ReadOnly = True, _ .AllowUserToAddRows = False, _ .MultiSelect = False, _ .SelectionMode = DataGridViewSelectionMode.FullRowSelect }
Dim product As New DataGridViewTextBoxColumn() With {.Name = "product", .HeaderText = "المنتوج"} Dim price As New DataGridViewTextBoxColumn() With {.Name = "price", .HeaderText = "الثمن"} Dim qty As New DataGridViewTextBoxColumn() With {.Name = "qty", .HeaderText = "الكمية"} dataGridView.Columns.AddRange(New DataGridViewColumn() {product, price, qty})