protected void btnsua_Click(object sender, EventArgs e) { if (txtMSP.Text == "" || txtsoluong.Text == "" || txtsoluong.Text == "") { Response.Write("<script>alert('Chưa nhập đủ thông tin');</script>"); } else if (IsNumber(txtsoluong.Text) || IsNumber(txtsoluong.Text)) { chitietphieunhap pn = new chitietphieunhap(); pn.MPN1 = int.Parse(Session["MPN"].ToString()); pn.MSP1 = int.Parse(txtMSP.Text); pn.SoLuongNhap1 = int.Parse(txtsoluong.Text); if (ado.suachitietphieunhap(pn)) { Response.Write("<script>alert('Đã sửa');</script>"); } else { Response.Write("<script>alert('Sản phẩm không có trong phiếu');</script>"); } Loadchitietphieunhap(); } else { Response.Write("<script>alert('Mã sản phẩm phải là số');</script>"); } }
public bool suachitietphieunhap(chitietphieunhap pn) { string qry = "update CTPhieuNhap set SoLuongNhap= '" + pn.SoLuongNhap1 + "' where MPN='" + pn.MPN1 + "' and MSP='" + pn.MSP1 + "'"; return(Insert_Update_Delete(qry)); }
public bool themtrungsanphampn(chitietphieunhap pn) { string qry = "update CTPhieuNhap set SoLuongNhap = SoLuongNhap + '" + pn.SoLuongNhap1 + "'where MSP = '" + pn.MSP1 + "'and MPN = '" + pn.MPN1 + "'"; return(Insert_Update_Delete(qry)); }
//------------------------------------------------------chi tiet phieu nhap--------------------------------- public bool themchitietphieunhap(chitietphieunhap pn) { string qry = "insert into CTPhieuNhap(MPN,MSP,SoLuongNhap) values('" + pn.MPN1 + "','" + pn.MSP1 + "','" + pn.SoLuongNhap1 + "') "; return(Insert_Update_Delete(qry)); }
protected void gvchitietphieunhap_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { int masp = int.Parse(gvchitietphieunhap.DataKeys[e.NewSelectedIndex].Value.ToString()); chitietphieunhap pn = new chitietphieunhap(); string a = Session["MPN"].ToString(); pn = ado.laychitietphieunhap(int.Parse(a), masp); txtMSP.Text = masp.ToString(); txtsoluong.Text = pn.SoLuongNhap1.ToString(); }
protected void btnthem_Click(object sender, EventArgs e) { if (txtMSP.Text == "" || txtsoluong.Text == "") { Response.Write("<script>alert('Chưa nhập đủ thông tin');</script>"); } else if (!IsNumber(txtsoluong.Text) || !IsNumber(txtMSP.Text)) { Response.Write("<script>alert('Dữ liệu nhập vào phải là số');</script>"); } else { chitietphieunhap pn = new chitietphieunhap(); chitietphieunhap pnktra = new chitietphieunhap(); sanpham sp = new sanpham(); pn.MPN1 = int.Parse(Session["MPN"].ToString()); pn.MSP1 = int.Parse(txtMSP.Text); pn.SoLuongNhap1 = int.Parse(txtsoluong.Text); pnktra = ado.laychitietphieunhap(int.Parse(Session["MPN"].ToString()), pn.MSP1); if (pnktra.MSP1 == pn.MSP1) { Response.Write("<script>alert('Đã cập nhật vào mã sản phẩm');</script>"); ado.themtrungsanphampn(pn); Loadchitietphieunhap(); } else { //////////////////////////////////////////////////////////////////////////////// sp = ado.laysanpham(pn.MSP1); if (sp.MSP1 == pn.MSP1) { Response.Write("<script>alert('Đã thêm sản phẩm vào phiếu nhập');</script>"); ado.themchitietphieunhap(pn); Loadchitietphieunhap(); } else { sanpham sp2 = new sanpham(); sp2.MSP1 = pn.MSP1; sp2.SoLuong1 = pn.SoLuongNhap1; Response.Write("<script>alert('Đã thêm sản phẩm vào danh sách sản phẩm và phiếu nhập');</script>"); ado.themsanphammoi(sp2); ado.themchitietphieunhap(pn); Loadchitietphieunhap(); } } } }
public chitietphieunhap laychitietphieunhap(int mapn, int masp) { chitietphieunhap a = new chitietphieunhap(); SqlConnection connect = new SqlConnection(connectionString); connect.Open(); string qry = "select * from CTPhieuNhap where MPN='" + mapn + "'and MSP='" + masp + "'"; SqlCommand cmd = new SqlCommand(qry, connect); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { a.MPN1 = reader.GetInt32(0); a.MSP1 = reader.GetInt32(1); a.SoLuongNhap1 = reader.GetInt32(2); } cmd.Dispose(); reader.Dispose(); connect.Close(); return(a); }
public int createDetailImport(chitietphieunhap ctpn) { db.chitietphieunhaps.Add(ctpn); db.SaveChanges(); return(1); }