Example #1
0
        private List <tblhangsanxuat> GetData()
        {
            tblhangsanxuatBL      ctr = new tblhangsanxuatBL();
            List <tblhangsanxuat> lst = new List <tblhangsanxuat>();
            string loi = "";

            for (int i = 1; i < c1FlexGrid1.Rows.Count; i++)
            {
                if (c1FlexGrid1[i, "TT"].ToString().Equals("0") == false)
                {
                    try
                    {
                        loi = "";
                        tblhangsanxuat _obj = new tblhangsanxuat();
                        if (c1FlexGrid1[i, "ten"].ToString().Trim().Equals("") == true || c1FlexGrid1[i, "ten"] == null)
                        {
                            loi = "Tên hãng sản xuất 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 hãng sản xuất đã 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 hãng sản xuất đã 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);
        }
Example #2
0
 /// <summary>
 /// Cập nhật dữ liệu vào bảng: tblhangsanxuat
 /// </summary>
 /// <param name="obj">objtblhangsanxuat</param>
 /// <returns>Trả về trắng: Cập nhật thành công; Trả về khác trắng: Cập nhật không thành công</returns>
 public string Update(tblhangsanxuat objtblhangsanxuat)
 {
     return(objtblhangsanxuatDA.Update(objtblhangsanxuat));
 }
Example #3
0
 /// <summary>
 /// Thêm mới dữ liệu vào bảng: tblhangsanxuat
 /// </summary>
 /// <param name="obj">objtblhangsanxuat</param>
 /// <returns>Trả về trắng: Thêm mới thành công; Trả về khác trắng: Thêm mới không thành công</returns>
 public string Insert(tblhangsanxuat objtblhangsanxuat)
 {
     return(objtblhangsanxuatDA.Insert(objtblhangsanxuat));
 }
Example #4
0
 public tblhangsanxuatBL()
 {
     objtblhangsanxuatDA = new tblhangsanxuat();
 }
Example #5
0
        private void Save()
        {
            string                temploi = "";
            string                loi     = "";
            tblhangsanxuatBL      _ctr    = new tblhangsanxuatBL();
            List <tblhangsanxuat> lst     = new List <tblhangsanxuat>();

            lst = GetData();
            if (lst != null)
            {
                for (int i = 0; i < lst.Count; i++)
                {
                    loi = "";
                    tblhangsanxuat _obj = new tblhangsanxuat();
                    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 hãng sản xuất: " + 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 hãng sản xuất: " + 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);
            }
        }