public static bool edit(PhieuXuat phieu) { try { using (EntitiesDataContext db = new EntitiesDataContext()) { PHIEUXUAT px; px = (from p in db.PHIEUXUATs where p.masophieuxuat.Equals(phieu.MaSoPhieuXuat) select p).SingleOrDefault(); if (px == null) { return(false); } px.masodaily = phieu.MaSoDaiLy; px.ngaylap = phieu.NgayLap; px.nguoinhasach = phieu.NguoiNhan; px.trangthai = phieu.TrangThai; px.tongtien = phieu.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia); // tính tổng tiền các chi tiết db.CHITIETPHIEUXUATs.DeleteAllOnSubmit(px.CHITIETPHIEUXUATs); db.SubmitChanges(); foreach (ChiTietPhieuXuat ct in phieu.ChiTiet) { ct.MaSoPhieuXuat = phieu.MaSoPhieuXuat; Chitiet.add(ct); } return(true); } }catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } }
public static int add(PhieuXuat phieuxuat) { try { using (EntitiesDataContext db = new EntitiesDataContext()) { var phieu = new PHIEUXUAT { masodaily = phieuxuat.MaSoDaiLy, ngaylap = phieuxuat.NgayLap, nguoinhasach = phieuxuat.NguoiNhan, tongtien = phieuxuat.ChiTiet.Sum(ct => ct.SoLuong * ct.DonGia), trangthai = 0 }; db.PHIEUXUATs.InsertOnSubmit(phieu); db.SubmitChanges(); foreach (ChiTietPhieuXuat ct in phieuxuat.ChiTiet) { Chitiet.add(ct, phieu.masophieuxuat); } return(phieu.masophieuxuat); } }catch (Exception ex) { Console.WriteLine(ex.Message); return(0); } }
private void LinkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e) { try { Chitiet.madh = Convert.ToInt32(lbMadh.Text); Chitiet frm = new Chitiet(); frm.ShowDialog(); } catch (Exception) { return; } }
protected void load(string masp) { string connectionstring = ConfigurationManager.ConnectionStrings["pktphonedata"].ConnectionString; SqlConnection conn = new SqlConnection(connectionstring); SqlCommand cmd = new SqlCommand("select SanPham.*,TenSX from SanPham join NhaSanXuat on SanPham.MaSX = NhaSanXuat.MaSX where MaSP=@masp", conn); cmd.Parameters.AddWithValue("@masp", masp); SqlDataAdapter adapter; adapter = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); adapter.Fill(dt); adapter.Dispose(); Chitiet.DataSource = dt.DefaultView; Chitiet.DataBind(); cmd.CommandText = "select SLTon from SanPham where MaSP=@masp"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@masp", masp); conn.Open(); int slton = (int)cmd.ExecuteScalar(); conn.Close(); if (slton != 0) { foreach (RepeaterItem item in Chitiet.Items) { Label lb = item.FindControl("slt") as Label; lb.Text = "Còn hàng"; foreach (RepeaterItem item1 in Chitiet.Items) { HyperLink l = item.FindControl("link") as HyperLink; l.Visible = true; l.NavigateUrl = "giohang.aspx?masp=" + masp; } } } else { foreach (RepeaterItem item in Chitiet.Items) { Label lb = item.FindControl("slt") as Label; lb.Text = "Hết hàng"; foreach (RepeaterItem item1 in Chitiet.Items) { HyperLink l = item.FindControl("link") as HyperLink; l.Visible = false; } } } }