المشاركات : 506
المواضيع 39
الإنتساب : Sep 2013
السمعة :
14
الشكر: 715
تم شكره 578 مرات في 220 مشاركات
27-10-13, 05:25 PM
(آخر تعديل لهذه المشاركة : 27-10-13, 05:30 PM {2} بواسطة hoob computer.)
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
الصلاة و السلام على أشرف خلق الله سيدنا محمد و على آله و صحبه و سلم
إخواني و أخواتي أعضاء المنتدى الكرام,
المشرفين و المراقبين و القائمين على هذا المنتدى الرائع,
أما بعد, لقد خطرت في بالي فكرة القيام بمشروع صغير يفيد المبتدئين و المتوسطين المستوى في (برمجة قواعد البيانات تحت بيئة VB.Net).
لذا, أحببت أن أقوم بعمل هذا المشروع البسيط و وضعه في المنتدى الجميل لتعم الفائدة ... فأرجوا منكم أن تقبلوا هذا المشروع كهدية بسيطة لكل الزوار و الأعضاء.
و الأن دعونا نبدأ على بركة الله في المشروع ...
1- إسم المشروع: Master – Detail Example with XtraReports
2- متطلبات المشروع:
- VS 2010 or VS 2012
- MS Office 2010 or MS Office 2013
- DevExpress v12.2 or DevExpress v13.1
3- خطوات العمل بالمشروع ستكون كالتالي:
- عمل قاعدة البيانات.
- عمل واجهات البرنامج المطلوبة.
- عمل التقرير المطلوب.
4- الصورة التالية توضح المشروع بعد نهايته:
أول خطوة سنقوم بها هي عمل قاعدة البيانات:
سنقوم بالبحث عن (MS Office Access) في قائمة إبدأ (Start) كما في الصورة:
شرح الصورة:
1- نضغط على قائمة إبدأ (Start) بزر الفأرة (Mouse) الأيسر.
2- نكتب في صندوق البحث (Access) ليظهر لنا (MS Office Access).
3- نضغط عليه بزر الفأرة (Mouse) الأيسر ليفتح لنا البرنامج كما في الصورة التالية:
بعد القيام بإختيار (Blank desktop database), ستظهر لنا الصورة التالية:
شرح الصورة:
1- نكتب إسم قاعدة البيانات مثل ما هو مكتوب (XtraReport.mdb).
2- عند الضغط على هذا الزر ستفتح لنا نافذة نختار منها مكان حفظ قاعدة البيانات كما في الصورة التالية:
- بعد الانتهاء من كتابة إسم قاعدة البيانات و إختيار مكان حفظها, نضغط على هذا الزر (OK).
3- بعدها نضغط على زر (Create) لتفتح لنا قاعدة البيانات كما في الصورة التالية:
نضغط على الزر الموضح في الصورة أعلاه ليظهر لنا التالي:
هنا سنقوم بكتابة إسم الجدول و سنسميه (Product_Table) و بعدها نضغط على (OK).
ثم نقوم بعمل الموضح في الصورة أدناه:
نقوم بكتابة أسماء الحقول كما هو موضح في الصورة أعلاه مع مراعاة نوع و حجم كل حقل كما هو موضح في (Description) كل حقل.
بعد الانتهاء من ذلك نقوم بعمل (Save) للجدول و إغلاقه. و من ثم نقوم بعمل جدول جديد و ذلك من خلال:
1- الذهاب إلى (Create).
2- الضغط على (Table). سيظهر لنا التالي:
نضغط على الموضح في الصورة أعلاه.
سيظهر لنا التالي:
نكتب إسم الجدول (Category_Table). من ثم نضغط على (OK) ليظهر لنا التالي:
نقوم بكتابة أسماء الحقول كما هو موضح في الصورة أعلاه مع مراعاة نوع و حجم كل حقل كما هو موضح في (Description) كل حقل.
بعد الانتهاء من ذلك نقوم بعمل (Save) للجدول و إغلاقه.
بعد الانتهاء من عمل الجدولين و حقولهما, نقوم بالتالي:
ستظهر لنا النافذة التالية:
نقوم بعمل (Add) للجدولين (Category_Table) و (Product_Table).
من ثم نقوم بما هو موضح في الصورة أدناه:
عند الانتهاء من عمل ما هو موضح في الصورة أعلاه سينتج لنا التالي:
إلى هنا ينتهي درس اليوم
يتبع ...
تم الشكر بواسطة: abulayth , Sajad , مالكـ , الشاكي لله , mamas1 , 30june , Omar Mekkawy , مبرمج بلا حدود , tempman , alsouf , asemshahen5
المشاركات : 1,379
المواضيع 77
الإنتساب : Sep 2012
السمعة :
180
الشكر: 7891
تم شكره 14093 مرات في 904 مشاركات
السلام عليكم
رائع بارك الله فيك وجعله في ميزان حسناتك
يعطيك العافية
(( يَا أَيَّتُهَا النَّفْسُ الْمُطْمَئِنَّةُ ارْجِعِي إِلَى رَبِّكِ رَاضِيَةً مَرْضِيَّةً فَادْخُلِي فِي عِبَادِي وَادْخُلِي جَنَّتِي ))
المشاركات : 506
المواضيع 39
الإنتساب : Sep 2013
السمعة :
14
الشكر: 715
تم شكره 578 مرات في 220 مشاركات
30-10-13, 03:34 PM
(آخر تعديل لهذه المشاركة : 30-10-13, 04:29 PM {2} بواسطة hoob computer.)
و بارك الله فيك أخي (abulayth)
تحياتي
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
و الصلاة على أشرف خلق الله سيدنا محمد و على آله و صحبه و سلم
نكمل اليوم الدرس الثاني من هذا المشروع, نبدأ بالدرس على بركة الله.
بعد أن قمنا بالانتهاء من عمل قاعدة البيانات, نقوم بفتح مشروع جديد من خلال VS و ذلك بالضغط على (New Project) كما هو موضح بالصورة أدناه:
من ثم سيظهر لنا التالي:
شرح الصورة:
1- نضغط على (Installed).
2- نضغط على (Windows) تحت (Templates --> Visual Basic).
3- نختار (Windows Form Application).
4- نكتب إسم المشروع.نختار مكان حفظ المشروع.
5- نضغط على (OK) بعد الانتهاء من الخطوات السابقة.
عندها سيظهر لنا التالي:
نقوم بغلق هذه الواجهة (Form1) و من ثم نقوم بعمل التالي:
نقوم بعمل (Delete) لهذه الواجهة كما هو موضح بالصورة أعلاه.
من ثم نقوم بإضافة واجهة (Form) جديدة للمشروع كما هو موضح بالصورة أدناه:
عندها سيظهر لنا التالي:
نقوم بإختيار (Windows Forms) و من نكتب إسم الواجهة كما هو موضح في الصورة أعلاه.
بعدها نضغط على (Add).
بعدها سيظهر لنا التالي:
عندها نقوم بتغيير بعض الخصائص في هذه الواجهة كما هو موضح في الصورة أدناه:
و نقوم بتغيير الخصائص الأخرى الخاصة بهذه الواجهة كما هو موضح في الصورة أدناه:
بعد الانتهاء من تغيير الخصائص المذكورة في الصورتين السابقتين. نقوم بالتالي:
شرح الصورة:
1- نقوم بإضافة (TextBox) عدد (2).
2- نقوم بإضافة (Label) عدد (3).
3- نقوم بإضافة (DataGridView) عدد (1).
4- بعد إضافة المكونات السابقة, نقوم بتغيير حجم الواجهة ليصبح كما هو عليه في الصورة أعلاه.
5- نختار الـ (Textbox1) و نغير خاصية (Maxlength=15).
و من ثم نقوم بالتالي:
شرح الصورة:
1- نختار (Textbox2) و نغير خاصية (Maxlength=255, Multline=True).
و من ثم نقوم بالتالي:
شرح الصورة:
1- نقوم بإزالة علامات الصح في الصناديق (Enable Adding, Enable Editing, Enable Deleting, Enable Column Reordering).
2- نغيير لون خلفية (DataGridView) من خلال الخاصية (GridColor=Maroon).
بعد الإنتهاء من الخطوات السابقة, نقوم بالتالي:
ملاحظة: نقوم بتغيير الخصائص التابعة للواجهة (Form) حسب رغبتنا من حيث الحجم و الألوان.
شرح الصورة:
1- نقوم بإضافة (Button) عدد (1).
2- نضغط على الواجهة.
3- نغير خاصية (KeyPreview=True) الخاصة بالواجهة.
بعدها نقوم بإضافة واجهة (Form) أخرى إلى المشروع كما هو موضح بالصورة أدناه:
من ثم نقوم بالتالي:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (ProFrm).
3- نضغط على (Add).
بعد أن تظهر لنا الواجهة (Form) الجديدة (ProFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (ListBox) عدد (1).
- نقوم بإضافة (GroupBox) عدد (2).
- نقوم بإضافة (TextBox) عدد (5(.
- نقوم بإضافة (DataGridView) عدد (1).
- نقوم بإضافة (Button) عدد (1).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (MDI Parent Form).
2- نكتب إسم الواجهة (MainFrm).
3- نضغط على (Add).
ستظهر لنا الواجهة التالية:
نقوم بعدة أمور هنا:
بعد أن نقوم بما هو مذكور في الصورة أعلاه, يجب علينا القيام بإضافة بعض الأدوات إلى هذه الواجهة:
1- إضافة قائمة (Products) إلى الـ(MenuStrip) الموجودة لدينا.
- نضيف تحتها (Add).
- نضيف تحتها (View).
2- إضافة قائمة (Categories) إلى الـ(MenuStrip) الموجودة لدينا.
- نضيف تحتها (Add).
- نضيف تحتها (View).
3- إضافة قائمة (Reports) إلى الـ(MenuStrip) الموجودة لدينا.
- نضيف تحتها (Master – Detail Report).
• نضيف تحتها (Method One).
• نضيف تحتها (Method Two).
4- إضافة قائمة (Options) إلى الـ(MenuStrip) الموجودة لدينا.
- نضيف تحتها (Master – Detail Window).
- نضيف تحتها (Products).
- نضيف تحتها (Categories).
5- إضافة (Timer) عدد (2).
6- إضافة (Label) عدد (6) إلى الـ(StatusStrip) الموجودة لدينا.
7- نعدل خصائص جميع (Label) الموجودة في الـ(StatusStrip) كالأتي:
- Label1.Text= Contact the programmer at:
- Label2.Text=ismaeel_it@yahoo.com
- Label3.Text=|
- Label4.Text= This program is just an example on how to create Master-Detail report in XtraReports tools
- Label5.Text=|
- Label6.Text=Time
8- ثم نقوم بتعديل قائمتي (File) و (View) كالأتي:
- نقوم بحذف كل ما هو موجود تحت قائمة (File) عدا (Exit).
- نقوم بحذف كل ما هو موجود تحت قائمة (View) عدا (Status Bar).
- نضيف (Category – Detail) تحت قائمة (View) و يكون تحت الـ(Status Bar).
هذه الصورة توضح كل شيء مذكور أعلاه:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (MasterDetailFrm).
3- نضغط على (Add).
4- بعد أن تظهر لنا الواجهة (Form) الجديدة (MasterDetailFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (GroupBox) عدد (2).
- نقوم بإضافة (DataGridView) عدد (1).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (OptCategoryFrm).
3- نضغط على (Add).
4- بعد أن تظهر لنا الواجهة (Form) الجديدة (OptCategoryFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (GroupBox) عدد (1).
- نقوم بإضافة (RadioButton) عدد (2).
- نقوم بإضافة (Button) عدد (3).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (OptProductFrm).
3- نضغط على (Add).
4- بعد أن تظهر لنا الواجهة (Form) الجديدة (OptProductFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (GroupBox) عدد (1).
- نقوم بإضافة (RadioButton) عدد (2).
- نقوم بإضافة (Button) عدد (3).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (OptMasterFrm).
3- نضغط على (Add).
4- بعد أن تظهر لنا الواجهة (Form) الجديدة (OptMasterFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (GroupBox) عدد (3).
- نقوم بإضافة (RadioButton) عدد (4).
- نقوم بإضافة (CheckBox) عدد (3).
- نقوم بإضافة (Button) عدد (3).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (RepViewerFrm).
3- نضغط على (Add).
4- بعد أن تظهر لنا الواجهة (Form) الجديدة (RepViewerFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (PrintBarManager) عدد (1).
- نقوم بإضافة (PrintControl) عدد (1).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة واجهة (Form) جديدة أخرى للمشروع كما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Windows Forms).
2- نكتب إسم الواجهة (LogFrm).
3- نضغط على (Add).
4- بعد أن تظهر لنا الواجهة (Form) الجديدة (LogFrm), نقوم بإضافة بعض الأدوات:
- نقوم بإضافة (TextBox) عدد (2).
- نقوم بإضافة (Label) عدد (2).
- نقوم بإضافة (CheckBox) عدد (1).
- نقوم بإضافة (Timer) عدد (1).
- نقوم بإضافة (Button) عدد (2).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعدها نقوم بإضافة موديل (Module) إلى البرنامج من خلال الأتي:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بإختيار (Module) و نكتب إسمه (ConProAndFun).
2- نضغط على (Add).
بعدها سيظهر لنا الموضح أدناه:
ثم بعدها نقوم بما هو موضح بالصورة أدناه:
بعد أن قمنا بإضافة كل ما يلزمنا من واجهات (Forms) و موديل (Module), نقوم الأن ببدء البرمجة.
سأقوم بوضح جميل كلاسات الواجهات (Forms) و تستطيعون نسخها من دون اللجوء إلى كتابة الكود كله – مجرد نسخ و لصق – و ذلك لطول الأكواد.
الأكواد:
كود :
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports DevExpress.XtraReports
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting
Imports System.Data.OleDb
Imports System.Data
Module ConProAndFun
Public Cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\XtraReport.mdb;OLE DB Services=-1")
Sub OneInstance()
Dim appProc() As Process
Dim strModName, strProcName As String
strModName = Process.GetCurrentProcess.MainModule.ModuleName
strProcName = System.IO.Path.GetFileNameWithoutExtension(strModName)
appProc = Process.GetProcessesByName(strProcName)
If appProc.Length > 1 Then
MessageBox.Show("The program is already opened!", "Open Master-Detail Example", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End
End If
End Sub
End Module
كود :
Imports System.Windows.Forms
Imports System.Drawing
Public Class MainFrm
Private Sub StatusBarToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles StatusBarToolStripMenuItem.Click
Me.StatusStrip.Visible = Me.StatusBarToolStripMenuItem.Checked
End Sub
Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub
Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ArrangeIconsToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.ArrangeIcons)
End Sub
Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
' Close all child forms of the parent.
For Each ChildForm As Form In Me.MdiChildren
ChildForm.Close()
Next
End Sub
Private Sub AddToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AddToolStripMenuItem.Click
ProFrm.MdiParent = Me
ProFrm.Show()
End Sub
Private Sub ViewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ViewToolStripMenuItem.Click
ProFrm.GroupBox1.Enabled = False
ProFrm.MdiParent = Me
ProFrm.Show()
End Sub
Private Sub AddToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles AddToolStripMenuItem1.Click
CatFrm.MdiParent = Me
CatFrm.Show()
End Sub
Private Sub ViewToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ViewToolStripMenuItem1.Click
CatFrm.TextBox1.Enabled = False
CatFrm.TextBox2.Enabled = False
CatFrm.Button1.Enabled = False
CatFrm.MdiParent = Me
CatFrm.Show()
End Sub
Private Sub ToolStripStatusLabel1_Click(sender As Object, e As EventArgs) Handles ToolStripStatusLabel1.Click
Dim subStr As String = "Master-Detail Example ... XtraReport Example"
Process.Start("Mailto:ismaeel_it@yahoo.com" & "?subject=" & subStr)
End Sub
Private Sub MainFrm_Load(sender As Object, e As EventArgs) Handles Me.Load
If My.Settings.adrmvmas = True Then
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
Else
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End If
If My.Settings.adrmvcontmas = True Then
Me.ControlBox = True
Else
Me.ControlBox = False
End If
If My.Settings.minboxmas = True Then
Me.MinimizeBox = True
Else
Me.MinimizeBox = False
End If
If My.Settings.maxboxmas = True Then
Me.MaximizeBox = True
Else
Me.MaximizeBox = False
End If
If My.Settings.watermas = True Then
Me.BackgroundImage = My.Resources.img_1
Else
Me.BackgroundImage = Nothing
End If
Timer1.Enabled = True
Timer2.Enabled = True
LogFrm.ShowDialog()
End Sub
Private Sub CategoryDetailToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles CategoryDetailToolStripMenuItem.Click
MasterDetailFrm.MdiParent = Me
MasterDetailFrm.Show()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ToolStripStatusLabel3.ForeColor = Color.Black Then
ToolStripStatusLabel3.ForeColor = Color.Red
ToolStripStatusLabel3.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
Else
ToolStripStatusLabel3.ForeColor = Color.Black
ToolStripStatusLabel3.Font = New System.Drawing.Font("Segoe UI", 9, FontStyle.Regular)
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
ToolStripStatusLabel5.Text = Now
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub CategoriesToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles CategoriesToolStripMenuItem1.Click
OptCategoryFrm.MdiParent = Me
OptCategoryFrm.Show()
End Sub
Private Sub ProductsToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ProductsToolStripMenuItem1.Click
OptProductFrm.MdiParent = Me
OptProductFrm.Show()
End Sub
Private Sub MasterDetailWindowToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MasterDetailWindowToolStripMenuItem.Click
OptMasterFrm.MdiParent = Me
OptMasterFrm.Show()
End Sub
Private Sub MethodTwoToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MethodTwoToolStripMenuItem.Click
RepViewerFrm.ShowDialog()
End Sub
Private Sub MethodOneToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MethodOneToolStripMenuItem.Click
masterdetailreport()
End Sub
End Class
كود :
Imports System.Drawing
Imports System.IO
Public Class LogFrm
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "Admin" AndAlso TextBox3.Text = "123" Then
MessageBox.Show("You logged in successfully!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
ElseIf TextBox1.Text <> "Admin" AndAlso TextBox3.Text = "123" Then
MessageBox.Show("The username you entered is wrong!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox1.Focus()
ElseIf TextBox3.Text <> "123" AndAlso TextBox1.Text = "Admin" Then
MessageBox.Show("The password you entered is wrong!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox2.Focus()
TextBox3.Text = ""
ElseIf TextBox1.Text <> "Admin" AndAlso TextBox3.Text <> "123" Then
MessageBox.Show("The username and password you entered are wrong!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox1.Focus()
TextBox3.Text = ""
End If
End Sub
#Region "TextBoxes"
Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
TextBox1.ForeColor = Color.Black
TextBox1.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox1.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox1.Text <> vbNullString Then
TextBox1.SelectAll()
End If
End Sub
Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
TextBox2.ForeColor = Color.Black
TextBox2.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox2.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox2.Text <> vbNullString Then
TextBox2.SelectAll()
End If
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
TextBox1.ForeColor = Color.Black
TextBox1.BackColor = Color.White
TextBox1.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
TextBox2.ForeColor = Color.Black
TextBox2.BackColor = Color.White
TextBox2.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
#End Region
Private Sub LogFrm_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not System.IO.File.Exists(Application.StartupPath & "\XtraReport.mdb") Then
MessageBox.Show("The database doesn't exist!" & vbNewLine & "Please, look in the application path or contact the programmer." _
& vbNewLine & "The application will be closed.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End
End If
Dim emptyMenu As New ContextMenu
TextBox2.ContextMenu = emptyMenu
Timer1.Interval = 1000
Timer1.Stop()
End Sub
Private passKey As String = String.Empty
Private ignoreKeys As New List(Of Keys) From {Keys.Left, Keys.Up, Keys.PageUp, Keys.Home, Keys.Space}
#Region "Trick for * character"
Private Sub TextBox2_PreviewKeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles TextBox2.PreviewKeyDown
If e.KeyData = Keys.Tab Then
e.IsInputKey = True
End If
End Sub
Private Sub TextBox2_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles TextBox2.MouseUp
TextBox2.SelectionStart = TextBox2.TextLength
End Sub
Private Sub TextBox2_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
Timer1.Stop()
If e.KeyCode = Keys.Enter Then Button1_Click(Button1, New EventArgs)
If ignoreKeys.Contains(e.KeyCode) OrElse e.Control OrElse e.KeyData = Keys.Tab Then
e.SuppressKeyPress = True
Return
End If
End Sub
Private Sub TextBox2_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
e.Handled = True
If e.KeyChar = ChrW(Keys.Escape) Then
passKey = String.Empty
ElseIf e.KeyChar = ChrW(Keys.Back) Then
If passKey.Length = 1 Then
passKey = String.Empty
ElseIf passKey.Length > 1 Then
passKey = passKey.Substring(0, passKey.Length - 1)
Else
Return
End If
ElseIf e.KeyChar = ChrW(Keys.Return) Then
HideAllKeys()
'MessageBox.Show(passKey)
Return
Else
passKey &= e.KeyChar.ToString
End If
If passKey.Length = 0 Then
TextBox2.Text = ""
TextBox3.Text = ""
ElseIf passKey.Length = 1 Then
TextBox2.Text = passKey
TextBox3.Text = passKey
Else
TextBox2.Text = New String("*"c, passKey.Length - 1) & passKey(passKey.Length - 1)
TextBox3.Text = passKey
End If
TextBox2.SelectionStart = TextBox2.TextLength
If passKey.Length > 0 Then
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
HideAllKeys()
End Sub
Private Sub HideAllKeys()
TextBox2.Text = New String("*"c, passKey.Length)
TextBox2.SelectionStart = TextBox2.TextLength
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked = True Then
TextBox2.Text = passKey
Else
HideAllKeys()
End If
End Sub
#End Region
End Class
كود :
Imports System.Data
Imports System.Data.OleDb
Public Class CatFrm
Dim DS As New DataSet
Private Sub CatFrm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Private Sub CatFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Settings.adrmvcat = True Then
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
Else
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End If
If Cn.State = ConnectionState.Open Then Cn.Close()
Try
DS.Clear()
Dim DP As New OleDbDataAdapter("SELECT CategoryName, CategoryNotes FROM Category_Table", Cn)
DP.Fill(DS, "Category_Table")
'============================
If DS.Tables("Category_Table").Rows.Count > 0 Then
DataGridView1.DataSource = DS.Tables("Category_Table")
FillGrid()
Else
MessageBox.Show("The Category Table doesn't contain any record to view in the grid.", _
"Load Category Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Load Category Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Sub FillGrid()
Try
With DataGridView1
.Columns(0).HeaderText = "Category Name"
.Columns(1).HeaderText = "Notes"
.Columns(0).Width = 150
.Columns(1).Width = 250
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Add Columns", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
#Region "TextBoxes"
Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
TextBox1.ForeColor = Color.Black
TextBox1.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox1.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox1.Text <> vbNullString Then
TextBox1.SelectAll()
End If
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
TextBox1.ForeColor = Color.Black
TextBox1.BackColor = Color.White
TextBox1.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
TextBox2.ForeColor = Color.Black
TextBox2.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox2.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox2.Text <> vbNullString Then
TextBox2.SelectAll()
End If
End Sub
Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
TextBox2.ForeColor = Color.Black
TextBox2.BackColor = Color.White
TextBox2.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
End Sub
Private Sub TextBox2_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Enter Then Button1_Click(Button1, New EventArgs)
End Sub
#End Region
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = vbNullString Then
MessageBox.Show("You should enter the Category Name, then you can add it to the table.", _
"Add Category", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Try
Dim AddCom As New OleDbCommand
With AddCom
.Connection = Cn
.CommandType = CommandType.Text
.CommandText = "INSERT INTO Category_Table (CategoryName,CategoryNotes) values(?,?)"
.Parameters.Clear()
.Parameters.AddWithValue("@CategoryName", OleDbType.VarChar).Value = TextBox1.Text.Trim
If TextBox2.Text = vbNullString Then
.Parameters.AddWithValue("@CategoryNotes", OleDbType.VarChar).Value = "No note"
Else
.Parameters.AddWithValue("@CategoryNotes", OleDbType.VarChar).Value = TextBox2.Text.Trim
End If
End With
Cn.Open()
AddCom.ExecuteNonQuery()
Cn.Close()
MessageBox.Show("You added a new Category successfully.", "Add Category", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Add Category", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
CatFrm_Load(Nothing, Nothing)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.Focus()
End If
End Sub
End Class
كود :
Imports System.Data
Imports System.Data.OleDb
Public Class ProFrm
Dim DS, DS1 As New DataSet
#Region "TextBoxes"
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
End Sub
Private Sub TextBox1_GotFocus(sender As Object, e As EventArgs) Handles TextBox1.GotFocus
TextBox1.ForeColor = Color.Black
TextBox1.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox1.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox1.Text <> vbNullString Then
TextBox1.SelectAll()
End If
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
TextBox1.ForeColor = Color.Black
TextBox1.BackColor = Color.White
TextBox1.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
Private Sub TextBox2_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
End Sub
Private Sub TextBox2_GotFocus(sender As Object, e As EventArgs) Handles TextBox2.GotFocus
TextBox2.ForeColor = Color.Black
TextBox2.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox2.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox2.Text <> vbNullString Then
TextBox2.SelectAll()
End If
End Sub
Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
TextBox2.ForeColor = Color.Black
TextBox2.BackColor = Color.White
TextBox2.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
Private Sub TextBox3_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox3.KeyDown
If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
End Sub
Private Sub TextBox3_GotFocus(sender As Object, e As EventArgs) Handles TextBox3.GotFocus
TextBox3.ForeColor = Color.Black
TextBox3.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox3.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox3.Text <> vbNullString Then
TextBox3.SelectAll()
End If
End Sub
Private Sub TextBox3_LostFocus(sender As Object, e As EventArgs) Handles TextBox3.LostFocus
TextBox3.ForeColor = Color.Black
TextBox3.BackColor = Color.White
TextBox3.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
Private Sub TextBox4_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox4.KeyDown
If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
End Sub
Private Sub TextBox4_GotFocus(sender As Object, e As EventArgs) Handles TextBox4.GotFocus
TextBox4.ForeColor = Color.Black
TextBox4.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox4.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox4.Text <> vbNullString Then
TextBox4.SelectAll()
End If
End Sub
Private Sub TextBox4_LostFocus(sender As Object, e As EventArgs) Handles TextBox4.LostFocus
TextBox4.ForeColor = Color.Black
TextBox4.BackColor = Color.White
TextBox4.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
If TextBox4.Text <> vbNullString Then
Dim totvalue As String = TextBox4.Text.Replace(",", "")
TextBox4.Text = Format(Val(totvalue), "###,###.##")
End If
End Sub
Private Sub TextBox5_GotFocus(sender As Object, e As EventArgs) Handles TextBox5.GotFocus
TextBox5.ForeColor = Color.Black
TextBox5.BackColor = System.Drawing.Color.FromArgb(255, 255, 192)
TextBox5.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Bold)
If TextBox5.Text <> vbNullString Then
TextBox5.SelectAll()
End If
End Sub
Private Sub TextBox5_LostFocus(sender As Object, e As EventArgs) Handles TextBox5.LostFocus
TextBox5.ForeColor = Color.Black
TextBox5.BackColor = Color.White
TextBox5.Font = New System.Drawing.Font("Times New Roman", 10, FontStyle.Regular)
End Sub
#End Region
Private Sub ProFrm_Activated(sender As Object, e As EventArgs) Handles Me.Activated
ListBox1.Focus()
ListBox1.SelectedIndex = 0
ListBox1_SelectedIndexChanged(ListBox1, New EventArgs)
End Sub
Private Sub ProFrm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Private Sub ProFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Settings.adrmvpro = True Then
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
Else
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
End If
If Cn.State = ConnectionState.Open Then Cn.Close()
Try
DS.Clear()
Dim DP As New OleDbDataAdapter("SELECT ID, CategoryName, CategoryNotes FROM Category_Table", Cn)
DP.Fill(DS, "Category_Table")
'============================
If DS.Tables("Category_Table").Rows.Count > 0 Then
ListBox1.Focus()
With ListBox1
.DisplayMember = "CategoryName"
.ValueMember = "ID"
.DataSource = DS.Tables("Category_Table")
End With
Else
MessageBox.Show("The Category Table doesn't contain any record." & vbNewLine _
& "Cann't view the Product Table in the grid.", "Load Product Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Load Product Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Sub FillGrid()
Try
With DataGridView1
.Columns(0).HeaderText = "Product Category"
.Columns(1).HeaderText = "Product Name"
.Columns(2).HeaderText = "Unit"
.Columns(3).HeaderText = "Quantity"
.Columns(4).HeaderText = "Unit Price"
.Columns(5).HeaderText = "Notes"
.Columns(0).Width = 150
.Columns(1).Width = 150
.Columns(2).Width = 150
.Columns(3).Width = 150
.Columns(4).Width = 150
.Columns(5).Width = 250
.Columns(0).Visible = False
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Add Columns", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = vbNullString OrElse TextBox2.Text = vbNullString OrElse _
TextBox3.Text = vbNullString OrElse TextBox4.Text = vbNullString Then
MessageBox.Show("You should fill the required fields, then you can add the product to the table.", _
"Add Product", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Try
Dim AddCom As New OleDbCommand
With AddCom
.Connection = Cn
.CommandType = CommandType.Text
.CommandText = "INSERT INTO Product_Table (ProductCategory,ProductName,ProductUnit,ProductQuantity,ProductPrice,ProductNotes) values(?,?,?,?,?,?)"
.Parameters.Clear()
.Parameters.AddWithValue("@ProductCategory", OleDbType.Integer).Value = ListBox1.SelectedValue
.Parameters.AddWithValue("@ProductName", OleDbType.VarChar).Value = TextBox1.Text.Trim
.Parameters.AddWithValue("@ProductUnit", OleDbType.VarChar).Value = TextBox2.Text.Trim
.Parameters.AddWithValue("@ProductQuantity", OleDbType.Single).Value = Val(TextBox3.Text.Trim)
.Parameters.AddWithValue("@ProductPrice", OleDbType.Currency).Value = Val(TextBox4.Text.Trim)
If TextBox5.Text = vbNullString Then
.Parameters.AddWithValue("@ProductNotes", OleDbType.VarChar).Value = "No note"
Else
.Parameters.AddWithValue("@ProductNotes", OleDbType.VarChar).Value = TextBox5.Text.Trim
End If
End With
Cn.Open()
AddCom.ExecuteNonQuery()
Cn.Close()
MessageBox.Show("You added a new Product successfully.", "Add Product", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "Add Product", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
ProFrm_Load(Nothing, Nothing)
ProFrm_Activated(Nothing, New EventArgs)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox1.Focus()
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.Focused = False Then Exit Sub
If Cn.State = ConnectionState.Open Then Cn.Close()
Try
DS1.Clear()
Dim DP1 As New OleDbDataAdapter("SELECT ProductCategory, ProductName, ProductUnit, ProductQuantity, ProductPrice, ProductNotes FROM Product_Table WHERE ProductCategory=" & ListBox1.SelectedValue, Cn)
DP1.Fill(DS1, "Product_Table")
If DS1.Tables("Product_Table").Rows.Count > 0 Then
DataGridView1.DataSource = DS1.Tables("Product_Table")
FillGrid()
Else
MessageBox.Show("This Category doesn't contain any Product." & vbNewLine _
& "Cann't view the Product Table in the grid.", "Load Product Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Load Product Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
End Class
كود :
Imports System.Data
Imports System.Data.OleDb
Public Class MasterDetailFrm
Private Sub MasterDetailFrm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Private Sub MasterDetailFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Cn.State = ConnectionState.Open Then Cn.Close()
Try
DataGridView1.DataSource = FillHeader()
showdetails()
DataGridView1.Refresh()
FillGrid()
FillGrid2()
Cn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Load Category Table", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub DataGridView1_SelectionChanged(sender As Object, e As EventArgs) Handles DataGridView1.SelectionChanged
Try
showdetails()
Catch ex As Exception
MessageBox.Show(ex.Message, "Load Product Table - According to the Selected Category", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Sub FillGrid()
Try
With DataGridView1
.Columns(0).HeaderText = "ID"
.Columns(1).HeaderText = "Category Name"
.Columns(2).HeaderText = "Notes"
.Columns(0).Width = 150
.Columns(1).Width = 150
.Columns(2).Width = 250
.Columns(0).Visible = False
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Add Columns", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Sub FillGrid2()
Try
With DataGridView2
.Columns(0).HeaderText = "Product Category"
.Columns(1).HeaderText = "Product Name"
.Columns(2).HeaderText = "Unit"
.Columns(3).HeaderText = "Quantity"
.Columns(4).HeaderText = "Unit Price"
.Columns(5).HeaderText = "Notes"
.Columns(0).Width = 150
.Columns(1).Width = 150
.Columns(2).Width = 150
.Columns(3).Width = 150
.Columns(4).Width = 150
.Columns(5).Width = 250
.Columns(0).Visible = False
End With
Catch ex As Exception
MessageBox.Show(ex.Message, "Add Columns", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Sub showdetails()
If DataGridView1.RowCount > 0 Then
Try
Dim headerID As Integer = CInt(DataGridView1.Item(0, DataGridView1.CurrentRow.Index).Value)
DataGridView2.DataSource = FillDetails(headerID)
Catch ex As Exception
MessageBox.Show(ex.Message, "Load Product Table - According to the Selected Category", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End If
End Sub
Private Function FillHeader() As DataTable
Dim DP As New OleDbDataAdapter("SELECT ID, CategoryName, CategoryNotes FROM Category_Table", Cn)
Dim dt As New DataTable
DP.Fill(dt)
Return dt
End Function
Private Function FillDetails(ByVal HID As Integer) As DataTable
Dim adapter As New OleDbDataAdapter("SELECT ProductCategory, ProductName, ProductUnit, ProductQuantity, ProductPrice, ProductNotes FROM Product_Table WHERE ProductCategory =@id", Cn)
adapter.SelectCommand.Parameters.Add("@id", OleDbType.Integer).Value = HID
Dim dt As New DataTable
adapter.Fill(dt)
Return dt
End Function
End Class
كود :
Public Class OptCategoryFrm
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.Save()
MessageBox.Show("Done!", "Save Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
My.Settings.Reload()
MessageBox.Show("Done!", "Reload Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Settings.Reset()
MessageBox.Show("Done!", "Reset Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
Private Sub OptCategoryFrm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
End Class
كود :
Public Class OptProductFrm
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.Save()
MessageBox.Show("Done!", "Save Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
Private Sub OptProductFrm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
My.Settings.Reload()
MessageBox.Show("Done!", "Reload Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Settings.Reset()
MessageBox.Show("Done!", "Reset Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
End Sub
End Class
كود :
Public Class OptMasterFrm
Private Sub OptMasterFrm_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
My.Settings.Save()
MessageBox.Show("Done!", "Save Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Application.Restart()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
My.Settings.Reload()
MessageBox.Show("Done!", "Reload Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Application.Restart()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
My.Settings.Reset()
MessageBox.Show("Done!", "Reset Settings", MessageBoxButtons.OK, MessageBoxIcon.Information)
Application.Restart()
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
If RadioButton3.Checked = True Then
CheckBox1.Enabled = True
CheckBox2.Enabled = True
End If
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
If RadioButton4.Checked = True Then
CheckBox1.Enabled = False
CheckBox1.Checked = False
CheckBox2.Enabled = False
CheckBox2.Checked = False
End If
End Sub
End Class
تبقت واجهة (Form) المسمى (RepViewerFrm.vb) من غير كود ... سنقوم بعمل كودها في الدرس القادم إن شاء الله, و ذلك لتعلقها بالتقارير.
ملاحظة: أغلب الأكواد تعلمتها من أعضاء منتدى (vb4arab.com) و (vb4arb.com), لذا جزاهم الله خيراً على ما علموني إياه من برمجة و بارك الله فيهم جميعاً.
إلى هنا ينتهي درس اليوم, أرجوا أن اكون قد وفقت فيه
يتبع ...
المشاركات : 1,561
المواضيع 264
الإنتساب : Sep 2013
السمعة :
29
الشكر: 653
تم شكره 1044 مرات في 408 مشاركات
-
السلام عليكم ورحمة الله
جزاك الله خيرا
شرح رائع ومتعوب عليه
ربنا يجعله فى موازين حسناتك
انا مليش فى التعامل مع قواعد البينات قوى
لاكن ياذن الله سكون لى معها وقفة
جزاك الله خيرا
-
المشاركات : 506
المواضيع 39
الإنتساب : Sep 2013
السمعة :
14
الشكر: 715
تم شكره 578 مرات في 220 مشاركات
وجزاك الله خيراً أخي (ali.alfoly) الكريم
تحياتي
المشاركات : 1,196
المواضيع 208
الإنتساب : Sep 2013
السمعة :
2
الشكر: 1
تم شكره 500 مرات في 294 مشاركات
مجهود رائع
برجاء ارسال المثال علي فيجوال 2008
شكرا علي تعبك مرة اخري
المشاركات : 506
المواضيع 39
الإنتساب : Sep 2013
السمعة :
14
الشكر: 715
تم شكره 578 مرات في 220 مشاركات
السلام عليكم و رحمة الله و بركاته,
أخي العزيز, الأكواد كلها موجودة في المشاركات أعلاه لكل المشروع, تستطيع نسخها و وضعها في مشروعك
و كذلك, فإنني لا أملك VS 2008 ... و نصيحة .. قم بإستعمال نسخة VS 2012 فهي رائعة جداً ...
و إن شاء الله سأكمل الدرس الأخير عن قريب
تحياتي
المشاركات : 506
المواضيع 39
الإنتساب : Sep 2013
السمعة :
14
الشكر: 715
تم شكره 578 مرات في 220 مشاركات
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
و الصلاة و السلام على أشرف خلق الله سيدنا محمد و على آله و صحبه أجمعين
في البداية, كل عام و أنتم بخير بمناسبة السنة الهجرية الجديدة ... عسى الله أن يجعلنا و إياكم من الصالحين.
نكمل اليوم الدرس الثالث و الأخير من هذا المشروع, نبدأ بالدرس على بركة الله.
بعد أن قمنا بالانتهاء من عمل قاعدة البيانات و عمل الواجهات, نقوم بعمل تقرير بسيط و هو لتعلم كيفية التعامل مع تقارير (XtraReport) من خلال الفيجوال بيسك. لذا نقوم بما هو موضح بالصورة أدناه:
لتظهر لنا الواجهة التالية:
شرح الصورة:
1- نقوم بفتح شجرة (Installed) و من ثم (Common Items).
2- نختار (DevExpress).
3- نضغط على (DXperience v12.2 Report Class).
4- نكتب إسم التقرير (MasterDetailRep.vb).
5- نضغط على (Add).
بعدها سيظهر لنا الموضح أدناه:
بعدها نقوم بعدة تعديلات و إضافة بعد الأداوت من الـ (Toolbox) إلى التقرير و هي:
1- نقوم بإضافة (xrLabel) عدد (3).
2- نقوم بإضافة (xrLine) عدد (5).
3- نقوم بإضافة (xrPageInfo) عدد (2).
4- نقوم بإضافة (xrTable) عدد (2).
5- نقوم بإضافة (xrTableCell) عدد (10).
6- نقوم بإضافة (xrTableRow) عدد (2).
نقوم بتغيير بعض الخصائص الخاصة بالواجهة (Form) و الادوات الموجودة عليها لنصل إلى التالي:
بعد أن قمنا بإضافة التقرير ... سنقوم الأن بكتابة الكود التالي في الواجهة (Form) المسماة بـ (RepViewerFrm) و الكود هو:
كود :
Imports System
Imports System.Windows.Forms
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraPrinting.Preview
Public Class RepViewerFrm
Private Sub RepViewerFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim rprt As XtraReport = masterdetailreport1()
Dim report As New MasterDetailRep
report.Pages.AddRange(rprt.Pages)
PrintControl1.PrintingSystem = report.PrintingSystem
End Sub
End Class
و من ثم نقوم بإضافة الإجراءات التالية إلى الموديل (Module) المسمى بـ (ConProAndFun) و كود الإجراءات هو:
كود :
Sub masterdetailreport()
' ======================================================================
Dim DA1 As New OleDbDataAdapter("SELECT ID, CategoryName, CategoryNotes" &
" FROM Category_Table", Cn)
'==========================================================
Dim DA2 As New OleDbDataAdapter("SELECT ID, ProductCategory, ProductName, ProductUnit, ProductQuantity, ProductPrice, ProductNotes" &
" FROM Product_Table", Cn)
'==========================================================
Dim fDS As New DataSet
fDS.Clear()
'==========================================================
DA1.Fill(fDS, "HeaderTbl")
DA2.Fill(fDS, "DetailTbl")
'==========================================================
Dim RelShp As New DataRelation("HeadDetailID", fDS.Tables("HeaderTbl").Columns("ID"), fDS.Tables("DetailTbl").Columns("ProductCategory"), True)
fDS.Relations.Add(RelShp)
'==========================================================
Dim report As New MasterDetailRep
report.DataSource = fDS
report.DataAdapter = DA1
'==========================================================
' Create the Group Header of the Report
Dim ghead As New GroupHeaderBand
report.Bands.Add(ghead)
Dim gfield As New GroupField("ID")
ghead.GroupFields.Add(gfield)
' Assign the Group Header to the Data
report.XrLabel8.DataBindings.Add("Text", Nothing, "CategoryName")
'==========================================================
report.DetailReport.DataSource = fDS
report.DetailReport.DataMember = "HeadDetailID"
report.DetailReport.DataAdapter = DA2
'==========================================================
report.XrTableCell22.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductName")
report.XrTableCell23.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductUnit")
report.XrTableCell24.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductQuantity")
report.XrTableCell25.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductPrice")
report.XrTableCell26.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductNotes")
'==========================================================
report.ShowPreviewDialog()
DA1.Dispose()
DA2.Dispose()
fDS.Dispose()
Cn.Close()
End Sub
Public Function masterdetailreport1() As XtraReport
' ======================================================================
Dim DA1 As New OleDbDataAdapter("SELECT ID, CategoryName, CategoryNotes" &
" FROM Category_Table", Cn)
'==========================================================
Dim DA2 As New OleDbDataAdapter("SELECT ID, ProductCategory, ProductName, ProductUnit, ProductQuantity, ProductPrice, ProductNotes" &
" FROM Product_Table", Cn)
'==========================================================
Dim fDS As New DataSet
fDS.Clear()
'==========================================================
DA1.Fill(fDS, "HeaderTbl")
DA2.Fill(fDS, "DetailTbl")
'==========================================================
Dim RelShp As New DataRelation("HeadDetailID", fDS.Tables("HeaderTbl").Columns("ID"), fDS.Tables("DetailTbl").Columns("ProductCategory"), True)
fDS.Relations.Add(RelShp)
'==========================================================
Dim report As New MasterDetailRep
report.DataSource = fDS
report.DataAdapter = DA1
'==========================================================
' Create the Group Header of the Report
Dim ghead As New GroupHeaderBand
report.Bands.Add(ghead)
Dim gfield As New GroupField("ID")
ghead.GroupFields.Add(gfield)
' Assign the Group Header to the Data
report.XrLabel8.DataBindings.Add("Text", Nothing, "CategoryName")
'==========================================================
report.DetailReport.DataSource = fDS
report.DetailReport.DataMember = "HeadDetailID"
report.DetailReport.DataAdapter = DA2
'==========================================================
report.XrTableCell22.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductName")
report.XrTableCell23.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductUnit")
report.XrTableCell24.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductQuantity")
report.XrTableCell25.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductPrice")
report.XrTableCell26.DataBindings.Add("Text", Nothing, "HeadDetailID.ProductNotes")
'==========================================================
report.CreateDocument()
DA1.Dispose()
DA2.Dispose()
fDS.Dispose()
Cn.Close()
Return report
End Function
إلى هنا ننتهي من هذه المقالة بحمد الله و شكره و الصلاة و السلام على النبي سيدنا محمد و على آله و صحبه و سلم.
لا أسألكم غير الدعاء لي و لأهلي بالخير ....
أرجوا أن يكون هذا العمل خالصاً لوجه الله تعالى .. و أرجوا أن تستفيدوا منه ....
تحياتي
المشاركات : 1,196
المواضيع 208
الإنتساب : Sep 2013
السمعة :
2
الشكر: 1
تم شكره 500 مرات في 294 مشاركات
السيد الفاضل
المنتدي عرضه عندي غير مكتمل والاكواد غير ظاهرة كاملة
والصورة تروح وتيجي والشاشة ناقصة
برجاء وضع المثال افضل باي نسخة فيجوال مثلا 2012 كما قلت
لم استطع اظهار الاكود حتي انسخها
شكرا لتعبك
المشاركات : 506
المواضيع 39
الإنتساب : Sep 2013
السمعة :
14
الشكر: 715
تم شكره 578 مرات في 220 مشاركات
(16-11-13, 02:19 PM)atefkhalf2004 كتب : السيد الفاضل
المنتدي عرضه عندي غير مكتمل والاكواد غير ظاهرة كاملة
والصورة تروح وتيجي والشاشة ناقصة
برجاء وضع المثال افضل باي نسخة فيجوال مثلا 2012 كما قلت
لم استطع اظهار الاكود حتي انسخها
شكرا لتعبك
السلام عليكم و رحمة الله و بركاته,
أخي العزيز, سأضع كتاب PDF مجمع فيه الدروس عن قريب إن شاء الله.
تحياتي
|