public void insert_PhieuThu(PhieuThu a)
        {
            QLVESODataContext db = new QLVESODataContext();

            db.PhieuThus.InsertOnSubmit(a);
            db.SubmitChanges();
        }
Esempio n. 2
0
 public ErrType Xoa1PhieuThu(PhieuThu phieu)
 {
     using (Connection db = new Connection())
     {
         PhieuThu a = db.PhieuThus.Find(phieu.PhieuThuID);
         if (a != null)
         {
             var dsChiTietPhieuThu = db.ChiTietPhieuThus.Where(x => x.PhieuThuID == phieu.PhieuThuID);
             if (dsChiTietPhieuThu.Count() != 0)
             {
                 foreach (ChiTietPhieuThu i in dsChiTietPhieuThu)
                 {
                     db.ChiTietPhieuThus.Remove(i);
                 }
                 db.PhieuThus.Remove(a);
                 db.SaveChanges();
                 return(ErrType.Succes);
             }
             else
             {
                 db.SaveChanges();
                 return(ErrType.Succes);
             }
         }
         else
         {
             return(ErrType.Empty);
         }
     }
 }
Esempio n. 3
0
        public IHttpActionResult PutPhieuThu(int id, PhieuThu phieuThu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != phieuThu.IDPhieuThu)
            {
                return(BadRequest());
            }

            db.Entry(phieuThu).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhieuThuExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 public bool UpdatePhieuThu(PhieuThu pt)
 {
     if (objPhieuThu.IsRowExists(pt.MaPhieuThu) && objNV.IsRowExists(pt.MaNhanVien) && objKH.IsRowExists(pt.MaKhachHang))
         return objPhieuThu.UpdateRow(pt);
     else
         return false;
 }
Esempio n. 5
0
        public async Task <IActionResult> PutPhieuThu([FromRoute] int id, [FromBody] PhieuThu phieuthu)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != phieuthu.PhieuThuId)
            {
                return(BadRequest());
            }

            _context.Entry(phieuthu).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhieuThuExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 6
0
 private void btsua_Click(object sender, EventArgs e)
 {
     try
     {
         PhieuThu pt = new PhieuThu();
         pt.MaPhieuThu = txt_MaPhieuThu.Text;
         pt.MaCongNo   = txt_MaCongNo.Text;
         pt.NgayThu    = DateTime.Parse(txt_Ngay.Text);
         pt.SoTienNop  = int.Parse(txt_SotienNop.Text);
         if (CB_flag.SelectedIndex == 0)
         {
             pt.Flag = 0;
         }
         else
         {
             pt.Flag = 1;
         }
         busPhieuThu.update_PhieuThu(pt);
         Load_Data();
     }
     catch
     {
         MessageBox.Show("Yêu cầu nhập đầy đủ dữ liệu");
     }
     resetForm();
 }
Esempio n. 7
0
 public ErrType Them1PhieuThu(PhieuThu phieu)
 {
     using (Connection db = new Connection())
     {
         using (var transaction = db.Database.BeginTransaction())
         {
             int thanhTien = 0;
             Console.WriteLine("so luong nguyen lieu ban: ");
             int n = int.Parse(Console.ReadLine());
             for (int i = 0; i < n; i++)
             {
                 ChiTietPhieuThu ct = new ChiTietPhieuThu();
                 ct.PhieuThuID  = phieu.PhieuThuID;
                 ct.NguyeLieuID = InputHelper.NhapInt("nhap ma nguyen lieu: ", "err");
                 ct.SoLuongBan  = InputHelper.NhapInt("nhap so luong cua nguyen lieu duoc ban: ", "err");
                 db.ChiTietPhieuThus.Add(ct);
                 NguyenLieu a = db.NguyenLieus.Find(ct.NguyeLieuID);
                 thanhTien    += ct.SoLuongBan * a.GiaBan;
                 a.SoLuongKho -= ct.SoLuongBan;
                 db.SaveChanges();
             }
             phieu.ThanhTien = thanhTien;
             db.PhieuThus.Add(phieu);
             db.SaveChanges();
             transaction.Commit();
             return(ErrType.Succes);
         }
     }
 }
Esempio n. 8
0
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            if (checkAddNewInformation())
            {
                //XtraMessageBox.Show("Các thông tin đã hợp lệ");
                PhieuThu tempPhieuThu = new PhieuThu(tempMaPT, Convert.ToDateTime(tempNgayLap), tempMaNV, tempMaKH,
                                                     tempSoTienNo, tempSoTienThu);
                bool inserted = false;
                inserted = UserControl_ListPhieuThu.objPhieuThuBUS.addPhieuThu(tempPhieuThu);
                if (inserted)
                {
                    //XtraMessageBox.Show("Cập nhật thành công!");
                    UserControl_ListPhieuThu.Instance.loadDanhSachPhieuThu();
                    UserControl_ListPhieuThu.Instance.BringToFront();

                    UserControl_ListPhieuThu.Instance.label_notification.Text = "Thêm thành công!";

                    //Enable các btn:
                    UserControl_ListButton_PhieuThu.Instance.btn_themMoi.Enabled = true;
                    UserControl_ListButton_PhieuThu.Instance.btn_Edit.Enabled    = false;
                    UserControl_ListButton_PhieuThu.Instance.btn_Xoa.Enabled     = false;
                }
                else
                {
                    XtraMessageBox.Show("Thêm không thành công!");
                }
            }
            else
            {
            }
        }
Esempio n. 9
0
        private void CommandBinding_Executed_LapPhieuThu(object sender, ExecutedRoutedEventArgs e)
        {
            PhieuThu a = new PhieuThu();

            a.MaPhieuThu = txtMaPT.Text.ToString();
            a.TongTien   = decimal.Parse(txtTongTien.Text.ToString());


            NhanVien nv = (NhanVien)xlNV.TimMa(txtNhanVienLP.Text.ToString());

            if (nv != null)
            {
                a.NhanVien = nv;
            }
            PhieuSDDV pk = (PhieuSDDV)xlPSDDV.Tim(dg.SelectedValue.ToString());

            if (pk != null)
            {
                a.PhieuSDDV = pk;
            }
            a.NgayLap = DateTime.Now;
            xlPT.Them(a);
            xlPSDDV.DaDongTien(dg.SelectedValue.ToString());

            //getDSPT();
            //getDSPSDDV();

            refresh();
            getDSPSDDV();
        }
Esempio n. 10
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            // save to database
            PhieuThu pt = new PhieuThu();

            pt.MaKH   = Convert.ToInt32(comboBox1.SelectedItem);
            pt.NgayPS = DateTime.Now;
            pt.SoPT   = db.PhieuThus.Count() + 1;
            pt.SoTien = Convert.ToDecimal(txtMoney.Text);

            db.PhieuThus.Add(pt);



            // open report dialog

            FormToView form = new FormToView();

            form.Address      = txtAddress.Text;
            form.HoaDonID     = pt.SoPT;
            form.NgayPS       = pt.NgayPS;
            form.CustomerName = txtName.Text;
            form.PostalCode   = db.DMKHs.FirstOrDefault(p => p.MaKH == pt.MaKH).MaST;
            form.SoTT         = pt.SoTien.ToString();
            rp_PhieuThu newPT = new rp_PhieuThu(form, rtDescription.Text);

            ReportPrintTool rp = new ReportPrintTool(newPT);

            rp.ShowPreviewDialog();
            rp.Report.CreateDocument();
        }
Esempio n. 11
0
        public PhieuThu getPhieuThu(string _maPhieuThu)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("PHIEUTHU_getPhieuThu", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                _maPT           = cmd.Parameters.Add(new SqlParameter("@MaPhieuThu", SqlDbType.VarChar, 10));
                _maPT.Value     = _maPhieuThu;

                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                SqlDataReader dr       = cmd.ExecuteReader();
                PhieuThu      phieuThu = null;
                if (dr.Read())
                {
                    phieuThu            = new PhieuThu();
                    phieuThu.maPhieuThu = dr["MaPT"].ToString();
                    phieuThu.ngayLap    = (DateTime)dr["NgayLap"];
                    phieuThu.maNV       = dr["MaNV"].ToString();
                    phieuThu.maKH       = dr["MaKH"].ToString();
                    phieuThu.soTienNo   = (int)dr["SoTienNo"];
                    phieuThu.soTienThu  = (int)dr["SoTienThu"];
                }
                conn.Close();
                return(phieuThu);
            }
            catch (Exception e)
            {
                conn.Close();
                Console.WriteLine("Lỗi: " + e.Message);
                return(null);
            }
        }
Esempio n. 12
0
        public PhieuThu getByID(int MaPhieuThu)
        {
            String query = "select MaPhieuThu NgayThuTien,SoTienThu from PhieuThu where MaPhieuThu = @MaPhieuThu";
            List <SqlParameter> sqlParameters = new List <SqlParameter>();
            SqlParameter        param         = new SqlParameter("MaPhieuThu", MaPhieuThu);

            sqlParameters.Add(param);
            DataTable dt = this.dp.ExecuteQuery(query, sqlParameters);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }
            else
            {
                PhieuThu phieuThu = new PhieuThu();
                phieuThu.MaPhieuThu  = (int)dt.Rows[0]["MaPhieuThu"];
                phieuThu.NgayThuTien = (DateTime)dt.Rows[0]["NgayThuTien"];
                phieuThu.SoTienThu   = (Decimal)dt.Rows[0]["SoTienThu"];



                return(phieuThu);
            }
        }
Esempio n. 13
0
 public ActionResult ThemMoi(PhieuThu _PhieuThu)
 {
     ViewBag.MaDaiLy = new SelectList(db.DaiLies.ToList().OrderBy(n => n.TenDaiLy), "MaDaiLy", "TenDaiLy");
     db.PhieuThus.Add(_PhieuThu);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Esempio n. 14
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            float CNo = 0;

            CNo = (float.Parse(txtSoTien.Text)) - (float.Parse(txtSoTienTra.Text));

            PhieuThu pt = new PhieuThu()
            {
                TenKH    = txtKhachHang.Text,
                MaCT     = txtTheoChungTu.Text,
                Ngay     = DateTime.Parse(dateHT.Text),
                SoTien   = float.Parse(txtSoTien.Text),
                ConNo    = CNo,
                DaTra    = float.Parse(txtSoTienTra.Text),
                NhanVien = txtMaNV.Text,
                GhiChu   = mmGhiChu.Text,
                Phieu    = txtPhieu.Text
            };

            if (pt_bus.ThemPT(pt) > 0)
            {
                MessageBox.Show("Lập phiếu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                XoaPT();
                this.Close();
            }
        }
Esempio n. 15
0
 /// <summary>
 /// add
 /// </summary>
 /// <param name="phieuthu"></param>
 public void AddPhieuThu(PhieuThu phieuthu)
 {
     using (conn)
     {
         if (conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         SqlCommand command = conn.CreateCommand();
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = "InsertUpdatePhieuThu";
         command.Parameters.Add("@MaPhieuThu", SqlDbType.VarChar, 20).Value   = phieuthu.MaPhieuThu;
         command.Parameters.Add("@NgayTaoPhieu", SqlDbType.VarChar, 20).Value = phieuthu.NgayTaoPhieu;
         command.Parameters.Add("@MaHocSinh", SqlDbType.Date).Value           = phieuthu.MaHocSinh;
         command.Parameters.Add("@MaNhanVien", SqlDbType.Decimal).Value       = phieuthu.MaNhanVien;
         command.Parameters.Add("@GhiChu", SqlDbType.Decimal).Value           = phieuthu.GhiChu;
         command.Parameters.Add("@Action", SqlDbType.VarChar, 10).Value       = "Insert";
         try
         {
             command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             throw ex;
         }
         finally
         {
             command.Dispose();
             conn.Dispose();
         }
     }
 }
Esempio n. 16
0
 public bool checkExistPhieuThu(PhieuThu phieuthu)
 {
     using (conn)
     {
         if (conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         SqlCommand command = conn.CreateCommand();
         try
         {
             command.CommandType = CommandType.StoredProcedure;
             command.CommandText = "GetPhieuThu";
             command.Parameters.Add("@MaHocSinh", SqlDbType.VarChar, 20).Value = phieuthu.MaHocSinh;
             command.Parameters.Add("@date", SqlDbType.VarChar, 7).Value       = phieuthu.NgayTaoPhieu;
             //command.;
             return(true);
         }
         catch (Exception ex)
         {
             return(false);
         }
         finally
         {
             command.Dispose();
             conn.Dispose();
         }
     }
 }
Esempio n. 17
0
 public bool Lap_PhieuThu(PhieuThu_DTO phieuthu)
 {
     try
     {
         PhieuThu pt = new PhieuThu();
         pt.MaPhieuThu         = phieuthu.MaPhieuThu;
         pt.SoPhieuThu         = phieuthu.SoPhieuThu;
         pt.LoaiThue           = phieuthu.LoaiThue;
         pt.LyDoNop            = phieuthu.LyDoNop;
         pt.DaDuyet            = phieuthu.DaDuyet;
         pt.NgayLapPhieu       = phieuthu.NgayLapPhieu;
         pt.LoaiPhieuThu       = phieuthu.LoaiPhieuThu;
         pt.IDKhachHang        = phieuthu.IDKhachHang;
         pt.IDNhanVienBanHang  = phieuthu.IDNhanVienBanHang;
         pt.IDNhanVienLapPhieu = phieuthu.IDNhanVienLapPhieu;
         _models.PhieuThus.Add(pt);
         _models.SaveChanges();
         var idphieuthu = pt.ID;
         foreach (var item in phieuthu.DSSanPham)
         {
             LapPhieuThu lpt = new LapPhieuThu();
             lpt.IDSanPham  = item.ID;
             lpt.IDPhieuThu = idphieuthu;
             lpt.DonGia     = item.DonGia;
             lpt.SoLuong    = item.SoLuong;
             _models.LapPhieuThus.Add(lpt);
         }
         _models.SaveChanges();
         return(true);
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Esempio n. 18
0
 //Click vào lưới
 private void dgv_DanhSachPhieuThu_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     //Nút sửa
     if (e.ColumnIndex == dgv_DanhSachPhieuThu.Columns["Fix"].Index)
     {
         txt_MaPhieuThu.Text   = dgv_DanhSachPhieuThu.CurrentRow.Cells["MaPhieuThu"].Value.ToString();
         msk_NgayThu.Text      = Convert.ToDateTime(dgv_DanhSachPhieuThu.CurrentRow.Cells["NgayThu"].Value).ToShortDateString();
         txt_NhanVien.Text     = dgv_DanhSachPhieuThu.CurrentRow.Cells["NhanVien"].Value.ToString();
         txt_KhachHang.Text    = dgv_DanhSachPhieuThu.CurrentRow.Cells["KhachHang"].Value.ToString();
         txt_KhachHang.Enabled = false;
         txt_SoTien.Text       = Convert.ToDecimal(dgv_DanhSachPhieuThu.CurrentRow.Cells["SoTienThu"].Value).ToString("#,##");
         Insert = false;
     }
     //Nút xoá
     if (e.ColumnIndex == dgv_DanhSachPhieuThu.Columns["Delete"].Index)
     {
         if (MessageBox.Show("Bạn chắc chắn muốn xoá phiếu thu này", "Xác nhận", MessageBoxButtons.OKCancel) == DialogResult.OK)
         {
             PhieuThu pt = new PhieuThu();
             pt.MaPhieuThu = dgv_DanhSachPhieuThu.CurrentRow.Cells["MaPhieuThu"].Value.ToString();
             pt.KhachHang  = dgv_DanhSachPhieuThu.CurrentRow.Cells["KhachHang"].Value.ToString();
             if (pt.Delete())
             {
                 MessageBox.Show("Xoá thành công");
             }
             else
             {
                 MessageBox.Show("Xoá thất bại");
             }
         }
     }
 }
Esempio n. 19
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                PhieuThu pt = new PhieuThu();
                pt.MaPhieuThu = txt_MaPhieuThu.Text;
                pt.MaCongNo   = txt_MaCongNo.Text;
                pt.NgayThu    = DateTime.Parse(txt_Ngay.Text);
                pt.SoTienNop  = int.Parse(txt_SotienNop.Text);

                if (CB_flag.SelectedIndex == 0)
                {
                    pt.Flag = 0;
                }
                else
                {
                    pt.Flag = 1;
                }

                busPhieuThu.insert_PhieuThu(pt);
                Load_Data();
            }
            catch
            {
                MessageBox.Show("Có lỗi xảy ra");
            }
            resetForm();
        }
Esempio n. 20
0
 public ErrType ThemDSChiTietPhieuThu(PhieuThu phieu)
 {
     using (Connection db = new Connection())
     {
         PhieuThu a = db.PhieuThus.Find(phieu.PhieuThuID);
         if (a != null)
         {
             Console.WriteLine("nhap so luong chi tiet phieu thu can them: ");
             int n = int.Parse(Console.ReadLine());
             for (int i = 0; i < n; i++)
             {
                 ChiTietPhieuThu x = new ChiTietPhieuThu();
                 x.PhieuThuID  = phieu.PhieuThuID;
                 x.NguyeLieuID = InputHelper.NhapInt("nhap id cua nguyen lieu ban: ", "err");
                 x.SoLuongBan  = InputHelper.NhapInt("nhap so luong ban cua nguyen lieu: ", "err");
                 db.ChiTietPhieuThus.Add(x);
                 db.SaveChanges();
             }
             return(ErrType.Succes);
         }
         else
         {
             return(ErrType.NotExist);
         }
     }
 }
Esempio n. 21
0
        public bool Create(PhieuThu entity)
        {
            var phieuThu = db.PhieuThu.Add(entity);

            db.SaveChanges();
            return(phieuThu != null);
        }
Esempio n. 22
0
 public bool AddPhieuThu(PhieuThu pt)
 {
     if (!objPhieuThu.IsRowExists(pt.MaPhieuThu))
         return objPhieuThu.AddRow(pt);
     else
         return false;
 }
Esempio n. 23
0
 public IActionResult Create(decimal TongTien, int?KhachHangId, int?NCCId, int LoaiPhieuId)
 {
     if (ModelState.IsValid)
     {
         PhieuThu phieu = new PhieuThu();
         phieu.NgayLap     = DateTime.Now;
         phieu.NhanVienId  = _bookStoreData.findUserId(User.Identity.Name);
         phieu.TongTien    = TongTien;
         phieu.LoaiPhieuId = LoaiPhieuId;
         if (KhachHangId != null)
         {
             phieu.KhachHangId = KhachHangId;
             _bookStoreData.TaoPhieuThu(phieu);
             return(RedirectToAction("Index"));
         }
         if (KhachHangId == null && NCCId == null)
         {
             phieu.KhachHangId = 1;
             _bookStoreData.TaoPhieuThu(phieu);
             return(RedirectToAction("Index"));
         }
         if (NCCId != null)
         {
             phieu.NhaCungCapId = NCCId;
             _bookStoreData.TaoPhieuThu(phieu);
             return(RedirectToAction("Index"));
         }
     }
     return(View());
 }
Esempio n. 24
0
        public PhieuThu GetRow(string maPhieuThu)
        {
            try
            {
                var obj = new PhieuThu();
                if (_connection.State != ConnectionState.Open)
                {
                    _connection.Open();
                }

                SqlCommand command = new SqlCommand("SELECT * FROM PhieuThu WHERE MaPhieuThu = @maphieuthu", _connection);
                command.Parameters.Add("@maphieuthu", SqlDbType.Char).Value = maPhieuThu;

                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    obj.MaPhieuThu  = reader["MaPhieuThu"].ToString();
                    obj.MaNhanVien  = reader["MaNhanVien"].ToString();
                    obj.MaKhachHang = reader["MaKhachHang"].ToString();
                    obj.NgayThu     = (DateTime)reader["NgayThu"];
                    obj.SoTienThu   = (decimal)reader["SoTienThu"];
                    obj.LyDoThu     = reader["LyDoThu"] as string;
                    reader.Close();
                }
                return(obj);
            }
            catch (Exception ex)
            {
                _connection.Close();
                Console.WriteLine(ex.Message);
            }
            return(null);
        }
 public ActionResult Edit([Bind(Include = "MaPhieuThu,MaDaiLy,NgayNop,SoTienNop")] PhieuThu phieuThu)
 {
     if (ModelState.IsValid)
     {
         DbContextTransaction tran = db.Database.BeginTransaction();
         try
         {
             TempData["notice"]       = "Successfully edit";
             TempData["ma"]           = phieuThu.MaPhieuThu;
             phieuThu.Flag            = true;
             db.Entry(phieuThu).State = EntityState.Modified;
             db.SaveChanges();
             tran.Commit();
             tran.Dispose();
         }
         catch
         {
             tran.Rollback();
             tran.Dispose();
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.MaDaiLy = new SelectList(db.DaiLies, "MaDaiLy", "TenDaiLy", phieuThu.MaDaiLy);
     return(View(phieuThu));
 }
        public void delete_PhieuThu(string ma)
        {
            QLVESODataContext db = new QLVESODataContext();
            PhieuThu          b  = db.PhieuThus.Where(a => a.MaPhieuThu == ma).Single();

            db.PhieuThus.DeleteOnSubmit(b);
            db.SubmitChanges();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PhieuThu phieuThu = db.PhieuThus.Find(id);

            db.PhieuThus.Remove(phieuThu);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 28
0
        public async Task <ActionResult> DeleteConfirmed(string id)
        {
            PhieuThu phieuThu = await db.PhieuThus.FindAsync(id);

            db.PhieuThus.Remove(phieuThu);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public ActionResult DeleteConfirmed(string id)
        {
            PhieuThu phieuthu = db.PhieuThu.Find(id);

            phieuthu.Flag = false;

            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: Admin/PhieuThus/Create
        public ActionResult Create()
        {
            ViewBag.MaDaiLy = new SelectList(db.DaiLies, "MaDaiLy", "TenDaiLy");
            PhieuThu a = new PhieuThu();

            a.MaPhieuThu = getMaDL();
            a.Flag       = true;
            return(View(a));
        }