Windows Form -----内容(4)

      

三个表中的下拉列表代码:

class DBconnection
    {
        public const string CONNECTIONSTRING = "server=.;database=mydb;uid=sa;pwd=5587725";
    }

class cbProd
    {
        private string _Prod_Code;

public string Prod_Code
        {
            get { return _Prod_Code; }
            set { _Prod_Code = value; }
        }
        private string _Prod_Name;

public string Prod_Name
        {
            get { return _Prod_Name; }
            set { _Prod_Name = value; }
        }
       
        public cbProd(string cd,string na)
        {
            _Prod_Code = cd;
            _Prod_Name = na;
        }
        public cbProd() { }
    }

class cbProdDA
    {
        private SqlConnection _Conn;
        private SqlCommand _Cmd;
        private SqlDataReader _DR;
        public cbProdDA()
        {
            _Conn = new SqlConnection(DBconnection.CONNECTIONSTRING);
            _Cmd = _Conn.CreateCommand();
        }
        public List<cbProd> Select()
        {
            List<cbProd> list=new List<cbProd>();
            _Cmd.CommandText = "select * from productor ";
            try
            {
                _Conn.Open();
                _DR = _Cmd.ExecuteReader();
                while (_DR.Read())
                {
                    cbProd data = new cbProd();
                    data.Prod_Name = _DR["Prod_Name"].ToString();
                    data.Prod_Code = _DR["Prod_Code"].ToString();
                    list.Add(data);
                }
            }
            finally
            {
                _Conn.Close();
            }
            return list;
        }
    }

class cbBrand
    {
        private string _Brand_Code;

public string Brand_Code
        {
            get { return _Brand_Code; }
            set { _Brand_Code = value; }
        }
        private string _Brand_Name;

public string Brand_Name
        {
            get { return _Brand_Name; }
            set { _Brand_Name = value; }
        }
        private string _Prod_Code;

public string Prod_Code
        {
            get { return _Prod_Code; }
            set { _Prod_Code = value; }
        }
        private string _Brand_Memo;

public string Brand_Memo
        {
            get { return _Brand_Memo; }
            set { _Brand_Memo = value; }
        }
        public cbBrand(string cd, string na)
        {
            _Brand_Code = cd;
            _Brand_Name = na;
        }
        public cbBrand() { }
    }

class cbBrandDA
    {
        private SqlConnection _Conn;
        private SqlCommand _Cmd;
        private SqlDataReader _DR;
        public cbBrandDA()
        {
            _Conn = new SqlConnection(DBconnection.CONNECTIONSTRING);
            _Cmd = _Conn.CreateCommand();
        }
        public List<cbBrand> Select(string cbProd_code)
        {
            List<cbBrand> list = new List<cbBrand>();
            _Cmd.CommandText = "select * from brand where [email protected]_code";
            _Cmd.Parameters.Clear();
            _Cmd.Parameters.AddWithValue("@prod_code",cbProd_code);
            try
            {
                _Conn.Open();
                _DR = _Cmd.ExecuteReader();
                while (_DR.Read())
                {
                    cbBrand data = new cbBrand();
                    data.Brand_Name = _DR["Brand_Name"].ToString();
                    data.Brand_Code = _DR["Brand_Code"].ToString();
                    data.Brand_Memo = _DR["Brand_Memo"].ToString();
                    data.Prod_Code = _DR["Brand_Code"].ToString();
                    list.Add(data);
                }
            }
            finally
            {
                _Conn.Close();
            }
            return list;
        }
    }

class cbCar
    {
        private string _Code;

public string Code
        {
            get { return _Code; }
            set { _Code = value; }
        }
        private string _Brand;

public string Brand
        {
            get { return _Brand; }
            set { _Brand = value; }
        }
        private string _Name;

public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        private DateTime _Time;

public DateTime Time
        {
            get { return _Time; }
            set { _Time = value; }
        }
        private decimal _Oil;

public decimal Oil
        {
            get { return _Oil; }
            set { _Oil = value; }
        }
        private int _Powers;

public int Powers
        {
            get { return _Powers; }
            set { _Powers = value; }
        }
        private int _Exhaust;

public int Exhaust
        {
            get { return _Exhaust; }
            set { _Exhaust = value; }
        }
        private decimal _Price;

public decimal Price
        {
            get { return _Price; }
            set { _Price = value; }
        }
        private string _Pic;

public string Pic
        {
            get { return _Pic; }
            set { _Pic = value; }
        }
        public cbCar(string cd, string na)
        {
            _Code = cd;
            _Name = na;
        }
        public cbCar() { }
    }

class cbCarDA
    {
        private SqlConnection _Conn;
        private SqlCommand _Cmd;
        private SqlDataReader _DR;
        public cbCarDA()
        {
            _Conn = new SqlConnection(DBconnection.CONNECTIONSTRING);
            _Cmd = _Conn.CreateCommand();
        }
        public List<cbCar> Select(string brand_code)
        {
            List<cbCar> list = new List<cbCar>();
            _Cmd.CommandText = "select * from Car where [email protected]_code";
            _Cmd.Parameters.Clear();
            _Cmd.Parameters.AddWithValue("@brand_code",brand_code);
            try
            {
                _Conn.Open();
                _DR = _Cmd.ExecuteReader();
                while (_DR.Read())
                {
                    cbCar data = new cbCar();
                    data.Code = _DR["Code"].ToString();
                    data.Name = _DR["Name"].ToString();
                    data.Brand = _DR["Brand"].ToString();
                    data.Time = Convert.ToDateTime(_DR["Time"]);
                    data.Oil = Convert.ToDecimal(_DR["Oil"]);
                    data.Powers = Convert.ToInt32(_DR["Powers"]);
                    data.Exhaust = Convert.ToInt32(_DR["Exhaust"]);
                    data.Price = Convert.ToDecimal(_DR["Price"]);
                    data.Pic = _DR["Pic"].ToString();
                    list.Add(data);
                }
            }
            finally
            {
                _Conn.Close();
            }
            return list;
        }
    }

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void FillcbProd()
        {
            //查数据
            List<cbProd> list = new cbProdDA().Select();
            list.Insert(0,new cbProd("-1","==请选择=="));
            //填进去
            Productor.DataSource = list;//将集合list 赋值给数据源
            Productor.DisplayMember = "Prod_Name";
            Productor.ValueMember="Prod_Code";
        }

private void FillcbBrand()
        {
            //获取当前选项(控件.SelectedItem)的code值
            string prod_code=(Productor.SelectedItem as cbProd).Prod_Code;  
            List<cbBrand> list = new cbBrandDA().Select(prod_code);
            list.Insert(0, new cbBrand("-1", "==请选择=="));
            Brand.DataSource = list;
            Brand.DisplayMember = "Brand_Name";
            Brand.ValueMember = "Brand_Code";
        }

private void FillcbCar()
        {
            string brand_code = (Brand.SelectedItem as cbBrand).Brand_Code;
            List<cbCar> list = new cbCarDA().Select(brand_code);
            list.Insert(0, new cbCar("-1", "==请选择=="));
            Car.DataSource = list;
            Car.DisplayMember = "Name";
            Car.ValueMember = "Code";
        }

private void Form1_Load(object sender, EventArgs e)
        {
            FillcbProd();
            FillcbBrand();
            FillcbCar();
        }

private void Productor_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillcbBrand();          
        }

private void Brand_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillcbCar();
        }
    }

时间: 2024-10-12 15:54:42

Windows Form -----内容(4)的相关文章

Windows Form -----内容(6)

FORM1 FORM2 添加在前面已经做过了,不再做过多的追叙.实现修改和删除的功能,主要用的知识点是:ListView: ListView: 主要是用来显示的控件.一.有五种显示的视图:大图标.小图标.平铺.列表.详细—— View属性*************二.ListView的结结构:1.ListView包括好多个ListViewItem,每个ListViewItem就是所显示的一项.    ListView1.Items --- ListViewItem项的集合    例如:    L

Windows Form -----内容(8)

窗体类型:SDI  MDI单文档窗体界面,多文档窗体界面 一.单文档窗体界面:有一个主窗体,其它的窗体是辅窗体和对话框.主窗体一旦关掉,整个程序全部结束. 案例一:如何做登录?1.确定好主窗体.在Program.cs文件中的Main函数,使用Application.Run()启动主窗体.Application.Run(new Main());2.做一个登录窗体.    登录验证完成后,不要关闭窗体,也不要显示主窗体.只需要给this.DialogResult赋个值即可.        priva

Windows Form -----内容(1)

窗体: 一.控制标题栏 Text--控制标题栏的文字 Icon--控制标题栏的图标 MaximizeBox--窗体标题栏的右上角是否有最大化框(ture/false) MinimizeBox--窗体标题栏的右上角是否有最小化框(ture/false) ControlBox--所有的最大化.最小化.关闭按钮(ture/false) 二.控制背景 BackColor--控制背景色 BackgroundImage--控制背景图 BackgroundImageLayout - 背景的布局方式 Tile-

Windows Form -----内容(7)

简单记录一下:对话框控件和布局控件 对话框:一.提示对话框:DialogResult result = MessageBox.Show("提示文字","标题文字",按钮设置,图标设置)if(result == 枚举){} 二.其它对话框:(一)ColorDialog:1.属性:    Color - 选中的颜色.2.方法:    ShowDialog() - 把颜色对话框显示出来.返回一个DialogResult对象.3.案例:            DialogR

Windows Form -----内容(10)

权限管理:一.设置权限:(一)设计界面:(二)代码:1.窗体加载时候:把人员加载上,把功能加载上.  **2.根据人员查看它相应的功能.**3.设置人员的功能.二.根据权限加载界面: namespace WindowsFormsApplication17 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Filluser() { List<UserPermiss

Windows Form -----内容(5)

同一表格下的三级联动:                 代码: class DBconnection    {        public const string CONNECTIONSTRING = "server=.;database=mydb;uid=sa;pwd=5587725";    } class chinastates    {        public string AreaCode { get; set; }        public string AreaN

Windows Form -----内容(12)流与事件

文件及文件夹操作:一.流:文件流:FileStream.用来操作文件.命名空间:System.IO;使用流的步骤:——最原生的流的操作.——通用性最强的.1.创建流.FileStream fs = new FileStream("文件路径",FileMode枚举);    FileMode.Appen - 如果存在,就打开追加:如果不存就新建    FileMode.Create - 如果存在,覆盖.如果不存在就新建.    FileMode.OpenOrCreate.如果存在就打开,

Liam的C# 学习历程(七):WPF(Windows Presentation Foundation)、Windows Form Applications

在今天的课堂中,老师向我们讲述了关于一些WPF(Windows Presentation Foundation)和Windows Form Applications的内容,接下来就让我们一起来复习一下: (一).WPF(Windows Presentation Foundation): WPF是一个重要运用于desktop手机开发方面.它使用到了一种XML的变形语言——XAML的语言(eXtensible Application Markup Language). 使用XAML开发人员可以对WP

如何用Web技术开发Windows Form应用

现在H5很热,很多互联网公司的产品都采用混合编程,其中各个平台客户端的“壳”为原生控件,但是内容很多都是Web网页,因此可以做出很多炫酷的效果.随着Node.js和Ionic等框架的出现,现在感觉JavaScript有一统Web.Mobile.PC三大平台应用开发的能力.在Windows Form 上,利用开源浏览器内核Chromium Embedded Framework (CEF),CEF可以实现C#调用JS,JS调用C#,可以很好的与Web进行应用交互.下面用一个简单的例子来说明. 1 新