السلام عليكم ورحمة الله وبركاته نكمل ماتبقى من مشروعنا السوبر ماركت , في الدرس السابق انتهينا من تصميم و برمجة فورم فاتوره المبيعات بشكل كامل وسنكمل ما تبقئ من مشروعنا …
ايضا في دروس سابقه صممنا وبرمجنا فورم فاتوره الشراء وبرمجنا فورم مرتجع الشراء لفاتوره الشراء في حاله تم ارجاع احد اصناف من فاتوره مشتريات وسنرمج فورم خاص بمرتجع فاتوره المبيعات في حاله استرجاع احد اصناف فاتوره المبيعات … .
تصميم مرتجع البيع
تصيمم و برمجة فورم مرتجع فاتوره المبيعات وسنختصر كل شي في برمجة مرتجع البيع لان فورم مرتجع البيع هو نفس فورم مرتجع الشراء وبالتالي نقوم باضافة فورم ونسميه Resale ثم نذهب لفورم مرتجع الشراء و نقوم بتحديد كافه ادوات الفورم وننسخها في فورم مرتجع البيع Resale ثم نبدا بتغير الاكواد او الادوات التي تتطلب التغيرات وكالتالي :
قبل تغير اي شي نقوم بتعريف متغيرات للداتا تيبل وداتا ادبتر و code و load ونعرف المتغيرات في المديول الخاص بالسوبر ماركت وكالتالي :
'===========Resalepill
Public Resalepilldt As New DataTable
Public Resalepillda As New OleDbDataAdapter
Public mynewldresalepill As Integer
Public Resalecmd As New OleDbCommand
Public Sub load_Resalepill()
Resalepilldt.Clear()
Resalepillda = New OleDbDataAdapter("select * from resalepill", con)
Resalepillda.Fill(Resalepilldt)
End Sub
Public Sub code_resalepill()
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("select max(resaleld) from resalepill", con)
da.Fill(dt)
If IsDBNull(dt(0)(0)) = True Then
mynewldresalepill = 1
Else
mynewldresalepill = dt(0)(0) + 1
End If
End Sub
شاهد الصوره توضيح كيف تم ترتيب الاكواد اعلاه نبدا بالتغيرات كالتالي
نقوم بتغير اسماء الادوات برمجيا ونسميها باسم الفورم وكالتالي
- التسلسل نسميه resaleld - المستخدم نسميه reseleuser - التاريخ الان نسميه resaledate - الوقت الان نسميه resaletime اما باقي الادوات تبقئ نفس اسمها الاصلي اي نفس اسمها عند اضافتها من صندوق الادوات Toolbox
شاهد بالفيديو كيف تم اضافة فورم جديد وسميناه rssale وكيف تم نسخ ادوات فورم مرتجع الشراء ولصقها في فورم مرتجع البيع
شاهد فيدو رقم 2 كيف تم تغير اسماء الادوات برمجيا
كيف نغير الحقول في داتا كراند فيو datagridview
ثم نفتح داتا كراند فيو ونغير اسماء الحقول تبعا لاسماء حقول جدول resalepill في قاعدة البيانات وكالتالي : رقم الفاتوره ➖➖ saleld تاريخ الفاتوره➖➖ saledate كاش➖➖➖ salecash اجل➖➖➖salepostpone العميل ➖➖➖salecustomer الصنف ➖➖➖operltem الصلاحية ➖➖➖seleexp كمية المباعه saleqty كمية المرتجع اجمالي المرتجع ملاحظات الخصم ➖➖➖saledisconud اجمالي الجمهور ➖➖saletotalg صافي البيع ➖➖saletotab رقم مرتجع ➖➖resaleld عدد الاصناف المرتجعه هذه التغيرات التي حدثت على داتا كراند فيو
شاهد الفيديو رقم 3 كيف تم تغير الحقول في داتا كراند فيو datagridview .
ثم نقوم بنسخ كافة اكواد فورم مرتجع الشراء ونلصقه في فورم مرتجع البيع ونبدا بتغير الاكواد التي تتطلب التغير ولكن لاختصار الوقت وحتئ لا نطول في برمجة فورم لانه هو نفس فورم مرتجع الشراء بالضبط لكن حدث تغيرات بسيطه علئ الاكواد لذلك قمت بوضع لكم كافة اكواد مرتجع البيع بعد كافه التغيرات التي حصلت عليه…
الاكواد تحت في ملف نصي text اخي المبرمج بعد نسخ الاكواد من ملف text قم بلصقها في فورم مرتجع البيع وهكذا يصبح لديك الفورم جاهز وكله تمام .
شاهد الفيديو رقم 4 بعد تنفيذ البرنامج كيف تمت عمليات البحث بالعميل والكاش والاجل والصنف
شاهد الفيديو رقم 5 كيف تم حفظ اصناف تم استرجاعها
شاهد الفيديو رقم 6 توضيح لكافة اكواد فورم مرتجع البيع
برمجة مرتجع البيع
ملف نصي بصيغه text جاهز فيه جميع اكواد فورم مرتجع البيع كل ماعليك اخي المبرمج قم بنسخ هذه الاكواد ولصقها في فورم مرتجع البيع resale
Imports System.Data.OleDb
Public Class Resale
Dim cruinqty As Double
Public ltemscmd As New OleDbCommand
'==================================
Public Sub newresale()
code_resalepill()
resaleld.Text = mynewldresalepill
resaleltemcount.Text = 0
resaletotolg.Text = 0
resaleuser.Text = ""
End Sub
Public Sub resaleQ()
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("SELECT salepill.saleld, salepill.saledate, salepill.salecustomer, salepill.salecash, salepill.salepostpone, operations.operltem, operations.saleexp, operations.saleqty, operations.saletotalg, operations.saledisconund, operations.saletotalb, operations.resaleqty, operations.resaletotalg, operations.resalenotes FROM salepill INNER JOIN operations ON salepill.saleld = operations.saleld", con)
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dt
End Sub
Private Sub Resale_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'=========================== ����� ������� �� ����� ����
load_ltmes()
ComboBox1.DataSource = ltmesdt
ComboBox1.DisplayMember = "ltemname"
ComboBox1.ValueMember = "ltemld"
'=========================== ����� ������ �� ����� ����
load_customers()
ComboBox2.DataSource = customersdt
ComboBox2.DisplayMember = "customername"
ComboBox2.ValueMember = "customerld"
'======================================= ����� ������
load_Resalepill()
'========================================
newresale()
'========================================
resaleQ()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
newresale()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
For z As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1(8, DataGridView1.Rows(z).Index).Value > 0 Then
oprationscmd = New OleDbCommand(" insert into operations (operltem,resaleld,resalenotes,resaleqty,resaletotalg) values ('" & DataGridView1(5, DataGridView1.Rows(z).Index).Value & "', " & resaleld.Text & " ,'" & DataGridView1(10, DataGridView1.Rows(z).Index).Value & "', " & DataGridView1(8, DataGridView1.Rows(z).Index).Value & " ," & DataGridView1(9, DataGridView1.Rows(z).Index).Value & ")", con)
con.Open()
oprationscmd.ExecuteNonQuery()
con.Close()
End If
Next
'=============================
'===========save
Resalepilldt.Rows.Add()
Dim last As Integer = Resalepilldt.Rows.Count - 1
Resalepilldt.Rows(last).Item("resaledate") = Resaledate.Value
Resalepilldt.Rows(last).Item("resaleld") = resaleld.Text
Resalepilldt.Rows(last).Item("resaleltemcount") = resaleltemcount.Text
Resalepilldt.Rows(last).Item("resaletime") = Resaletime.Value
Resalepilldt.Rows(last).Item("resaletotalg") = resaletotolg.Text
Resalepilldt.Rows(last).Item("resaleuser") = resaleuser.Text
Dim save As New OleDbCommandBuilder(Resalepillda)
Resalepillda.Update(Resalepilldt)
Resalepilldt.AcceptChanges()
MsgBox("�� ��� �������� �����")
load_Resalepill()
'===============================
newresale()
'==============================
'update
For x As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1(8, DataGridView1.Rows(x).Index).Value > 0 Then
Dim dt As New DataTable
Dim da As New OleDbDataAdapter
dt.Clear()
da = New OleDbDataAdapter("select * from ltems where ltemname = '" & DataGridView1(5, DataGridView1.Rows(x).Index).Value & "'", con)
da.Fill(dt)
If dt.Rows.Count > 0 Then
cruinqty = dt.Rows(0).Item("ltemqty")
MsgBox(cruinqty)
End If
'==============================
Dim newqtw As Double
newqtw = cruinqty - Val(DataGridView1(8, DataGridView1.Rows(x).Index).Value)
ltemscmd = New OleDbCommand("update ltems set ltemqty = " & newqtw & " where ltemname = '" & DataGridView1(5, DataGridView1.Rows(x).Index).Value & "' ", con)
con.Open()
ltemscmd.ExecuteNonQuery()
con.Close()
End If
Next
End Sub
Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Try
Dim total, count As Double
'======= ���� ������ ������� �� ���� ����� ���
DataGridView1(9, DataGridView1.CurrentRow.Index).Value = DataGridView1(8, DataGridView1.CurrentRow.Index).Value * DataGridView1(13, DataGridView1.CurrentRow.Index).Value
'==========,����� ������� ��������
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1(8, DataGridView1.Rows(i).Index).Value > 0 Then
DataGridView1(14, DataGridView1.Rows(i).Index).Value = resaleld.Text
'=========== ��� ������� ��������
DataGridView1(15, DataGridView1.Rows(i).Index).Value = 1
'=====���� ������ ������� �� ��� ����
total = total + DataGridView1(9, DataGridView1.Rows(i).Index).Value
'========== ��� ������� ��������
count = count + DataGridView1(15, DataGridView1.Rows(i).Index).Value
Else
'========��� �������
DataGridView1(14, DataGridView1.Rows(i).Index).Value = Nothing
'========������ �������
DataGridView1(15, DataGridView1.Rows(i).Index).Value = Nothing
End If
resaletotolg.Text = total
resaleltemcount.Text = count
Next
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
'===================��� ���
If RadioButton1.Checked = True And RadioButton2.Checked = False And RadioButton3.Checked = False And RadioButton4.Checked = False Then
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("SELECT salepill.saleld, salepill.saledate, salepill.salecustomer, salepill.salecash, salepill.salepostpone, operations.operltem, operations.saleexp, operations.saleqty, operations.saletotalg, operations.saledisconund, operations.saletotalb, operations.resaleqty, operations.resaletotalg, operations.resalenotes FROM salepill, operations where salepill.saleld = operations.saleld and saledate between #" & DateTimePicker1.Value.ToString("yyyy/MM/dd") & "# and #" & DateTimePicker2.Value.ToString("yyyy/MM/dd") & "#", con)
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dt
End If
'======================================
'===================��� ������
If RadioButton1.Checked = True And RadioButton2.Checked = False And RadioButton3.Checked = False And RadioButton4.Checked = False Then
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("SELECT salepill.saleld, salepill.saledate, salepill.salecustomer, salepill.salecash, salepill.salepostpone, operations.operltem, operations.saleexp, operations.saleqty, operations.saletotalg, operations.saledisconund, operations.saletotalb, operations.resaleqty, operations.resaletotalg, operations.resalenotes FROM salepill, operations where salepill.saleld = operations.saleld and saledate between #" & DateTimePicker1.Value.ToString("yyyy/MM/dd") & "# and #" & DateTimePicker2.Value.ToString("yyyy/MM/dd") & "# and operltem = '" & ComboBox1.Text & "'", con)
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dt
End If
'======================================
'===================��� �������
If RadioButton1.Checked = False And RadioButton2.Checked = True And RadioButton3.Checked = False And RadioButton4.Checked = False Then
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("SELECT salepill.saleld, salepill.saledate, salepill.salecustomer, salepill.salecash, salepill.salepostpone, operations.operltem, operations.saleexp, operations.saleqty, operations.saletotalg, operations.saledisconund, operations.saletotalb, operations.resaleqty, operations.resaletotalg, operations.resalenotes FROM salepill, operations where salepill.saleld = operations.saleld and saledate between #" & DateTimePicker1.Value.ToString("yyyy/MM/dd") & "# and #" & DateTimePicker2.Value.ToString("yyyy/MM/dd") & "# and salecustomer = '" & ComboBox2.Text & "'", con)
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dt
End If
'======================================
'===================��� ����
If RadioButton1.Checked = False And RadioButton2.Checked = False And RadioButton3.Checked = True And RadioButton4.Checked = False Then
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("SELECT salepill.saleld, salepill.saledate, salepill.salecustomer, salepill.salecash, salepill.salepostpone, operations.operltem, operations.saleexp, operations.saleqty, operations.saletotalg, operations.saledisconund, operations.saletotalb, operations.resaleqty, operations.resaletotalg, operations.resalenotes FROM salepill, operations where salepill.saleld = operations.saleld and saledate between #" & DateTimePicker1.Value.ToString("yyyy/MM/dd") & "# and #" & DateTimePicker2.Value.ToString("yyyy/MM/dd") & "# and salecash = " & RadioButton3.Checked & "", con)
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dt
End If
'======================================
'===================��� ���
If RadioButton1.Checked = False And RadioButton2.Checked = False And RadioButton3.Checked = False And RadioButton4.Checked = True Then
Dim dt As New DataTable
Dim da As New OleDbDataAdapter("SELECT salepill.saleld, salepill.saledate, salepill.salecustomer, salepill.salecash, salepill.salepostpone, operations.operltem, operations.saleexp, operations.saleqty, operations.saletotalg, operations.saledisconund, operations.saletotalb, operations.resaleqty, operations.resaletotalg, operations.resalenotes FROM salepill, operations where salepill.saleld = operations.saleld and saledate between #" & DateTimePicker1.Value.ToString("yyyy/MM/dd") & "# and #" & DateTimePicker2.Value.ToString("yyyy/MM/dd") & "# and salepostpone = " & RadioButton4.Checked & "", con)
da.Fill(dt)
DataGridView1.AutoGenerateColumns = False
DataGridView1.DataSource = dt
End If
End Sub
End Class
