Example #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            HangHoa hhObj = new HangHoa();

            HangHoaMod hhMod = new HangHoaMod();
            DataTable  dthh  = new DataTable();

            dthh = hhMod.GetData();
            DataTable dt = new DataTable();

            dt.Rows.Clear();
            dt.Columns.Add("MaHH");
            //for (int i = 0; i <= dt.Rows.Count; i++)
            //{
            //    for (int j = 0; j < dthh.Rows.Count; j++)
            //    {
            //        if (dt.Rows[i][0].ToString() != dthh.Rows[j][0].ToString())
            //        {
            if (flagLuu == 0)
            {
                addData(hhObj);
                if (hhCtr.AddData(hhObj))
                {
                    MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Thêm không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (flagLuu == 1)
            {
                editData(hhObj);
                if (hhCtr.UpdData(hhObj))
                {
                    MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                addDataSl(hhObj);
                if (hhCtr.UpdData(hhObj) && hhCtr.UpdNhapHang(dtDSCT))
                {
                    MessageBox.Show("Nhập hàng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Nhập hàng không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            frm_hanghoa_Load(sender, e);
            //}
            //else
            //{
            //    MessageBox.Show("Mã đã tồn tại", "Thông Báo", MessageBoxButtons.OKCancel);
            //    txtMahh.Focus();
            //}
            //    }

            //}
        }