FTest.Code

Màu nền
Font chữ
Font size
Chiều cao dòng

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;

using Test.Biz;

namespace Test

{

    public partial class FTest : Form

    {

        public FTest()

        {

            InitializeComponent();

        }

        List<BizProduct> products = new List<BizProduct>();

        BizProduct pro = new BizProduct();

        private void FTest_Load(object sender, EventArgs e)

        {

        }

        private void btGetAll_Click(object sender, EventArgs e)

        {

            GetAllPro();

        }

        private void btAdd_Click(object sender, EventArgs e)

        {

            try

            {

                BizProduct pr = new BizProduct();

                pr.ProCode = tbProCode.Text;

                pr.ProName = tbProName.Text;

                pr.ProLine = tbProLine.Text;

                MessageBox.Show("Product ID :"+ pr.Add().ToString());

                GetAllPro();

                ResetTxt();

            }

            catch(Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

        }

        private void gridProduct_CellClick(object sender, DataGridViewCellEventArgs e)

        {

            if (e.RowIndex>=0)

            {

                tbProCode.Text = products[e.RowIndex].ProCode;

                tbProName.Text = products[e.RowIndex].ProName;

                tbProLine.Text = products[e.RowIndex].ProLine;

                pro = products[e.RowIndex];

            }

        }

        private void btUpdate_Click(object sender, EventArgs e)

        {

            try

            {

                BizProduct pr = new BizProduct();

                pr.ProCode = tbProCode.Text;

                pr.ProName = tbProName.Text;

                pr.ProLine = tbProLine.Text;

                pr.ProID = pro.ProID;

                MessageBox.Show("Update Success = "+ pr.Update());

                pro = null;

                GetAllPro();

                ResetTxt();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

        }

        private void btDelete_Click(object sender, EventArgs e)

        {

           MessageBox.Show("Delete Success= "+pro.Delete());

           pro = null;

           GetAllPro();

           ResetTxt();

        }

         public void GetAllPro()

         {

              BizProduct pr = new BizProduct();

            products = pr.GetAll();

            gridProduct.DataSource = products;

         }

        public void ResetTxt()

        {

           tbProCode.Text=null;

            tbProName.Text=null;

            tbProLine.Text=null;

        }

    }

}

Bạn đang đọc truyện trên: Truyen2U.Pro