Exemplo n.º 1
0
        private void BilingListToDataGridView(List <PhieuNhapNN> phieuNhapNNs)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("STT");
            dt.Columns.Add("Ngày nhập");
            dt.Columns.Add("Nguyên liệu");
            dt.Columns.Add("Số lượng");
            dt.Columns.Add("Giá");
            int STT = 1;

            for (int i = 0; i < phieuNhapNNs.Count; i++, STT++)
            {
                PhieuNhapNN PN = phieuNhapNNs[i];
                dt.Rows.Add(new string[] { STT.ToString(), PN.ngayNhap.ToString(), PN.NguyenLieu.ten, PN.soLuong.ToString(), PN.giaDauVao.ToString() });
            }
            dataNhapNN.DataSource = dt;
        }
Exemplo n.º 2
0
        private void btnNhap_Click(object sender, EventArgs e)
        {
            if (txtGiaMua.Text == "" || txtTrongLuong.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!");
            }
            else
            {
                PhieuNhapNN phieuNhapNN = new PhieuNhapNN();
                phieuNhapNN.ngayNhap     = DateTime.Now;
                phieuNhapNN.maNguyenLieu = Int32.Parse(cbNguyenLieu.SelectedValue.ToString());
                phieuNhapNN.soLuong      = float.Parse(txtTrongLuong.Text);
                phieuNhapNN.giaDauVao    = decimal.Parse(txtGiaMua.Text);
                model.PhieuNhapNN.Add(phieuNhapNN);
                model.SaveChanges();

                NguyenLieu nguyenLieu = model.NguyenLieu.FirstOrDefault(x => x.ma == phieuNhapNN.maNguyenLieu);
                nguyenLieu.trongLuong = nguyenLieu.trongLuong + phieuNhapNN.soLuong;
                model.SaveChanges();
            }
            BilingListToDataGridView(model.PhieuNhapNN.OrderByDescending(x => x.ma).ToList());
        }