Esempio n. 1
0
        private int Execute(string _operator, ListVatTu _operand, ListVatTu oldstate)
        {
            Command command = new Vattu_Command(_operator, _operand, oldstate);
            int     code    = command.Execute();

            _commands.Push(command);
            btnUndo.Enabled = true;
            return(code);
        }
Esempio n. 2
0
        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnXoa.Enabled = false;
            DataRow red = gridView1.GetFocusedDataRow();
            string  MA_LOAI_TRONGBANG = lvt.Select(string.Format("TENLOAI='{0}'", red["TENLOAI"].ToString()))[0][0].ToString();// doc ma loại trong gridview1

            MessageBox.Show(MA_LOAI_TRONGBANG);
            ListVatTu VT_TrongBang = new ListVatTu
            {
                MAVT   = red["MAVT"].ToString(),
                TENVT  = red["TENVT"].ToString(),
                DONVI  = red["DONVI"].ToString(),
                DONGIA = Convert.ToDecimal(red["DONGIA"].ToString()),
                MALOAI = MA_LOAI_TRONGBANG,
            };
            string    MA_LOAI_TRONGFORM = lvt.Select(string.Format("TENLOAI ='{0}'", cBoxLoaiVT.Text))[0][0].ToString();
            ListVatTu VT_TrongFORM      = new ListVatTu
            {
                MAVT   = tBoxMaVT.Text.Trim().ToUpper(),
                TENVT  = tboxTenVT.Text.Trim(),
                DONVI  = tBoxDonvi.Text.Trim(),
                DONGIA = Convert.ToDecimal(tBoxDongia.Text.Trim()),
                MALOAI = MA_LOAI_TRONGFORM,
            };

            try
            {
                int code = Execute("delete", VT_TrongFORM, VT_TrongBang);
                if (code == 0)
                {
                    //MessageBox.Show("Xoá thành công");
                    btnReload.PerformClick();
                    tBoxMaVT.Text    = "";
                    tboxTenVT.Text   = "";
                    tBoxDonvi.Text   = "";
                    tBoxDongia.Text  = "";
                    tBoxMaVT.Enabled = false;
                    btnHuy.Enabled   = false;
                    btnLuu.Enabled   = false;
                }
                else
                {
                    MessageBox.Show("Xoá thất bại.");
                }
            }
            catch
            {
                MessageBox.Show("Vật tư này đang được bán. Bạn không thể xóa");
            }
            tBoxMaVT.Enabled = false;
            btnXoa.Enabled   = true;
        }
Esempio n. 3
0
        private void btnXoa_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnXoa.Enabled = false;
            if (tBoxMaVatTu.Text.Trim() == "")
            {
                MessageBox.Show("Chọn vật tư trước khi xóa");
                return;
            }
            DataRow   row           = gridView1.GetFocusedDataRow();
            ListVatTu Kho_TrongBang = new ListVatTu
            {
                MAVT        = row["MAVT"].ToString(),
                TENVT       = row["TENVT"].ToString(),
                DVT         = row["DVT"].ToString(),
                SOLUONGTON  = Convert.ToInt32(row["SOLUONGTON"].ToString()),
                DONGIA      = float.Parse(row["DONGIA"].ToString()),
                TrangThaiVT = Convert.ToInt32(row["TrangThai"].ToString())
            };
            //MessageBox.Show(row["MAKHO"].ToString());
            ListVatTu Kho_TrongForm = new ListVatTu
            {
                MAVT        = tBoxMaVatTu.Text.Trim().ToString(),
                TENVT       = tboxTenVattu.Text.Trim().ToString(),
                DVT         = tBoxDonVi.Text.ToString(),
                SOLUONGTON  = checkSoluong(tboxSoluong.Text.ToString()),
                DONGIA      = float.Parse(tboxDongia.Text.ToString()),
                TrangThaiVT = checkTrangThaiVatTu(cboxTrangThai.Text.ToString())
            };

            try
            {
                int code = Execute("delete", Kho_TrongForm, Kho_TrongBang);
                if (code == 0)
                {
                    MessageBox.Show("Xoá thành công");
                    btnReload.PerformClick();
                }
                else
                {
                    MessageBox.Show("Vât tư này đang bán - hoặc trong kho còn vật tư =>Không được xóa");
                }
                tBoxMaVatTu.Enabled = false;
                btnXoa.Enabled      = true;
            }
            catch
            {
                MessageBox.Show("Vât tư này đang bán - hoặc trong kho còn vật tư =>Không được xóa");
            }
        }
Esempio n. 4
0
        public int Operation(string _operator, ListVatTu _operand, ListVatTu oldstate)
        {
            int code = 0;

            switch (_operator)
            {
            case "insert":
                code = CreateVatTu(_operand);
                break;

            case "update":
                code = UpdateVatTu(_operand);
                break;

            case "delete":
                code = RemoveVatTu(_operand);
                break;

            case "unupdate":
                code = UpdateVatTu(oldstate);
                break;
            }
            return(code);
        }
Esempio n. 5
0
 private int RemoveVatTu(ListVatTu vt)
 {
     string[] name  = { "@MAVT" };
     object[] param = { vt.MAVT };
     return(Access.ExecuteNonQuery("SP_XOA_VATTU", name, param, 1));
 }
Esempio n. 6
0
 private int UpdateVatTu(ListVatTu vt)
 {
     string[] name  = { "@MAVT", "@TENVT", "@DONVI", "@TRANGTHAI", "@DONGIA" };
     object[] param = { vt.MAVT, vt.TENVT, vt.DVT, vt.TrangThaiVT, vt.DONGIA };
     return(Access.ExecuteNonQuery("SP_SUA_VATTU", name, param, 5));
 }
Esempio n. 7
0
 private int CreateVatTu(ListVatTu vt)
 {
     string[] name  = { "@MAVT", "@TENVT", "@DONVI", "@DONGIA" };
     object[] param = { vt.MAVT, vt.TENVT, vt.DVT, vt.DONGIA };
     return(Access.ExecuteNonQuery("SP_TAO_VATTU", name, param, 4));
 }
Esempio n. 8
0
 public Vattu_Command(string _operator, ListVatTu _operand, ListVatTu oldstate)
 {
     this._operator = _operator;
     this._operand  = _operand;
     this.oldstate  = oldstate;
 }
Esempio n. 9
0
        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnLuu.Enabled = false;
            int    noError = 0;
            string errors  = "Nội dung bạn nhập có 1 số lỗi sau. Vui lòng sửa trước khi lưu.";

            if (tboxTenVT.Text.Trim() == "")
            {
                //MessageBox.Show("Nội dung câu hỏi không được bỏ trống");
                errors += "\r\n+ Tên vật tư bị bỏ trống";
                noError++;
            }
            if (tBoxDonvi.Text.Trim() == "")
            {
                //MessageBox.Show("Đáp án A không được bỏ trống");
                errors += "\r\n+ Đơn vị bị bỏ trống";
                noError++;
            }
            if (tBoxDongia.Text.Trim() == "")
            {
                //MessageBox.Show("Đáp án B không được bỏ trống");
                errors += "\r\n+ Đáp án B bị bỏ trống";
                noError++;
            }
            if (cBoxLoaiVT.Text.Trim() == "")
            {
                //MessageBox.Show("Đáp án C không được bỏ trống");
                errors += "\r\n+ Đơn giá bị bỏ trống";
                noError++;
            }
            if (noError > 0)
            {
                MessageBox.Show(errors);
                btnLuu.Enabled = true;
                return;
            }
            DataRow   red = gridView1.GetFocusedDataRow();
            string    MA_LOAI_TRONGBANG = lvt.Select(string.Format("TENLOAI='{0}'", red["TENLOAI"].ToString()))[0][0].ToString();// doc ma loại trong gridview1
            ListVatTu VT_TrongBang      = new ListVatTu
            {
                MAVT   = red["MAVT"].ToString(),
                TENVT  = red["TENVT"].ToString(),
                DONVI  = red["DONVI"].ToString(),
                DONGIA = Convert.ToDecimal(red["DONGIA"].ToString()),
                MALOAI = MA_LOAI_TRONGBANG,
            };

            string    MA_LOAI_TRONGFORM = lvt.Select(string.Format("TENLOAI ='{0}'", cBoxLoaiVT.Text))[0][0].ToString();
            ListVatTu VT_TrongFORM      = new ListVatTu
            {
                MAVT   = tBoxMaVT.Text.Trim().ToUpper(),
                TENVT  = tboxTenVT.Text.Trim(),
                DONVI  = tBoxDonvi.Text.Trim(),
                DONGIA = Convert.ToDecimal(tBoxDongia.Text.Trim()),
                MALOAI = MA_LOAI_TRONGFORM,
            };

            DataRow row = gridView1.GetFocusedDataRow();

            if (tBoxMaVT.Enabled)
            {
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    if (tBoxMaVT.Text.Trim().ToUpper().ToString() == gridView1.GetRowCellValue(i, gridView1.Columns["MAVT"]).ToString().Trim().ToUpper() ||
                        tboxTenVT.Text.Trim().ToString().ToUpper() == gridView1.GetRowCellValue(i, gridView1.Columns["TENVT"]).ToString().Trim().ToUpper())
                    {
                        MessageBox.Show("Vat tu them da ton tai");
                        break;
                    }
                    else
                    {
                        if (i == (gridView1.RowCount - 1))
                        {
                            try
                            {
                                int code = Execute("insert", VT_TrongFORM, VT_TrongBang);
                                if (code == 0)
                                {
                                    MessageBox.Show("Thêm vật tư thành công");
                                    btnReload.PerformClick();
                                    EnableFor();
                                }
                                else
                                {
                                    MessageBox.Show("Vat tu them da ton tai");
                                }
                                break;
                            }
                            catch
                            {
                                MessageBox.Show("Vat tu them da ton tai");
                            }
                        }
                    }
                }


                btnLuu.Enabled = true;
            }
            else
            {
                string tenvt = row["TENVT"].ToString().Trim().ToUpper();
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    if (tboxTenVT.Text.Trim().ToUpper().ToString() == gridView1.GetRowCellValue(i, gridView1.Columns["TENVT"]).ToString().Trim().ToUpper() &&
                        tboxTenVT.Text.Trim().ToUpper().ToString() != tenvt)
                    {
                        MessageBox.Show("Vat tu them da ton tai");
                        break;
                    }
                    else
                    {
                        if (i == (gridView1.RowCount - 1))
                        {
                            int code = Execute("update", VT_TrongFORM, VT_TrongBang);
                            if (code == 0)
                            {
                                MessageBox.Show("Lưu vật tư thành công");
                                btnReload.PerformClick();
                            }
                            else
                            {
                                MessageBox.Show("Lưu vật tư thất bại");
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            btnLuu.Enabled = false;
            int    noError = 0;
            string errors  = " Nội dung nhập có 1 số lỗi sau. Vui lòng sửa trước khi lưu";

            if (tBoxMaVatTu.Text.Trim() == "")
            {
                errors += "\r\n+ Mã vật tự bị bỏ trống";
                noError++;
            }
            if (tboxTenVattu.Text.Trim() == "")
            {
                errors += "\r\n+ Tên vật tư bị bỏ trống";
                noError++;
            }
            if (tBoxDonVi.Text.Trim() == "")
            {
                errors += "\r\n+ Tên Đơn vị bị bỏ trống";
                noError++;
            }
            if (tboxDongia.Text.Trim() == "")
            {
                errors += "\r\n+ Đơn giá bị bỏ trống";
                noError++;
            }

            if (noError > 0)
            {
                MessageBox.Show(errors);
                btnLuu.Enabled = true;
                return;
            }

            DataRow   row             = gridView1.GetFocusedDataRow();
            ListVatTu Vattu_TrongBang = new ListVatTu
            {
                MAVT        = row["MAVT"].ToString(),
                TENVT       = row["TENVT"].ToString(),
                DVT         = row["DVT"].ToString(),
                SOLUONGTON  = Convert.ToInt32(row["SOLUONGTON"].ToString()),
                DONGIA      = float.Parse(row["DONGIA"].ToString()),
                TrangThaiVT = Convert.ToInt32(row["TrangThai"].ToString())
            };

            ListVatTu Vattu_TrongForm = new ListVatTu
            {
                MAVT        = tBoxMaVatTu.Text.Trim().ToString(),
                TENVT       = tboxTenVattu.Text.Trim().ToString(),
                DVT         = tBoxDonVi.Text.ToString(),
                SOLUONGTON  = checkSoluong(tboxSoluong.Text.ToString()),
                DONGIA      = float.Parse(tboxDongia.Text.ToString()),
                TrangThaiVT = checkTrangThaiVatTu(cboxTrangThai.Text.ToString())
            };

            if (tBoxMaVatTu.Enabled)
            {
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    if (tBoxMaVatTu.Text.Trim().ToUpper().ToString() == gridView1.GetRowCellValue(i, gridView1.Columns[0]).ToString() ||
                        tboxTenVattu.Text.Trim().ToUpper().ToString() == gridView1.GetRowCellValue(i, gridView1.Columns[1]).ToString())
                    {
                        MessageBox.Show("Vật tư thêm đã tồn tại");
                        return;
                    }
                    else
                    {
                        if (i == (gridView1.RowCount - 1))
                        {
                            int code = Execute("insert", Vattu_TrongForm, Vattu_TrongBang);
                            if (code == 0)
                            {
                                MessageBox.Show("Thêm Vật tư Thành công");
                                btnReload.PerformClick();
                            }
                            else
                            {
                                MessageBox.Show("Vật tư đã tồn tại ở chi nhánh bên kia");
                            }
                            break;
                        }
                    }
                }


                btnLuu.Enabled = true;
            }

            else
            {
                for (int i = 0; i < gridView1.RowCount; i++)
                {
                    if (tboxTenVattu.Text.Trim().ToUpper().ToString() == gridView1.GetRowCellValue(i, gridView1.Columns[1]).ToString() &&
                        tBoxDonVi.Text.Trim() == gridView1.GetRowCellValue(i, gridView1.Columns[2]).ToString()
                        )
                    {
                        MessageBox.Show("Vật tu thêm đã tồn tại");
                        break;
                    }
                    else
                    {
                        if (i == (gridView1.RowCount - 1))
                        {
                            int code = Execute("update", Vattu_TrongForm, Vattu_TrongBang);
                            if (code == 0)
                            {
                                MessageBox.Show("Update Vattu thành công");
                                btnReload.PerformClick();
                            }
                            else
                            {
                                MessageBox.Show("Lưu vật tư thất bại");
                            }
                        }
                    }
                }
            }
        }