private void LoadCBLoaiMH()
        {
            tblloaimathangBL ctr = new tblloaimathangBL();
            DataTable        dt  = new DataTable();

            dt = ctr.GetAll();
            cbLoaiMH.DataSource    = dt;
            cbLoaiMH.DisplayMember = "ten";
            cbLoaiMH.ValueMember   = "id";
        }
        private void LoadCBTKLoaiMH()
        {
            flagload = true;
            tblloaimathangBL ctr = new tblloaimathangBL();
            DataTable        dt  = new DataTable();

            dt = ctr.GetAll();
            cbTKLoaiMH.DataSource    = dt;
            cbTKLoaiMH.DisplayMember = "ten";
            cbTKLoaiMH.ValueMember   = "id";
            flagload = false;
        }
Exemple #3
0
        private void HienThiDS()
        {
            tblloaimathangBL _ctr = new tblloaimathangBL();
            DataTable        dt   = new DataTable();

            dt = _ctr.GetAll();
            if (dt != null)
            {
                c1FlexGrid1.DataSource = dt;
                dt.Columns.Add("TT", typeof(Int32));
                FormatGrid();
            }
        }
Exemple #4
0
        private void Delete()
        {
            tblloaimathangBL _ctr = new tblloaimathangBL();
            string           loi  = "";
            string           sten = "";
            string           iid  = "";
            int n = c1FlexGrid1.RowSel;

            if (n >= 1)
            {
                try { sten = c1FlexGrid1[c1FlexGrid1.RowSel, "ten"].ToString().Trim(); }
                catch { }
                try { iid = c1FlexGrid1[c1FlexGrid1.RowSel, "id"].ToString().Trim(); }
                catch { }
                DialogResult bien;
                bien = MessageBox.Show("Xác nhận xóa dữ liệu", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (bien == DialogResult.Yes)
                {
                    loi = _ctr.Delete(iid);
                    if (loi.Equals("") == true)
                    {
                        try { _ctrlog.Append(Data.use, "Xóa loại mặt hàng: " + sten.Trim()); }
                        catch { }
                        HienThiDS();
                    }
                    else
                    {
                        MessageBox.Show(loi, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Dữ liệu hiện tại đang trắng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            c1FlexGrid1.Focus();
        }
Exemple #5
0
        private void Save()
        {
            string                temploi = "";
            string                loi     = "";
            tblloaimathangBL      _ctr    = new tblloaimathangBL();
            List <tblloaimathang> lst     = new List <tblloaimathang>();

            lst = GetData();
            if (lst != null)
            {
                for (int i = 0; i < lst.Count; i++)
                {
                    loi = "";
                    tblloaimathang _obj = new tblloaimathang();
                    try { _obj = _ctr.GetByID(lst[i].id); }
                    catch { }
                    if (_obj == null)
                    {
                        try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten").ToString().Trim(); }
                        catch { }
                        if (loi.Equals("") == true)
                        {
                            loi = _ctr.Insert(lst[i]);
                            if (loi.Equals("") == false)
                            {
                                c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                            }
                            else
                            {
                                _ctrlog.Append(Data.use, "Thêm mới loại mặt hàng: " + lst[i].ten.Trim());
                            }
                        }
                        else
                        {
                            c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                        }
                        if (loi.Trim().Equals("") == false)
                        {
                            temploi = loi;
                        }
                    }
                    else
                    {
                        try { loi = c1FlexGrid1.GetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten").ToString().Trim(); }
                        catch { }
                        if (loi.Equals("") == true)
                        {
                            loi = _ctr.Update(lst[i]);
                            if (loi.Equals("") == false)
                            {
                                c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten", loi);
                                c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                            }
                            else
                            {
                                _ctrlog.Append(Data.use, "Cập nhật loại mặt hàng: " + lst[i].ten.Trim());
                            }
                        }
                        else
                        {
                            c1FlexGrid1.SetUserData(c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true), "ten", loi);
                            c1FlexGrid1.Rows[c1FlexGrid1.FindRow(lst[i].id.ToString().Trim(), 1, c1FlexGrid1.Cols["id"].Index, true, true, true)].Style = cserror;
                        }
                        if (loi.Trim().Equals("") == false)
                        {
                            temploi = loi;
                        }
                    }
                }
            }
            if (temploi.Trim().Equals("") == true)
            {
                HienThiDS();
                MessageBox.Show("Cập nhật dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Cập nhật dữ liệu không thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #6
0
        private List <tblloaimathang> GetData()
        {
            tblloaimathangBL      ctr = new tblloaimathangBL();
            List <tblloaimathang> lst = new List <tblloaimathang>();
            string loi = "";

            for (int i = 1; i < c1FlexGrid1.Rows.Count; i++)
            {
                if (c1FlexGrid1[i, "TT"].ToString().Equals("0") == false)
                {
                    try
                    {
                        loi = "";
                        tblloaimathang _obj = new tblloaimathang();
                        if (c1FlexGrid1[i, "kyhieu"].ToString().Trim().Equals("") == true || c1FlexGrid1[i, "kyhieu"] == null)
                        {
                            loi = "Ký hiệu loại mặt hàng không được để trắng.";
                            c1FlexGrid1.SetUserData(i, "ten", loi);
                            c1FlexGrid1.Rows[i].Style = cserror;
                        }
                        _obj.kyhieu = c1FlexGrid1[i, "kyhieu"].ToString();
                        if (c1FlexGrid1[i, "TT"].ToString().Equals("1") == true)
                        {
                            if (ctr.CheckExit("", _obj.kyhieu, "") == true)
                            {
                                loi = "Ký hiệu loại mặt hàng đã có trong cơ sở dữ liệu.";
                                c1FlexGrid1.SetUserData(i, "ten", loi);
                                c1FlexGrid1.Rows[i].Style = cserror;
                            }
                            _obj.id = Guid.NewGuid().ToString();
                            c1FlexGrid1[i, "id"] = _obj.id.Trim();
                        }
                        if (c1FlexGrid1[i, "TT"].ToString().Equals("2") == true)
                        {
                            _obj.id = c1FlexGrid1[i, "id"].ToString().Trim();
                            if (ctr.CheckExit(_obj.id, _obj.kyhieu, "") == true)
                            {
                                loi = "Ký hiệu loại mặt hàng đã có trong cơ sở dữ liệu.";
                                c1FlexGrid1.SetUserData(i, "ten", loi);
                                c1FlexGrid1.Rows[i].Style = cserror;
                            }
                        }
                        if (c1FlexGrid1[i, "ten"].ToString().Trim().Equals("") == true || c1FlexGrid1[i, "ten"] == null)
                        {
                            loi = "Tên loại mặt hàng không được để trắng.";
                            c1FlexGrid1.SetUserData(i, "ten", loi);
                            c1FlexGrid1.Rows[i].Style = cserror;
                        }
                        _obj.ten = c1FlexGrid1[i, "ten"].ToString();
                        if (c1FlexGrid1[i, "TT"].ToString().Equals("1") == true)
                        {
                            if (ctr.CheckExit("", "", _obj.ten) == true)
                            {
                                loi = "Tên loại mặt hàng đã có trong cơ sở dữ liệu.";
                                c1FlexGrid1.SetUserData(i, "ten", loi);
                                c1FlexGrid1.Rows[i].Style = cserror;
                            }
                            _obj.id = Guid.NewGuid().ToString();
                            c1FlexGrid1[i, "id"] = _obj.id.Trim();
                        }
                        if (c1FlexGrid1[i, "TT"].ToString().Equals("2") == true)
                        {
                            _obj.id = c1FlexGrid1[i, "id"].ToString().Trim();
                            if (ctr.CheckExit(_obj.id, "", _obj.ten) == true)
                            {
                                loi = "Tên loại mặt hàng đã có trong cơ sở dữ liệu.";
                                c1FlexGrid1.SetUserData(i, "ten", loi);
                                c1FlexGrid1.Rows[i].Style = cserror;
                            }
                        }
                        _obj.ghichu = c1FlexGrid1[i, "ghichu"].ToString();
                        lst.Add(_obj);
                    }
                    catch { }
                }
            }
            return(lst);
        }