private void btnLuu_Click(object sender, EventArgs e)
        {
            int result = -1;

            if (isValidData())
            {
                MayTinh mt = new MayTinh();
                mt.id      = txtID.Text;
                mt.cpu     = txtCpu.Text;
                mt.ram     = txtRam.Text;
                mt.vga     = txtVga.Text;
                mt.monitor = txtMonitor.Text;
                mt.hdd     = txtHdd.Text;
                mt.idPhong = getIdPhong(list, txtPhong.Text);
                if (mt.idPhong > 0)
                {
                    result = tblMayTinh.PUT(mt);
                }
                if (result == -1)
                {
                    MessageBox.Show("Lỗi kết nối cơ sở dữ liệu");
                }
                else if (result == 0)
                {
                    MessageBox.Show("Thông tin máy không tồn tại!");
                }
                else
                {
                    MessageBox.Show("Cập nhật thành công!");
                    ReloadAll();
                }
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            int result = -1;

            if (isValidData())
            {
                MayTinh mt = new MayTinh();
                mt.id      = txtID.Text;
                mt.cpu     = txtCpu.Text;
                mt.ram     = txtRam.Text;
                mt.vga     = txtVga.Text;
                mt.monitor = txtMonitor.Text;
                mt.hdd     = txtHdd.Text;
                mt.idPhong = getIdPhong(list, txtPhong.Text);
                if (mt.idPhong >= 0)
                {
                    result = tblMayTinh.POST(mt);
                }
                if (result == -1)
                {
                    MessageBox.Show("Không tìm thấy phòng hợp lệ!");
                }
                else if (result == 0)
                {
                    MessageBox.Show("Thông tin máy đã tồn tại!");
                }
                else
                {
                    MessageBox.Show("Thêm thành công!");
                    ReloadAll();
                }
            }
        }
 private void FocusListView(MayTinh mt)
 {
     foreach (ListViewItem i in lvw.Items)
     {
         if (i.Name.Equals(mt.id))
         {
             i.Selected = true;
             LoadMayTinhToForm(mt);
             return;
         }
     }
 }
        private void LoadMayTinhToForm(MayTinh mt)
        {
            txtID.Text      = mt.id;
            txtCpu.Text     = mt.cpu;
            txtHdd.Text     = mt.hdd;
            txtRam.Text     = mt.ram;
            txtVga.Text     = mt.vga;
            txtMonitor.Text = mt.monitor;
            int id = int.Parse(mt.idPhong.ToString());

            txtPhong.Text = getPhong(id).ten;
        }
 private void lvw_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (lvw.SelectedItems.Count > 0)
     {
         string  id = lvw.Items[lvw.SelectedIndices[0]].Name;
         MayTinh mt = tblMayTinh.GET(id).First();
         LoadMayTinhToForm(mt);
         for (int i = 1; i < lvw.SelectedItems.Count; i++)
         {
             lvw.SelectedItems[i].Selected = false;
         }
     }
 }
Esempio n. 6
0
 public int DELETE(string id)
 {
     try
     {
         MayTinh mt = dt.MayTinhs.Where(item => item.id == id).FirstOrDefault();
         dt.MayTinhs.DeleteOnSubmit(mt);
         dt.SubmitChanges();
         return(1);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
Esempio n. 7
0
        public int POST(MayTinh mt)
        {
            //System.Data.Common.DbTransaction transaction = dt.Connection.BeginTransaction();
            try
            {
                //dt.Transaction = transaction;

                dt.MayTinhs.InsertOnSubmit(mt);
                dt.SubmitChanges();
                //dt.Transaction.Commit();
                return(1);
            }
            catch (Exception e)
            {
                //dt.Transaction.Rollback();
                return(-1);
            }
        }
        private void tree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            TreeNode node  = tree.SelectedNode;
            int      level = node.Level;

            if (level == 0)
            {
                int id = int.Parse(node.Name);
                IEnumerable <MayTinh> mts = tblPhongMay.GetMayTinhByPhongMay(id);
                LoadMayTinhToListView(mts);
            }
            else if (level == 1)
            {
                int      idphong           = int.Parse(node.Parent.Name);
                PhongMay pm                = getPhong(idphong);
                MayTinh  mt                = (MayTinh)node.Tag;
                IEnumerable <MayTinh> list = tblPhongMay.GetMayTinhByPhongMay(pm.id);
                LoadMayTinhToListView(list);
                FocusListView(mt);
            }
        }
Esempio n. 9
0
 public int PUT(MayTinh mt)
 {
     try
     {
         IQueryable <MayTinh> item = from i in dt.MayTinhs
                                     where i.id.Equals(mt.id)
                                     select i;
         item.First().cpu     = mt.cpu;
         item.First().hdd     = mt.hdd;
         item.First().ram     = mt.ram;
         item.First().vga     = mt.vga;
         item.First().monitor = mt.monitor;
         item.First().idPhong = mt.idPhong;
         dt.SubmitChanges();
         return(1);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
 private void detach_MayTinhs(MayTinh entity)
 {
     this.SendPropertyChanging();
     entity.PhongMay = null;
 }
 private void attach_MayTinhs(MayTinh entity)
 {
     this.SendPropertyChanging();
     entity.PhongMay = this;
 }
 partial void DeleteMayTinh(MayTinh instance);
 partial void UpdateMayTinh(MayTinh instance);
 partial void InsertMayTinh(MayTinh instance);