示例#1
0
 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();
 }
示例#2
0
 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);
         }
     }
 }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
 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);
 }
示例#6
0
 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);
 }
示例#7
0
        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);
        }
示例#8
0
 public bool UpdData(MonAnObj hhObj)
 {
     return(hhMod.UpdData(hhObj));
 }
示例#9
0
 public bool AddData(MonAnObj hhObj)
 {
     return(hhMod.AddData(hhObj));
 }