private void addData(MonAnObj hh) { hh.MaMA = txtMa.Text.Trim(); hh.DonGia = int.Parse(txtDonGia.Text.Trim()); hh.SoLuong = txtSL.Text.Trim(); hh.TenMA = txtTen.Text.Trim(); }
private void btnLuu_Click(object sender, EventArgs e) { if (txtMaMA.Enabled) { try { MonAnObj monAnObj = new MonAnObj(txtMaMA.Text, txtTenMA.Text, txtDV.Text, decimal.Parse(txtDG.Text), txtGC.Text, (int)treeView.SelectedNode.Tag); if (monAn.AddMonAn(monAnObj)) { loadDataGrid((int)treeView.SelectedNode.Tag); HideTextMonAn(false); btnThem.Text = "&Nhập mới"; } else { MessageBox.Show("Không thêm được!"); txtMaMA.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { try { MonAnObj monAnObj = new MonAnObj(txtMaMA.Text, txtTenMA.Text, txtDV.Text, decimal.Parse(txtDG.Text), txtGC.Text, (int)treeView.SelectedNode.Tag); if (monAn.AddMonAn(monAnObj)) { loadDataGrid((int)treeView.SelectedNode.Tag); HideTextMonAn(false); btnThem.Text = "&Nhập mới"; } else { MessageBox.Show("Không sửa được!"); txtMaMA.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public bool SuaMonAn(MonAnObj monAn) { db = new DataClasses_QLMADataContext(); MonAn temp = db.MonAns.Where(x => x.maMonAn == monAn.MaMonAn).FirstOrDefault(); if (temp != null) { temp.maMonAn = monAn.MaMonAn; temp.tenMonAn = monAn.TenMonAn; temp.donViTinh = monAn.DonviTinh; temp.maNhom = (int)monAn.MaNhom; temp.donGia = (decimal)monAn.DonGia; temp.ghiChu = monAn.GhiChu; db.MonAns.InsertOnSubmit(temp); db.SubmitChanges(); } return(true); }
public List <MonAnObj> GetTheoNhom(int maNhom) { List <MonAnObj> lst = new List <MonAnObj>(); db = new DataClasses_QLMADataContext(); foreach (var item in db.MonAns.Where(x => x.maNhom == maNhom)) { MonAnObj monAn = new MonAnObj(); monAn.MaMonAn = item.maMonAn; monAn.TenMonAn = item.tenMonAn; monAn.DonviTinh = item.donViTinh; monAn.MaNhom = (int)item.maNhom; monAn.DonGia = (decimal)item.donGia; monAn.GhiChu = item.ghiChu; lst.Add(monAn); } return(lst); }
public bool UpdData(MonAnObj hhObj) { cmd.CommandText = "Update MonAn set TenMA = N'" + hhObj.TenMA + "', DonVi = N'" + hhObj.SoLuong + "', DonGia = " + hhObj.DonGia + " Where MaMA = '" + hhObj.MaMA + "'"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; try { con.OpenConn(); cmd.ExecuteNonQuery(); return(true); } catch (Exception ex) { string mex = ex.Message; cmd.Dispose(); con.CloseConn(); } return(false); }
public bool AddData(MonAnObj hhObj) { cmd.CommandText = "Insert into MonAn values ('" + hhObj.MaMA + "', N'" + hhObj.TenMA + "',N'" + hhObj.SoLuong + "' ," + hhObj.DonGia + " )"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; try { con.OpenConn(); cmd.ExecuteNonQuery(); return(true); } catch (Exception ex) { string mex = ex.Message; cmd.Dispose(); con.CloseConn(); } return(false); }
private void btnLuu_Click(object sender, EventArgs e) { MonAnObj hhObj = new MonAnObj(); addData(hhObj); if (flagLuu == 0) { if (hhCtr.AddData(hhObj)) { MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (flagLuu == 1) { if (hhCtr.UpdData(hhObj)) { MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (hhCtr.UpdData(hhObj)) { MessageBox.Show("Nhập hàng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Nhập hàng không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } frmMonAn_Load(sender, e); }
public bool UpdData(MonAnObj hhObj) { return(hhMod.UpdData(hhObj)); }
public bool AddData(MonAnObj hhObj) { return(hhMod.AddData(hhObj)); }