0% found this document useful (0 votes)
66 views2 pages

Frncomputer Form Treenodemouseclickeventargs

This document contains code for a C# Windows Forms application that manages computer inventory. It defines forms, classes, and methods to load and display computer data in a tree view and datagrid. Methods allow selecting nodes to view computer details, adding/editing/deleting computers, and saving changes made to computer properties back to the database.

Uploaded by

than19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views2 pages

Frncomputer Form Treenodemouseclickeventargs

This document contains code for a C# Windows Forms application that manages computer inventory. It defines forms, classes, and methods to load and display computer data in a tree view and datagrid. Methods allow selecting nodes to view computer details, adding/editing/deleting computers, and saving changes made to computer properties back to the database.

Uploaded by

than19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ComputerManager
{
public partial class frnComputer : Form
{
public frnComputer()
{
InitializeComponent();
}
DataClasses1DataContext dt = new
DataClasses1DataContext();
private void textBox2_TextChanged(object sender,
EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
loadtreeview();
defaults();
}
private void loadtreeview()
{
var classlist = from clas in dt.tlbPhonghocs
select clas;
foreach (var clas in classlist)
{
//nham bai`
//root
TreeNode item = new TreeNode(clas.tenphong);
item.Tag = clas.msphong;/// dung cai nay` de luu
ma~ phong
/// //hieu tag dung lam gi chuwa?
/// ok
treeView1.Nodes.Add(item);
//level 1
//trong treeview la Node
// trong may cai khac la Items
}
}
private
void

getmaytinhs()
{
//lay msphong
string msphong =
treeView1.SelectedNode.Tag.ToString();
//tree view luon luon chon 1 Node
var maytinhs = from mt in dt.tblmaytinhs
where mt.msphong == msphong
select mt;
dataGridView1.DataSource = maytinhs;
dataGridView1.Columns[6].Visible = false;
}
private void treeView1_NodeMouseClick(object
sender, TreeNodeMouseClickEventArgs e)
{
}
private void treeView1_AfterSelect(object sender,
TreeViewEventArgs e)
{
//sau khi thay doi chon
getmaytinhs();
}
private void dataGridView1_RowEnter(object sender,
DataGridViewCellEventArgs e)
{
//lay maso cua may tinh dang dc chon...
//s kin ny l s kin 1 dng c chn./
//do datagridview c th chn nhiu dong nn mnh
kim tra
if (dataGridView1.SelectedRows.Count >
0&&dataGridView1.Rows[e.RowIndex].IsNewRow==fals
e)
{
string msMaytinh =
dataGridView1.SelectedRows[0].Cells[0].Value.ToString()
;
laythongtinmaytinh(msMaytinh);
}
}
private void laythongtinmaytinh(string msmaytinh)
{
var maytinh = (from mt in dt.tblmaytinhs
where mt.msmay == msmaytinh
select mt).SingleOrDefault();
if (maytinh != null)
{
txtmamay.Text = maytinh.msmay;
txtcpu.Text = maytinh.Cpu;
txtdisk.Text = maytinh.hardisk;
txtram.Text = maytinh.Ram;
txtmornito.Text = maytinh.Mornito;
// txtvga.Text = maytinh.vga;
txtphong.Text = maytinh.msphong;

}
defaults();

}
private void enable()
{
txtcpu.ReadOnly = false;
txtcpu.Clear();
txtphong.ReadOnly = false;
txtphong.Clear();
txtmornito.ReadOnly = false;
txtmornito.Clear();
txtmamay.ReadOnly = false;
txtmamay.Clear();
txtram.ReadOnly = false;
txtram.Clear();
txtdisk.ReadOnly = false;
txtdisk.Clear();
btnsave.Enabled = true;
}
private void defaults()
{
txtcpu.ReadOnly = true;
txtphong.ReadOnly = true;
txtmornito.ReadOnly = true;
txtmamay.ReadOnly = true;
txtram.ReadOnly = true;
txtdisk.ReadOnly = true;
btnsave.Enabled = false;
}
private void btnAdd_Click(object sender, EventArgs
e)
{ enable();
txtmamay.Focus();
btnAdd.Enabled = false;
btnsave.Enabled = true;
}
private void update()
{
var listcp = from cpts in dt.tblmaytinhs
select cpts;
dataGridView1.DataSource =listcp;
}
private void btnsave_Click(object sender, EventArgs
e)

{
tbm.msphong = txtphong.Text;
tbm.msmay = txtmamay.Text;
tbm.hardisk = txtdisk.Text;
tbm.Ram = txtram.Text;
tbm.Mornito = txtmornito.Text;
tbm.Cpu = txtcpu.Text;
try
{
dt.tblmaytinhs.InsertOnSubmit(tbm);
dt.SubmitChanges();
}
catch (Exception ex)
{
MessageBox.Show("Id is exist or Room not
available");
}
}
else {
MessageBox.Show("Not input validate");
}
btnsave.Enabled = false;
btnAdd.Enabled = true;
update();
}
private void btndel_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
string id =
dataGridView1.SelectedRows[0].Cells[0].Value.ToString()
;
var cp = (from cpt in dt.tblmaytinhs
where cpt.msmay == id
select cpt).SingleOrDefault();
dt.tblmaytinhs.DeleteOnSubmit(cp);
dt.SubmitChanges();
}
getmaytinhs();

{
tblmaytinh tbm = new tblmaytinh();
var phong = (from p in dt.tlbPhonghocs
where p.msphong == txtphong.Text
select p).SingleOrDefault();

}
private void btnexit_Click(object sender, EventArgs
e)
{

if (txtcpu.Text != "" && txtdisk.Text != "" &&


txtmamay.Text != "" && txtmornito.Text != "" &&
txtphong.Text != "" && txtram.Text != "" && phong !=
null)

this.Close();
}

You might also like