예제 #1
0
        private void lueChungLoai_TextChanged(object sender, EventArgs e)
        {
            DataRowView row = lueChungLoai.Properties.GetDataSourceRowByKeyValue(lueChungLoai.EditValue) as DataRowView;

            try
            {
                int machungloai = int.Parse(row.Row["MaChungLoai"].ToString());
                lueLoaiHang.Properties.DataSource = LoaiHangService.GetByChungLoai(machungloai);
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể lấy mã chủng loại!");
                return;
            }
        }
예제 #2
0
        private void lueChungLoai_TextChanged(object sender, EventArgs e)
        {
            int         maChungLoai = -1;
            DataRowView row         = lueChungLoai.Properties.GetDataSourceRowByKeyValue(lueChungLoai.EditValue) as DataRowView;

            try
            {
                maChungLoai = int.Parse(row.Row["MaChungLoai"].ToString());
            }
            catch (Exception)
            {
                MessageBox.Show("Không thể lấy mã!");
            }
            if (maChungLoai != -1)
            {
                DataTable temp = LoaiHangService.GetByChungLoai(maChungLoai);
                if (temp.Rows.Count > 0)
                {
                    dtLoaiHang.Rows.Clear();
                    DataRow dr = dtLoaiHang.NewRow();
                    dr[0] = 0;
                    dr[1] = "Tất cả";
                    dtLoaiHang.Rows.Add(dr);
                    for (int i = 0; i < temp.Rows.Count; i++)
                    {
                        DataRow dr1 = dtLoaiHang.NewRow();
                        dr1[0] = temp.Rows[i].Field <int>("MaLoaiHang");
                        dr1[1] = temp.Rows[i].Field <string>("TenLoaiHang");
                        dtLoaiHang.Rows.Add(dr1);
                    }
                    lbcLoaiHang.DataSource = dtLoaiHang;
                }
                else
                {
                    lbcLoaiHang.DataSource = temp;
                }
            }
        }