示例#1
0
        public async Task <IActionResult> PostLinhkien([FromBody] Linhkien linhkien)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Linhkien.Add(linhkien);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (LinhkienExists(linhkien.MaLk))
                {
                    return(new StatusCodeResult(StatusCodes.Status409Conflict));
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetLinhkien", new { id = linhkien.MaLk }, linhkien));
        }
示例#2
0
        public List <Linhkien> TimLinhkien(Linhkien sp)
        {
            List <Linhkien> list = GetAllLinhkien();
            List <Linhkien> kq   = new List <Linhkien>();

            if (string.IsNullOrEmpty(sp.Malk) && string.IsNullOrEmpty(sp.Tenlk) && sp.Gia == 0 && sp.Soluong == 0)
            {
                kq = list;
            }
            //Tim theo mã
            else if (sp.Malk != "")
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (list[i].Malk == sp.Malk)
                    {
                        kq.Add(new Linhkien(list[i]));
                    }
                }
            }
            else
            {
                kq = null;
            }
            return(kq);
        }
示例#3
0
        public async Task <IActionResult> PutLinhkien([FromRoute] string id, [FromBody] Linhkien linhkien)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != linhkien.MaLk)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
示例#4
0
        //Chèn một bản ghi  vào tệp
        public void ThemLinhkien(Linhkien lk)
        {
            StreamWriter fwrite = File.AppendText(Txtfile);

            fwrite.WriteLine();
            fwrite.Write(lk.Ngaygio + "#" + lk.Malk + "#" + lk.Tenlk + "#" + lk.Gia + "#" + lk.Soluong + "#" + lk.Tinhtien);
            fwrite.Close();
        }
示例#5
0
        public void Sua()
        {
            Console.Clear();
            Console.SetCursorPosition(10, 5); Console.WriteLine("╔══════════════════════════════════════════════════════════════════════════════════════════════════════╗");
            Console.SetCursorPosition(10, 6); Console.WriteLine("║                                       Sửa Thông Tin Linh Kiện                                        ║");
            Console.SetCursorPosition(10, 7); Console.WriteLine("╠══════════════════════════════════════════════════════════════════════════════════════════════════════╣");

            List <Linhkien> list = LK.GetAllLinhkien();
            string          Masua;

            Console.SetCursorPosition(10, 8); Console.Write("║ Nhập Mã Linh Kiện Cần Sửa :                                                                          ║");
            Console.SetCursorPosition(40, 8);
            Masua = Console.ReadLine();
            int i;

            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Malk == Masua)
                {
                    break;
                }
            }
            if (i < list.Count)
            {
                Console.SetCursorPosition(10, 9);  Console.WriteLine("║                                      Thông tin linh kiện                                             ║");
                Console.SetCursorPosition(10, 10); Console.WriteLine("╠══════════════════════════╦════════════╦═══════════════╦═══════════════╦══════════════╦═══════════════╣");
                Console.SetCursorPosition(10, 11); Console.WriteLine("║        Ngày Giờ          ║Mã Linh Kiện║ Tên Linh Kiện ║    Giá Bán    ║   Số Lượng   ║      Tiền     ║");
                Console.SetCursorPosition(10, 12); Console.WriteLine("╠══════════════════════════╬════════════╬═══════════════╬═══════════════╬══════════════╬═══════════════╣");
                Console.SetCursorPosition(10, 13); Console.WriteLine("║ " + list[i].Ngaygio + "    ║    " + list[i].Malk + "\t  ║   " + list[i].Tenlk + "\t  ║    " + list[i].Gia + "\t  ║    " + list[i].Soluong + "\t ║   " + list[i].Tinhtien + "\t ║");
                Console.SetCursorPosition(10, 14); Console.WriteLine("╚══════════════════════════╩════════════╩═══════════════╩═══════════════╩══════════════╩═══════════════╝");
                Linhkien lk = new Linhkien(list[i]);
                Console.SetCursorPosition(10, 16); Console.Write(" Nhập Tên Linh Kiện Mới :");
                string ten = Console.ReadLine();
                if (!string.IsNullOrEmpty(ten))
                {
                    lk.Tenlk = ten;
                }
                Console.SetCursorPosition(10, 18); Console.Write(" Nhập Giá Linh Kiện Mới :");
                double gia = double.Parse(Console.ReadLine());
                if (gia > 0)
                {
                    lk.Gia = gia;
                }
                Console.SetCursorPosition(10, 20); Console.Write(" Nhập Số Lượng Linh Kiện Mới :");
                int soluong = int.Parse(Console.ReadLine());
                if (soluong > 0)
                {
                    lk.Soluong = soluong;
                }
                LK.SuaLinhkien(lk);
            }
            else
            {
                Console.SetCursorPosition(10, 15); Console.WriteLine("╚══════════════════════════════════════════════════════════════════════════════════════════════════════╝");
                Console.SetCursorPosition(10, 11); Console.Write("  Không tồn tại mã linh kiện này.....");
                Console.ReadKey();
            }
        }
示例#6
0
 public void ThemLinhkien(Linhkien lk)
 {
     if (!string.IsNullOrEmpty(lk.Tenlk))
     {
         this.LK.ThemLinhkien(lk);
     }
     else
     {
         throw new Exception("du lieu sai");
     }
 }
示例#7
0
        public void Nhap()
        {
            Console.Clear();
            Console.SetCursorPosition(25, 5); Console.WriteLine("╔═══════════════════════════════════════════════════════════════════════════╗");
            Console.SetCursorPosition(25, 6); Console.WriteLine("║                         Thêm Thông Tin Linh Kiện                          ║");
            Console.SetCursorPosition(25, 7); Console.WriteLine("╠═══════════════════════════════════════════════════════════════════════════╣");
            Console.SetCursorPosition(25, 15); Console.WriteLine("╚═══════════════════════════════════════════════════════════════════════════╝");
            Linhkien lk = new Linhkien();

            Console.SetCursorPosition(27, 8); Console.Write("Nhập Mã Linh Kiện: ");
            lk.Malk = Console.ReadLine();
            Console.SetCursorPosition(27, 10); Console.Write("Nhập Tên Linh Kiện: ");
            lk.Tenlk = Console.ReadLine();
            Console.SetCursorPosition(27, 12); Console.Write("Nhập Giá Linh Kiện: ");
            lk.Gia = double.Parse(Console.ReadLine());
            Console.SetCursorPosition(27, 14); Console.Write("Nhập Số Lượng Linh Kiện: ");
            lk.Soluong = int.Parse(Console.ReadLine());
            LK.ThemLinhkien(lk);
        }
示例#8
0
        public void SuaLinhkien(Linhkien lk)
        {
            int             i;
            List <Linhkien> list = GetAllLinhkien();

            for (i = 0; i < list.Count; ++i)
            {
                if (list[i].Malk == lk.Malk)
                {
                    break;
                }
            }
            if (i < list.Count)
            {
                list.RemoveAt(i);
                list.Add(lk);
                this.LK.Update(list);
            }
            else
            {
                throw new Exception("Khong ton tai linh kien  nay");
            }
        }