private async void PostPhieuNhap()
        {
            PhieuNhapSach pn = new PhieuNhapSach();

            pn.NgayNhap = dateTimePicker1.Value;
            pn.Saches   = saches;

            StringContent content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(pn), Encoding.UTF8, "application/json");

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:5001/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = await client.PostAsync("api/phieunhapsach", content);

                if (response.IsSuccessStatusCode)
                {
                    if (response.StatusCode == System.Net.HttpStatusCode.OK)
                    {
                        MessageBox.Show("Lưu phiếu thành công", "Lưu phiếu thành công", MessageBoxButtons.OK);
                        button1_Click(null, null);
                    }
                    else
                    {
                        MessageBox.Show("Lưu phiếu thất bại", "Lưu phiếu thất bại", MessageBoxButtons.OK);
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase));
                }
            }
        }
Example #2
0
        private void phiếuNhậpSáchToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            PhieuNhapSach f = new PhieuNhapSach();

            f.MdiParent = this;
            f.Show();
        }
Example #3
0
 public bool AddRow(PhieuNhapSach obj)
 {
     try
     {
         if (_connection.State != ConnectionState.Open)
         {
             _connection.Open();
         }
         string sql = "INSERT INTO [dbo].[PhieuNhapSach]\n"
                      + "           ([MaPhieuNhapSach]\n"
                      + "           ,[NgayNhap]\n"
                      + "           ,[MaNhanVien])\n"
                      + "     VALUES\n"
                      + "           (@MaPhieuNhapSach\n"
                      + "           ,@NgayNhap\n"
                      + "           ,@MaNhanVien)";
         SqlCommand cmd = new SqlCommand(sql, _connection);
         cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach;
         cmd.Parameters.Add("@NgayNhap", SqlDbType.Date).Value        = obj.NgayNhap;
         cmd.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value      = obj.MaNhanVien;
         cmd.ExecuteNonQuery();
         _connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         _connection.Close();
         Console.WriteLine(ex.Message);
     }
     return(false);
 }
Example #4
0
 public bool UpdateRow(PhieuNhapSach obj)
 {
     try
     {
         if (_connection.State != ConnectionState.Open)
         {
             _connection.Open();
         }
         string sql = "UPDATE [dbo].[PhieuNhapSach]\n"
                      + "   SET [NgayNhap] = @NgayNhap\n"
                      + "      ,[MaNhanVien] = @MaNhanVien\n"
                      + " WHERE [MaPhieuNhapSach] = @MaPhieuNhapSach";
         var cmd = new SqlCommand(sql, _connection);
         cmd.Parameters.Add("@MaPhieuNhapSach", SqlDbType.Char).Value = obj.MaPhieuNhapSach;
         cmd.Parameters.Add("@NgayNhap", SqlDbType.Date).Value        = obj.NgayNhap;
         cmd.Parameters.Add("@MaNhanVien", SqlDbType.Char).Value      = obj.MaNhanVien;
         cmd.ExecuteNonQuery();
         _connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         _connection.Close();
         Console.WriteLine(ex.Message);
     }
     return(false);
 }
Example #5
0
        public PhieuNhapSach GetRow(string maPhieuNhapSach)
        {
            try
            {
                var obj = new PhieuNhapSach();
                if (_connection.State != ConnectionState.Open)
                {
                    _connection.Open();
                }

                SqlCommand command = new SqlCommand("SELECT * FROM PhieuNhapSach WHERE MaPhieuNhapSach = @maphieunhapsach", _connection);
                command.Parameters.Add("@maphieunhapsach", SqlDbType.Char).Value = maPhieuNhapSach;

                SqlDataReader reader = command.ExecuteReader();
                if (reader.Read())
                {
                    obj.MaPhieuNhapSach = reader["MaPhieuNhapSach"].ToString();
                    obj.MaNhanVien      = reader["MaNhanVien"].ToString();
                    obj.NgayNhap        = (DateTime)reader["NgayNhap"];
                    reader.Close();
                }
                return(obj);
            }
            catch (Exception ex)
            {
                _connection.Close();
                Console.WriteLine(ex.Message);
            }
            return(null);
        }
Example #6
0
        public PhieuNhapDTO ConvertPhieuNhapToPhieuNhapDTO(PhieuNhapSach coupon)
        {
            PhieuNhapDTO dto = new PhieuNhapDTO();

            dto.Id       = coupon.Id;
            dto.IdNxb    = (int)coupon.IdNxb;
            dto.TenNXB   = db.NhaXuatBan.Where(n => n.Id == coupon.IdNxb).FirstOrDefault().TenNxb;
            dto.NgayNhap = coupon.NgayNhap.Value.ToShortDateString();
            dto.TongTien = GetPriceForCoupon(coupon.Id);
            return(dto);
        }
        public void Insert(PhieuNhapSach info)
        {
            string sqlQuery = "insert into PhieuNhapSach values ('" +
                              info.MaPN + "','" +
                              info.MaSach + "','" +
                              info.MaNCC + "'," +
                              info.SoLuong + ",'" +
                              info.NgayNhap.ToShortDateString() + "')";

            ExecuteNonQuery(sqlQuery);
        }
        public void Update(PhieuNhapSach info)
        {
            string sqlQuery = "update PhieuNhapSach" +
                              " set MaSach='" + info.MaSach + "'," +
                              "MaNCC='" + info.MaNCC + "'" +
                              "SoLuong=" + info.SoLuong +
                              "NgayNhap='" + info.NgayNhap.ToShortDateString() + "'" +
                              "where MaPN='" + info.MaPN + "'";

            ExecuteNonQuery(sqlQuery);
        }
Example #9
0
 public bool AddPhieuNhap(PhieuNhapSach pn)
 {
     if (!objPhieuNhap.IsRowExists(pn.MaPhieuNhapSach))
     {
         return(objPhieuNhap.AddRow(pn));
     }
     else
     {
         return(UpdatePhieuNhap(pn));
     }
 }
Example #10
0
        // Chuyển giá trị trong Textbox thành PhieuNhapSach
        public PhieuNhapSach Textbox_To_PhieuNhapSach()
        {
            try
            {
                PhieuNhapSach result = new PhieuNhapSach();


                result.id         = (int)this.numbid.Value;
                result.id_tblSach = (int)this.numbid_tblSach.Value;
                result.soLuong    = (int)this.numbsoLuong.Value;
                result.ngay       = this.datengay.Value;

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
Example #11
0
 public bool UpdatePhieuNhap(PhieuNhapSach pn)
 {
     if (objPhieuNhap.IsRowExists(pn.MaPhieuNhapSach))
     {
         ChiTietPhieuNhapSachBus ctb = new ChiTietPhieuNhapSachBus();
         foreach (string ct in ctb.GetMaCTPNList(pn.MaPhieuNhapSach))
         {
             if (ctb.DeleteChiTietPN(ct))
             {
                 Console.WriteLine("Delete: {0}", ct);
             }
         }
         return(objPhieuNhap.UpdateRow(pn));
     }
     else
     {
         return(false);
     }
 }
Example #12
0
        public void CretaCoupon(NhaXuatBan nxb, List <ChiTietPhieuNhapSach> listChiTiet)
        {
            PhieuNhapSach coupon = new PhieuNhapSach();

            coupon.NgayNhap = DateTime.Now.Date;
            string id = "PNS" + nxb.Id + DateTime.Now.ToBinary().ToString();

            coupon.IdNxb = nxb.Id;
            coupon.Id    = id;
            db.PhieuNhapSach.Add(coupon);
            db.SaveChanges();
            foreach (ChiTietPhieuNhapSach item in listChiTiet)
            {
                item.IdPhieuNhap = id;
                Sach book = sachBL.GetBookById((int)item.IdSach);
                book.SoLuong += (int)item.SoLuong;
                db.Sach.Update(book);
                db.ChiTietPhieuNhapSach.Add(item);
            }
            db.SaveChanges();
        }
Example #13
0
        public ActionResult ThemPhieuNhap()
        {
            PhieuNhapSach pn = new PhieuNhapSach();

            pn.IDPhieuNhapSach = "";
            pn.NgayNhap        = DateTime.Now.Date;
            pn.TongSoLuong     = 0;
            pn.TongDongia      = 0;
            db.PhieuNhapSaches.Add(pn);
            db.SaveChanges();

            string ma    = "";
            var    phieu = db.PhieuNhapSaches.OrderByDescending(x => x.IDPhieuNhapSach).ToList();

            foreach (var item in phieu)
            {
                ma = item.IDPhieuNhapSach;
                break;
            }

            return(PartialView(db.PhieuNhapSaches.Find(ma)));
        }
        public List <PhieuNhapSach> GetList()
        {
            List <PhieuNhapSach> list = new List <PhieuNhapSach>();

            string sqlQuery = "select * from PhieuNhapSach";

            reader = ExecuteReader(sqlQuery);

            while (reader.Read())
            {
                PhieuNhapSach phieuNhapSach = new PhieuNhapSach();

                phieuNhapSach.MaPN     = reader["MaPN"].ToString();
                phieuNhapSach.MaSach   = reader["MaSach"].ToString();
                phieuNhapSach.MaNCC    = reader["MaNCC"].ToString();
                phieuNhapSach.SoLuong  = (int)reader["SoLuong"];
                phieuNhapSach.NgayNhap = (DateTime)reader["NgayNhap"];
                list.Add(phieuNhapSach);
            }

            return(list);
        }
Example #15
0
        // Chuyển giá trị trong DataGridView thành PhieuNhapSach
        public PhieuNhapSach DataGridView_To_PhieuNhapSach(int index)
        {
            try
            {
                PhieuNhapSach result = new PhieuNhapSach();


                var id = this.dgvData.Rows[index].Cells["id"].Value;
                if (id != null)
                {
                    result.id = int.Parse(id.ToString());
                }

                var id_tblSach = this.dgvData.Rows[index].Cells["id_tblSach"].Value;
                if (id_tblSach != null)
                {
                    result.id_tblSach = (id_tblSach == null ? null : (int?)int.Parse(id_tblSach.ToString()));
                }

                var soLuong = this.dgvData.Rows[index].Cells["soLuong"].Value;
                if (soLuong != null)
                {
                    result.soLuong = (soLuong == null ? null : (int?)int.Parse(soLuong.ToString()));
                }

                var ngay = this.dgvData.Rows[index].Cells["ngay"].Value;
                if (ngay != null)
                {
                    result.ngay = (ngay == null ? null : (DateTime?)DateTime.Parse(ngay.ToString()));
                }

                return(result);
            }
            catch (Exception ex) { ShowMessage(ex.Message, false); } // Không load được hoặc xảy ra lỗi
            return(null);
        }
 public void Update(PhieuNhapSach info)
 {
     data.Update(info);
 }
 public void Insert(PhieuNhapSach info)
 {
     data.Insert(info);
 }