public void SearchProduct(TextBox Name) { Dialog.DialogCOSaleProduct frm; frm = new Dialog.DialogCOSaleProduct(Name.Text.Trim(), Class.Function.GetTextId(txtSupplier.Text)); frm.ShowDialog(); getLevel(); if (frm.DialogResult == DialogResult.OK) { dgvSaleDetail.ColumnCount = 15; FormatdgvSaleAdding(); foreach (String id in frm.PoDetailId()) { String sql = "select distinct COSIGNMENT_STOCK_DETAIL.ProductId,PRODUCT.ProductName,'' as NumPack,UNITPACK.UnitPackName,'' as NumSale,UNITSALE.UnitSaleName," + "'' as [Weight],'ก.ก' as UnitWeight,isnull(ProductSetPriceLevel." + strLevel + ",'0') as UnitPrice,'' as Distext,'' as Dis,'' as DiscountBth,'' as w,'' as t," + "'' as totalprice from PRODUCT inner join COSIGNMENT_STOCK_DETAIL on COSIGNMENT_STOCK_DETAIL.ProductId=PRODUCT.ProductId inner join UNITPACK " + "on UNITPACK.UnitPackId=PRODUCT.UnitPackId inner join UNITSALE on UNITSALE.UnitSaleId=PRODUCT.UnitSaleId left join ProductSetPriceLevel " + "on ProductSetPriceLevel.ProductId=COSIGNMENT_STOCK_DETAIL.ProductId where COSIGNMENT_STOCK_DETAIL.ProductId='" + id + "'" + ""; DataTable dtNew = Class.DBConnString.clsDB.QueryDataTable(sql); foreach (DataRow row in dtNew.Rows) { uni = 0; for (int nbRow = 0; nbRow < dgvSaleDetail.Rows.Count; nbRow++) { string value = dgvSaleDetail.Rows[nbRow].Cells[0].Value.ToString(); if (id == value) { uni += 1; } } if (uni == 0) { dgvSaleDetail.Rows.Add(row.ItemArray); } foreach (DataGridViewRow r in dgvSaleDetail.Rows) { if (r.Index % 2 == 0) { r.DefaultCellStyle.BackColor = Color.LightBlue; } else { r.DefaultCellStyle.BackColor = Color.SkyBlue; } } } } } }
/*เก็บรายการสินค้าลงใน list และแสดงใน datagridview โดยเลือกสินค้าจาก dialog แสดงสินค้า*/ public void SearchProduct(TextBox Name) { Dialog.DialogCOSaleProduct frm; frm = new Dialog.DialogCOSaleProduct(Name.Text.Trim(), Class.Function.GetTextId(txtCustomer.Text)); frm.ShowDialog(); getLevel(); if (frm.DialogResult == DialogResult.OK) { dgvDetail.ColumnCount = 17; FormatdgvDetail(); foreach (String id in frm.PoDetailId()) { String sql = "select distinct CO_REQ_DETAIL.ProductId,PRODUCT.ProductName,'' as NumPack,UNITPACK.UnitPackName,'' as NumSale," + "UNITSALE.UnitSaleName,'' as [Weight],'ก.ก' as UnitWeight," + "isnull((select top 1 SALE_DETAIL.SaleDetailPriceUnit from SALE_DETAIL inner join SALE_HEAD " + "on SALE_HEAD.SaleHeadId=SALE_DETAIL.SaleHeadId where PRODUCT.ProductId = SALE_DETAIL.ProductId " + "order by SALE_HEAD.SaleHeadDate desc),'0') as UnitPrice," + "'' as Distext,'' as Dis,'' as DiscountBth,'' as w,'' as t," + "'' as totalprice,'' as CQHeadId,'' as CQDetailId from PRODUCT inner join CO_REQ_DETAIL on CO_REQ_DETAIL.ProductId=PRODUCT.ProductId inner join UNITPACK " + "on UNITPACK.UnitPackId=PRODUCT.UnitPackId inner join UNITSALE on UNITSALE.UnitSaleId=PRODUCT.UnitSaleId " + "where CO_REQ_DETAIL.ProductId='" + id + "'"; DataTable dtNew = Class.DBConnString.clsDB.QueryDataTable(sql); foreach (DataRow row in dtNew.Rows) { uni = 0; for (int nbRow = 0; nbRow < dgvDetail.Rows.Count; nbRow++) { string value = dgvDetail.Rows[nbRow].Cells[0].Value.ToString(); if (id == value) { uni += 1; } } if (uni == 0) { dgvDetail.Rows.Add(row.ItemArray); } foreach (DataGridViewRow r in dgvDetail.Rows) { if (r.Index % 2 == 0) { r.DefaultCellStyle.BackColor = Color.LightBlue; } else { r.DefaultCellStyle.BackColor = Color.SkyBlue; } } } } } }