Ejemplo n.º 1
0
 public DeletePhongBan(string text, TblPhongBan bophan, Show.DanhSachPhongBan dsbp)
 {
     InitializeComponent();
     this.bophan = bophan;
     this.dsbp   = dsbp;
     init();
 }
Ejemplo n.º 2
0
        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[4] is DataGridViewImageButtonSaveColumn && e.RowIndex >= 0 && senderGrid.Columns[5] is DataGridViewImageButtonDeleteColumn)
            {
                switch (e.ColumnIndex)
                {
                case 4:
                    TblPhongBan     data = new TblPhongBan();
                    DataGridViewRow row  = dataGridView1.Rows[e.RowIndex];
                    data.MaPhong  = row.Cells[0].Value.ToString();
                    data.TenPhong = row.Cells[1].Value.ToString();
                    data.GhiChu   = row.Cells[2].Value.ToString();
                    Add.AddPhongBan uc = new Add.AddPhongBan(data, "Cập nhật phòng ban", this);
                    uc.ShowDialog();
                    break;

                case 5:
                    TblPhongBan     data2 = new TblPhongBan();
                    DataGridViewRow row2  = dataGridView1.Rows[e.RowIndex];
                    data2.MaPhong  = row2.Cells[0].Value.ToString();
                    data2.TenPhong = row2.Cells[1].Value.ToString();
                    data2.GhiChu   = row2.Cells[2].Value.ToString();
                    Delete.DeletePhongBan uc2 = new Delete.DeletePhongBan("Bộ phận này", data2, this);
                    uc2.ShowDialog();
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public Result <TblPhongBan> updatePhongBan(TblPhongBan instance)
        {
            //var a = AutoMapper.Mapper.Map<TblTTNVCoBan, NhanVienDTO>(instance);
            var result = new Result <TblPhongBan>();
            var temp   = connect.TblPhongBans.Where(x => x.MaPhong == instance.MaPhong).FirstOrDefault();

            if (temp != null)
            {
                try
                {
                    temp = instance;
                    connect.TblPhongBans.Attach(temp);
                    connect.Entry(temp).State = EntityState.Modified;
                    connect.SaveChanges();
                    result.Success = true;
                    result.Message = "Thành công!";
                    result.Data    = instance;
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.Message = "Đã xảy ra lỗi khi thêm bản ghi! ";
                    result.Data    = instance;
                }
                return(result);
            }
            else
            {
                result.Success = false;
                result.Message = "Không tìm thấy bản ghi";
                return(result);
            }
        }
Ejemplo n.º 4
0
        public Result <TblPhongBan> addPhongBan(TblPhongBan instance)
        {
            var result = new Result <TblPhongBan>();
            var temp   = connect.TblPhongBans.Where(x => x.MaPhong == instance.MaPhong).FirstOrDefault();

            if (temp == null)
            {
                try
                {
                    connect.TblPhongBans.Add(instance);
                    connect.SaveChanges();
                    result.Success = true;
                    result.Message = "Thành công!";
                    result.Data    = instance;
                }
                catch (Exception e)
                {
                    result.Success = false;
                    result.Message = "Đã xảy ra lỗi khi thêm bản ghi! ";
                    result.Data    = instance;
                }
                return(result);
            }
            else
            {
                result.Success = false;
                result.Message = "Đã tồn tại bản ghi";
                result.Data    = instance;
                return(result);
            }
        }
Ejemplo n.º 5
0
        public TblPhongBan getOnePhongBan(string maPB)
        {
            TblPhongBan result = new TblPhongBan();

            result = connect.TblPhongBans.Where(x => x.MaPhong == maPB).FirstOrDefault();
            return(result);
        }
Ejemplo n.º 6
0
 public AddPhongBan(TblPhongBan data, string title, Show.DanhSachPhongBan dsbp)
 {
     InitializeComponent();
     this.Text = title;
     this.data = data;
     this.dsbp = dsbp;
     init();
 }
Ejemplo n.º 7
0
        private void btnSave_Click_1(object sender, EventArgs e)
        {
            TblPhongBan data = new TblPhongBan();

            data.MaPhong  = maBPTB.Text.ToString().Trim();
            data.TenPhong = tenBPTB.Text.ToString().Trim();
            data.GhiChu   = ghiChu.Text.ToString().Trim();
            data.MaBoPhan = comboBox1.SelectedValue.ToString();
            data.NgayTLap = dateTimePicker1.Value;
            if (mode == ADD)
            {
                Result <TblPhongBan> result = new PhongBanController().addPhongBan(data);
                if (result.Success)
                {
                    this.Hide();
                    dsbp.getData();
                    MessageBox.Show(result.Message.ToString());
                }
                else
                {
                    MessageBox.Show(result.Message.ToString());
                }
            }
            else if (mode == EDIT)
            {
                Result <TblPhongBan> result = new PhongBanController().updatePhongBan(data);
                if (result.Success)
                {
                    this.Hide();
                    dsbp.getData();
                    MessageBox.Show(result.Message.ToString());
                }
                else
                {
                    MessageBox.Show(result.Message.ToString());
                }
            }
        }