private void setGrdSale() { DataTable dt = new DataTable(); DataTable dt1 = new DataTable(); double amt = 0, amt1 = 0, amt2 = 0; dt = lc.lotdb.selectSumBySale(cboYear.Text, cboMonth.SelectedValue.ToString(), cboPeriod.SelectedValue.ToString()); dgvSale.Rows.Clear(); Font font = new Font("Microsoft Sans Serif", 12); dgvSale.SelectionMode = DataGridViewSelectionMode.CellSelect; if (dt.Rows.Count > 0) { dgvSale.RowCount = dt.Rows.Count + 1; //// +1 เพราะ row สุดท้ายไว้ summary } else { dgvSale.RowCount = 1; } dgvSale.ColumnCount = colSCnt; dgvSale.Columns[colSName].Width = 200; dgvSale.Columns[colSAmt].Width = 100; dgvSale.Columns[colSPay].Width = 80; dgvSale.Columns[colSId].Width = 100; //dgvRate.Columns[colRRow].HeaderText = "ลำดับ"; dgvSale.Columns[colSName].HeaderText = "sale"; dgvSale.Columns[colSAmt].HeaderText = "ยอด"; dgvSale.Columns[colSPay].HeaderText = "%ยอด"; dgvSale.Columns[colS3Up].HeaderText = "3บน"; dgvSale.Columns[colS3Tod].HeaderText = "3โต๊ด"; dgvSale.Columns[colS3Down].HeaderText = "3ล่าง"; dgvSale.Columns[colS2Up].HeaderText = "2บน"; dgvSale.Columns[colS2Tod].HeaderText = "2โต๊ด"; dgvSale.Columns[colS2Down].HeaderText = "2ล่าง"; dgvSale.Columns[colSUp].HeaderText = "วิ่งบน"; dgvSale.Columns[colSDown].HeaderText = "วิ่งล่าง"; dgvSale.Columns[colSStatusDiscount].HeaderText = "แทงถูก"; dgvSale.Columns[colSPerDiscount].HeaderText = "คงเหลือ"; dgvSale.Columns[colSId].HeaderText = " "; dgvSale.Columns[colSAmt].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight; dgvSale.Columns[colSPay].DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomRight; dgvSale.ReadOnly = true; if (dt.Rows.Count > 0) { //dgvSale.RowCount = dt.Rows.Count; for (int i = 0; i < dt.Rows.Count; i++) { Double reward = 0, nettotal = 0; dt1 = new DataTable(); //dgvRate[colRRow, i].Value = (i + 1); cItem = lc.getCboItem(cboSale, dt.Rows[i][lc.saledb.sale.Id].ToString()); dgvSale[colSName, i].Value = cItem.Text; dgvSale[colSAmt, i].Value = String.Format("{0:#,###,###.00}", dt.Rows[i]["amt"]); dgvSale[colSPay, i].Value = lc.getSalePercent(cboYear.Text, cboMonth.SelectedValue.ToString(), cboPeriod.SelectedValue.ToString(), dt.Rows[i][lc.saledb.sale.Id].ToString()); dt1 = lc.lotdb.selectSumBySale(cboYear.Text, cboMonth.SelectedValue.ToString(), cboPeriod.SelectedValue.ToString(), dt.Rows[i][lc.saledb.sale.Id].ToString()); dgvSale[colS3Up, i].Value = dt1.Rows[0][lc.lotdb.lot.r3Up].ToString(); dgvSale[colS3Tod, i].Value = dt1.Rows[0][lc.lotdb.lot.r3Tod].ToString(); dgvSale[colS3Down, i].Value = dt1.Rows[0][lc.lotdb.lot.r3Down].ToString(); dgvSale[colS2Up, i].Value = dt1.Rows[0][lc.lotdb.lot.r2Up].ToString(); dgvSale[colS2Down, i].Value = dt1.Rows[0][lc.lotdb.lot.r2Down].ToString(); //dgvSale[colSUp, i].Value = dt1.Rows[0][lc.lotdb.lot.rUp].ToString(); //dgvSale[colSDown, i].Value = dt1.Rows[0][lc.lotdb.lot.rDown].ToString(); dgvSale[colSId, i].Value = dt.Rows[i][lc.saledb.sale.Id].ToString(); amt += Double.Parse(dt.Rows[i]["amt"].ToString()); reward = Double.Parse(dt1.Rows[0][lc.lotdb.lot.r3Up].ToString()) + Double.Parse(dt1.Rows[0][lc.lotdb.lot.r3Tod].ToString()) + Double.Parse(dt1.Rows[0][lc.lotdb.lot.r3Down].ToString()) + Double.Parse(dt1.Rows[0][lc.lotdb.lot.r2Up].ToString()) + Double.Parse(dt1.Rows[0][lc.lotdb.lot.r2Down].ToString()) + Double.Parse(dt1.Rows[0][lc.lotdb.lot.rUp].ToString()) + Double.Parse(dt1.Rows[0][lc.lotdb.lot.rDown].ToString()); nettotal = Double.Parse(dgvSale[colSAmt, i].Value.ToString()) - Double.Parse(dgvSale[colSPay, i].Value.ToString()) - reward; amt1 += nettotal; amt2 += reward; dgvSale[colSStatusDiscount, i].Value = String.Format("{0:#,###,###.00}", reward); dgvSale[colSPerDiscount, i].Value = String.Format("{0:#,###,###.00}", nettotal); //dgvRate[colRId, i].Value = dt.Rows[i][lc.ratedb.rate.Id].ToString(); if ((i % 2) != 0) { dgvSale.Rows[i].DefaultCellStyle.BackColor = Color.LightSalmon; } } } dgvSale.RowHeadersVisible = false; dgvSale.Columns[colSId].Visible = false; //dgvSale.Columns[colSStatusDiscount].Visible = false; //dgvSale.Columns[colSPerDiscount].Visible = false; //dgvSale.Columns[colRRow].Visible = false; dgvSale[colSAmt, dgvSale.RowCount - 1].Value = String.Format("{0:#,###,###.00}", amt); dgvSale[colSPerDiscount, dgvSale.RowCount - 1].Value = String.Format("{0:#,###,###.00}", amt1); dgvSale[colSStatusDiscount, dgvSale.RowCount - 1].Value = String.Format("{0:#,###,###.00}", amt2); dgvSale.Font = font; dgvSale.ReadOnly = true; //setDataGrdThoo(); //setThooAmount(); }