تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] مساعدة في عمل برنامج تعليم
#14
اعذرني لم اراعي انك تستخدم #C 
على كل حال هذا الكود بـ #C
سنغير المديول الى Static Class حيث في #C لا يوجد Module 
اضف كلاس للمشروع و سميه Connect و هذا كوده

PHP كود :
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Data.OleDb;
using System Windows.Forms;

static class 
Connect
{
 
   public static string ConnectionString "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\TestDb.accdb";

 
   public static OleDbConnection Con = new OleDbConnection(ConnectionString);

 
   public static void CloseConnect()
 
   {
 
       if (Con.State == ConnectionState.Open)
 
       {
 
           Con.Close();
 
       }
 
   }


 
   public static void OpenConnect()
 
   {
 
       if (Con.State == ConnectionState.Closed)
 
       {
 
           if (Con.ConnectionString == null)
 
               Con.ConnectionString ConnectionString;
 
           Con.Open();
 
       }
 
   }


 
   public static DataTable SelectWithString(string TblNmaestring[] Filedsstring CondFiledstring Match)
 
   {

 
       if (Fileds.Length == 0)
 
       {
 
           MessageBox.Show("تاكد من ملئ مصفوفة الحقول");
 
           return null;
 
       }

 
       string SelectStatement "Select ";
 
       string SetFileds "";
 
       foreach (string str in Fileds)
 
       {
 
           SetFileds += str ",";
 
       }

 
       if (SetFileds.EndsWith(","))
 
           SetFileds SetFileds.Remove(SetFileds.Length 11);

 
       SelectStatement += SetFileds " From " TblNmae " Where " CondFiled " Like '" Match "' ";
 
       if (Con.ConnectionString == null)
 
           Con.ConnectionString ConnectionString;
 
       OleDbCommand Cmd = new OleDbCommand(SelectStatementCon);
 
       DataTable Dt = new DataTable();
 
       Dt.Clear();
 
       OleDbDataAdapter Da = new OleDbDataAdapter(Cmd);
 
       if (Con.State == ConnectionState.Closed)
 
           Con.Open();
 
       Da.Fill(Dt);
 
       Cmd.Dispose();
 
       return Dt;
 
   }

 
   public static DataTable SelectWithInteger(string TblNmaestring[] Filedsstring CondFiledint ID)
 
   {

 
       if (Fileds.Length == 0)
 
       {
 
           MessageBox.Show("تاكد من ملئ مصفوفة الحقول");
 
           return null;
 
       }

 
       string SelectStatement "Select ";
 
       string SetFileds "";
 
       foreach (string str in Fileds)
 
       {
 
           SetFileds += str ",";
 
       }

 
       if (SetFileds.EndsWith(","))
 
           SetFileds SetFileds.Remove(SetFileds.Length  11);

 
       SelectStatement += SetFileds " From " TblNmae " Where " CondFiled " Like '" ID "' ";
 
       if (Con.ConnectionString == null)
 
           Con.ConnectionString ConnectionString;
 
       OleDbCommand Cmd = new OleDbCommand(SelectStatementCon);
 
       DataTable Dt = new DataTable();
 
       Dt.Clear();
 
       OleDbDataAdapter Da = new OleDbDataAdapter(Cmd);
 
       if (Con.State == ConnectionState.Closed)
 
           Con.Open();
 
       Da.Fill(Dt);
 
       Cmd.Dispose();
 
       return Dt;
 
   }


 
   public static DataTable SelectFTableNormal(string TblNmaestring[] Fileds)
 
   {
 
       if (Fileds.Length == 0)
 
       {
 
           MessageBox.Show("تاكد من ملئ مصفوفة الحقول");
 
           return null;
 
       }

 
       string SelectStatement "Select ";
 
       string SetFileds "";
 
       foreach (string str in Fileds)
 
       {
 
           SetFileds += str ",";
 
       }

 
       if (SetFileds.EndsWith(","))
 
           SetFileds SetFileds.Remove(SetFileds.Length 11);

 
       SelectStatement += SetFileds " From " TblNmae;
 
       if (Con.ConnectionString == null)
 
           Con.ConnectionString ConnectionString;
 
       OleDbCommand Cmd = new OleDbCommand(SelectStatementCon);
 
       DataTable Dt = new DataTable();
 
       Dt.Clear();
 
       OleDbDataAdapter Da = new OleDbDataAdapter(Cmd);
 
       if (Con.State == ConnectionState.Closed)
 
           Con.Open();
 
       Da.Fill(Dt);
 
       Cmd.Dispose();
 
       return Dt;
 
   }

 
   public static string GetFiled(string ReturnFiledstring Tblstring CondFiledstring Id)
 
   {
 
       string serch "";
 
       serch "Select " ReturnFiled " From " Tbl " Where " CondFiled " Like '" Id "' ";

 
       OleDbCommand Cmd = new OleDbCommand(serchCon);
 
       string ReturnResult "";
 
       OpenConnect();
 
       OleDbDataReader red Cmd.ExecuteReader();
 
       while (red.Read())
 
       {
 
           if (red.HasRows)
 
           {
 
               if ((red[ReturnFiled] != null) | red[ReturnFiled].ToString().Length 0)
 
               {
 
                   ReturnResult red[ReturnFiled].ToString();
 
               }
 
               else
                
{
 
                   ReturnResult null;
 
               }
 
           }
 
       }
 
       red.Close();
 
       Cmd.Dispose();
 
       CloseConnect();
 
       return ReturnResult;
 
   }


و هذا كود النموذج
PHP كود :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 
WindowsFormsApplication1
{
 
   public partial class TForm Form
    
{
 
       public TForm()
 
       {
 
           InitializeComponent();
 
       }


 
   DataTable TB_Content,TB_F ,TB_M = new DataTable();
 
   string[] Fileds null;

 
       private void Cmb_F_SelectedIndexChanged(object senderEventArgs e)
 
       {
 
           Fileds = new string[] {"Cont_ID","Cont_Title"};
 
           TB_Content Connect.SelectWithInteger("TB_Content"Fileds"MF_ID"int.Parse(Cmb_F.SelectedValue.ToString() ));
 
           ListContent.DataSource TB_Content;
 
           ListContent.DisplayMember "Cont_Title";
 
           ListContent.ValueMember "Cont_ID";
 
       }


 
       private void ListContent_SelectedIndexChanged(object senderEventArgs e)
 
       {
 
           if (!(ListContent.SelectedValue is DataRowView))
 
           {
 
               richTextBox1.Text =Connect GetFiled("Content""TB_Content""Cont_ID"ListContent.SelectedValue.ToString());
 
           }

 
       }

 
       

        private void TForm_Load
(object senderEventArgs e)
 
       {
 
           Fileds = new string[] {"M_ID","M_Name"};
 
           TB_M Connect.SelectFTableNormal("TB_M"Fileds);
 
           Cmb_M.DataSource TB_M;
 
           Cmb_M.DisplayMember "M_Name";
 
       }

 
       private void Cmb_M_SelectedIndexChanged(object senderEventArgs e)
 
       {
 
           Fileds = new string[] {"MF_ID""F_Nmae"};
 
           TB_F Connect.SelectWithString("TB_MF"Fileds"M_Nmae"Cmb_M.Text);
 
           Cmb_F.DataSource TB_F;
 
           Cmb_F.DisplayMember "F_Nmae";
 
           Cmb_F.ValueMember "MF_ID";
 
       }

 
       
    
}

و بالنسبة لرسالة الخطأ لو تكون بالانكليزي يكون احسن كوني لا افقه الفرنسية
بكل الاحوال جرب هذا و بعدها شوف اذا استمرت رسالة الخطأ بالظهور اخبرني (انا لم تظهر معي الرسالة)
اللهم لك الحمد كما ينبغي لجلال وجهك و عظيم سلطانك
في حل و ترحال
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
RE: مساعدة في عمل برنامج تعليم - بواسطة ابو ليلى - 16-11-16, 10:48 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم