private void rptPO_Load(object sender, EventArgs e) { string strConn; strConn = DBConnString.strConn; Conn = new SqlConnection(); if (Conn.State == ConnectionState.Open) { Conn.Close(); } Conn.ConnectionString = strConn; Conn.Open(); sb = new StringBuilder(); String sql; sb.Remove(0, sb.Length); sb.Append("SELECT PO_HEAD.PoHeadId, PO_HEAD.PoHeadDate,"); sb.Append("PRODUCT.ProductId, PRODUCT.ProductName,"); sb.Append("SUPPLIER.SupplierName, SUPPLIER.SupplierAddress,"); sb.Append("SUPPLIER.SupplierContactName, SUPPLIER.SupplierPhone, SUPPLIER.SupplierFax,"); sb.Append("PO_DETAIL.PoDetailQuantity, PO_DETAIL.PoDetailUnitPrice,"); sb.Append("PO_DETAIL.PoDetailTotal "); sb.Append("FROM PO_HEAD INNER JOIN SUPPLIER ON PO_HEAD.SupplierId = SUPPLIER.SupplierId "); sb.Append("INNER JOIN PO_DETAIL ON PO_HEAD.PoHeadId = PO_DETAIL.PoHeadId "); sb.Append("INNER JOIN PRODUCT ON PO_DETAIL.ProductId = PRODUCT.ProductId "); sb.Append("WHERE (PO_HEAD.PoHeadId = @PoHeadId) "); sb.Append("ORDER BY dbo.PO_HEAD.PoHeadId DESC;"); sql = sb.ToString(); com = new SqlCommand(sql, Conn); com.Parameters.Add("@PoHeadId", SqlDbType.NVarChar).Value = PoId; PoHeadDa = new SqlDataAdapter(com); PoHeadDa.Fill(PoHeadDataset, "Po"); for (int i = 0; i < PoHeadDataset.Tables["Po"].Rows.Count; i++) { int IntPoHeadId1 = PoId; string StrPoHeadDate = PoHeadDataset.Tables["Po"].Rows[i]["PoHeadDate"].ToString(); string StrProductId = PoHeadDataset.Tables["Po"].Rows[i]["ProductId"].ToString(); string StrProductName = PoHeadDataset.Tables["Po"].Rows[i]["ProductName"].ToString(); string StrSupplierName = PoHeadDataset.Tables["Po"].Rows[i]["SupplierName"].ToString(); string StrSupplierAddress = PoHeadDataset.Tables["Po"].Rows[i]["SupplierAddress"].ToString(); string StrSupplierContactName = PoHeadDataset.Tables["Po"].Rows[i]["SupplierContactName"].ToString(); string StrSupplierPhone = PoHeadDataset.Tables["Po"].Rows[i]["SupplierPhone"].ToString(); string StrSupplierFax = PoHeadDataset.Tables["Po"].Rows[i]["SupplierFax"].ToString(); string StrPoDetailQuantity = PoHeadDataset.Tables["Po"].Rows[i]["PoDetailQuantity"].ToString(); string StrPoDetailUnitPrice = PoHeadDataset.Tables["Po"].Rows[i]["PoDetailUnitPrice"].ToString(); string StrPoDetailTotal = PoHeadDataset.Tables["Po"].Rows[i]["PoDetailTotal"].ToString(); X = new Dataset.DataSet(); if (X.DT_PO.Rows.Count > 0) { X.DT_PO.Clear(); } else { X.DT_PO.Rows.Add(IntPoHeadId1, StrPoHeadDate, StrProductId, StrProductName, StrSupplierAddress, StrSupplierContactName, StrSupplierPhone, StrSupplierFax, StrPoDetailQuantity, StrPoDetailUnitPrice, StrPoDetailTotal); } } Conn.Close(); Report.CtrPO Crv = new Report.CtrPO(); ; Crv.SetDataSource(PoHeadDataset.Tables["Po"]); //PoHeadDataset.Tables["Po"] CrvPO.ReportSource = Crv; CrvPO.Refresh(); if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print();//พิมพ์เอกสาร } }
private void rptBid_Load(object sender, EventArgs e) { string strConn; lblPoId.Text = Convert.ToString(PoId); strConn = DBConnString.strConn; Conn = new SqlConnection(); if (Conn.State == ConnectionState.Open) { Conn.Close(); } Conn.ConnectionString = strConn; Conn.Open(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append("SELECT BID_HEAD.BidHeadId,BID_HEAD.BidHeadDate, PRODUCT.ProductId, PRODUCT.ProductName,"); sb.Append("BID_DETAIL.BidDetailQuantity, UNITSALE.UnitSaleName, "); sb.Append("BID_DETAIL.BidDetailUnitPrice, BID_DETAIL.BidDetailTotal,SUPPLIER.SupplierName "); sb.Append("FROM ( BID_DETAIL INNER JOIN BID_HEAD ON BID_DETAIL.BidHeadId = BID_HEAD.BidHeadId ) "); sb.Append("INNER JOIN PRODUCT ON BID_DETAIL.ProductId = PRODUCT.ProductId "); sb.Append("INNER JOIN SUPPLIER ON BID_HEAD.SupplierId = SUPPLIER.SupplierId "); sb.Append("INNER JOIN UNITSALE ON PRODUCT.UnitSaleId = UNITSALE.UnitSaleId "); sb.Append("WHERE BID_HEAD.BidHeadId = @PoHeadId"); string sql = sb.ToString(); com = new SqlCommand(sql, Conn); com.Parameters.Add("@PoHeadId", SqlDbType.NVarChar).Value = PoId; PoHeadDa = new SqlDataAdapter(com); PoHeadDa.Fill(PoHeadDataset, "PoNoSubmit"); for (int i = 0; i < PoHeadDataset.Tables["PoNoSubmit"].Rows.Count; i++) { string StrPoHeadId1 = lblPoId.Text; string StrPoHeadDate = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["BidHeadDate"].ToString(); string StrProductId = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["ProductId"].ToString(); string StrProductName = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["ProductName"].ToString(); string StrPoDetailQuantity = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["BidDetailQuantity"].ToString(); string StrUnitSaleName = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["UnitSaleName"].ToString(); string StrPoDetailUnitPrice = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["BidDetailUnitPrice"].ToString(); string StrPoDetailTotal = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["BidDetailTotal"].ToString(); string StrSupplierName = PoHeadDataset.Tables["PoNoSubmit"].Rows[i]["SupplierName"].ToString(); X = new Dataset.DataSet(); if (X.DT_PoNoSubmit.Rows.Count > 0) { X.DT_PoNoSubmit.Clear(); } else { X.DT_PoNoSubmit.Rows.Add(StrPoHeadId1, StrPoHeadDate, StrProductId, StrProductName, StrPoDetailQuantity, StrUnitSaleName, StrPoDetailUnitPrice, StrPoDetailTotal, StrSupplierName); } } Conn.Close(); Report.CtrPoNoSubmit Crv = new Report.CtrPoNoSubmit(); ; Crv.SetDataSource(PoHeadDataset.Tables["PoNoSubmit"]); // CrvBidReport.ReportSource = Crv; CrvBidReport.Refresh(); if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print();//พิมพ์เอกสาร } }