コード例 #1
0
ファイル: toipham.cs プロジェクト: datacntt/kt_sql_dotnet
        private void txt_timkiem_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ketnoi conn    = new ketnoi();
                string timkiem = "";
                string tk      = txt_timkiem.Text.Trim();

                /*
                 * if ((txt_timkiem.Text == ""))
                 * {
                 *  MessageBox.Show("Bạn hãy nhập tên nhân viên cần tìm kiếm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 *  return;
                 * }
                 */
                //string sql = "SELECT * from toipham WHERE 1=1";

                string    ml        = "";
                string    tl        = cb_ml.Text.ToString();
                string    select_ma = "select DISTINCT(maloai) from loai where tenloai = '" + tl + "'";
                DataTable dt_ml     = conn.LoadDuLieu(select_ma);
                if (dt_ml != null)
                {
                    foreach (DataRow dr in dt_ml.Rows)
                    {
                        ml = dr["maloai"].ToString();
                    }
                }
                timkiem = "SELECT matoipham,tentoipham,tenloai from toipham,loai WHERE loai.maloai = toipham.maloai and tentoipham LIKE N'%" + tk + "%'";
                //if (txt_timkiem.Text != "")
                // timkiem += " and tentoipham LIKE N'%" + tk + "%'";
                DataTable dt = conn.LoadDuLieu(timkiem);

                /*
                 * if (dt.Rows.Count == 0)
                 *  MessageBox.Show("Không có tên toi pham cần tìm kiếm!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 * else MessageBox.Show("Có " + dt.Rows.Count + " nhân viên thoả mãn điều kiện!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 */

                data_toipham.DataSource = dt;
            }
            catch (Exception)
            {
                MessageBox.Show("Tim kiem dữ liệu không thành công");
            }
        }
コード例 #2
0
ファイル: toipham.cs プロジェクト: datacntt/kt_sql_dotnet
        private void button4_Click(object sender, EventArgs e)
        {
            DialogResult dialog;

            dialog = MessageBox.Show(" Thông tin sẽ bị thay đổi. Bạn có muốn tiếp tục", "Cảnh báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dialog == DialogResult.Yes)
            {
                ketnoi conn = new ketnoi();
                string mtp  = txt_mtp.Text.ToString();
                string ttp  = txt_ttp.Text.ToString();
                string ns   = tb_ns.Text.ToString();
                // lay ma loai tu ten loai
                string    ml        = "";
                string    tl        = cb_ml.Text.ToString();
                string    select_ma = "select DISTINCT(maloai) from loai where tenloai = '" + tl + "'";
                DataTable dt_ml     = conn.LoadDuLieu(select_ma);
                if (dt_ml != null)
                {
                    foreach (DataRow dr in dt_ml.Rows)
                    {
                        ml = dr["maloai"].ToString();
                    }
                }

                string sua_data = "Update toipham set tentoipham= N'" + ttp + "', ns = '" + ns + "', maloai = '" + ml + "' where matoipham = N'" + mtp + "'";
                int    ketqua   = conn.ThemSuaXoa(sua_data);
                if (ketqua >= 1)
                {
                    MessageBox.Show("Sua thành công");
                }
                else
                {
                    MessageBox.Show("Sua thất bai");
                }

                // load lai form
            }
            txt_mtp.Text = "";
            txt_ttp.Text = "";
            toipham_Load(sender, e);
        }
コード例 #3
0
ファイル: toipham.cs プロジェクト: datacntt/kt_sql_dotnet
        private void toipham_Load(object sender, EventArgs e)
        {
            ketnoi conn = new ketnoi();

            // load data gitview
            string    show_data = "select matoipham,tentoipham,tenloai,ns  from toipham,loai where loai.maloai = toipham.maloai";
            DataTable dt        = conn.LoadDuLieu(show_data);

            data_toipham.DataSource = dt;


            // load combobox nam sinh
            string t = DateTime.Now.ToString("yyyy");

            tb_ns.Items.Clear();
            for (int i = 1990; i < Convert.ToInt32(t); i++)
            {
                tb_ns.Items.Add(i);
            }
            tb_ns.SelectedIndex = 0;


            // load combobox ma toi pham
            string    load_ma = "select DISTINCT(tenloai) from loai";
            DataTable dt_ml   = conn.LoadDuLieu(load_ma);

            cb_ml.Items.Clear();
            if (dt_ml != null)
            {
                foreach (DataRow dr in dt_ml.Rows)
                {
                    cb_ml.Items.Add(dr["tenloai"].ToString());
                }
            }
            cb_ml.SelectedIndex = 0;
        }
コード例 #4
0
ファイル: toipham.cs プロジェクト: datacntt/kt_sql_dotnet
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                ketnoi conn = new ketnoi();
                string mtp  = txt_mtp.Text.ToString();
                string ttp  = txt_ttp.Text.ToString();
                string ns   = tb_ns.Text.ToString();
                // lay ma loai tu ten loai
                string    ml        = "";
                string    tl        = cb_ml.Text.ToString();
                string    select_ma = "select DISTINCT(maloai) from loai where tenloai = '" + tl + "'";
                DataTable dt_ml     = conn.LoadDuLieu(select_ma);
                if (dt_ml != null)
                {
                    foreach (DataRow dr in dt_ml.Rows)
                    {
                        ml = dr["maloai"].ToString();
                    }
                }

                // kiem tra matoipham
                int       dem     = 0;
                string    kt_matp = "select matoipham from toipham where matoipham = N'" + mtp + "'";
                DataTable kq      = conn.LoadDuLieu(kt_matp);
                if (kq != null)
                {
                    foreach (DataRow dr in kq.Rows)
                    {
                        dem++;
                    }
                }
                if (dem == 0)
                {
                    // MessageBox.Show("Thêm thành công");
                    string create_data = "insert into toipham values ('" + mtp + "','" + ttp + "','" + ml + "','" + ns + "')";
                    int    ketqua      = conn.ThemSuaXoa(create_data);
                    if (ketqua >= 1)
                    {
                        MessageBox.Show("Thêm thành công");
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bai");
                    }
                }
                else
                {
                    MessageBox.Show("Ma toi pham " + mtp + " da toi tai");
                }



                // load lai form
                txt_mtp.Text = "";
                txt_ttp.Text = "";
                toipham_Load(sender, e);
            }
            catch (Exception)
            {
                MessageBox.Show("Them dữ liệu không thành công");
            }
        }