Ejemplo n.º 1
0
        private void btnCapNhat_Click_1(object sender, EventArgs e)
        {
            try
            {
                ht = new HoTro();
                SqlCommand command = new SqlCommand();
                int maNguoiDung = DangNhap.idNguoiDung;

                for (int i = 0; i < dataGridViewDanhSach.Rows.Count; i++)
                {
                    DataGridViewRow row = dataGridViewDanhSach.Rows[i];
                    // insert PhieuNhapKho
                    int maNhaCungCap = ht.LayVeKhoa("Provider", "ProviderId", "ProviderName", row.Cells[8].Value.ToString());
                    command = new SqlCommand("insert into BillPurchase values(@ngaythang, @giaohang, @maNhacungcap, @manguoiDung)");
                    command.Parameters.Add("@ngaythang", ht.toSQLDateTime(txtNgayThang.Text));
                    command.Parameters.Add("@giaohang", row.Cells[9].Value.ToString());
                    command.Parameters.Add("@maNhacungcap", maNhaCungCap);
                    command.Parameters.Add("@manguoiDung", maNguoiDung);
                    ht.CapNhatDuLieu(command);

                    int soLuong = Int32.Parse(row.Cells[1].Value.ToString());
                    int donvi = ht.LayVeKhoa("Units", "UnitId", "UnitName", row.Cells[4].Value.ToString());
                    Int64 billPurchaseId = ht.LayGiaTriTruongKhoaVuaChen2("BillPurchase", "BillPurchaseId");
                    for (int j = 0; j < soLuong; j++)
                    {
                        // insert SanPham
                        int IdtenSp = ht.LayVeKhoa("ProductName", "ProductNameId", "ProdName", row.Cells[0].Value.ToString());
                        command = new SqlCommand("insert into Product values(" +
                            "@ngaysx, @ngayHetHan, @IdtenSP, @PurchasePrice, null," +
                            "null, @statusId, @billPurchaseId, null, @UnitId, @mota)");
                        command.Parameters.Add("@ngaysx", row.Cells[2].Value.ToString());
                        command.Parameters.Add("@ngayHetHan", row.Cells[3].Value.ToString());
                        command.Parameters.Add("@IdtenSP", IdtenSp);
                        command.Parameters.Add("@PurchasePrice", Int32.Parse(row.Cells[7].Value.ToString())); //VietLH change string to int on 9 Dec 2009
                        command.Parameters.Add("@statusId", 1);
                        command.Parameters.Add("@billPurchaseId", billPurchaseId);
                        command.Parameters.Add("@UnitId", donvi);
                        command.Parameters.Add("@mota", richTextBoxMota.Text);
                        ht.CapNhatDuLieu(command);
                    }
                }
                HoTro.thongBao("Nhập hàng thành công !");
                dataGridViewDanhSach.Rows.Clear();
            }
            catch (Exception ex)
            {
                HoTro.baoLoi(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void cboNhaSanXuat_SelectedIndexChanged(object sender, EventArgs e)
        {
            ht = new HoTro() ;
            int manId = ht.LayVeKhoa("Manufacturer", "ManId", "ManName", cboNhaSanXuat.Text) ;
            SqlConnection conn = ht.KetNoi();
            try {
                int countryId = 0;
                string CauLenh = "select  countryId from Manufacturer where manId= " + manId;
                SqlCommand cmd = new SqlCommand(CauLenh, conn);
                cmd.Connection.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    cboNguonGoc.SelectedValue = (Object)dr.GetInt32(0);
                }

            } catch(Exception ex) {
                MessageBox.Show(ex.Message) ;
                conn.Close() ;
            }
        }