2017-12-20 15 views
1

私は2つのdatagridviewを持っています。第一は資産であり、第二は負債である。これを1つのdatagridviewに垂直形式で追加することは可能ですか? 私はそれらを次々と整理することしかできません。私は彼らの間に国境が必要ですdatagridview。 まず第一にそれは可能ですか? 私のコードは、私が最小限にその幅を設定することにより、間の障壁としてのカラムを使用して、バックアップする背景色ですDatagridviewは2つの部分に分割されています

`

`ます。private void btnshow_Click(オブジェクト送信者、EventArgsの電子)

{ 
     int a = 0, b = 0; 
     decimal opstk = 0, clstk = 0,val=0; 
     string dateas = dtpdate.Value.ToString("yyyy-MM-dd"); 
     dataGridView1.Rows.Clear(); 
     dataGridView2.Rows.Clear(); 

     string qry = "select x.head_id, head_name,coalesce(op,0) as op from (select master_id, head_id, head_name, current_balance from heads where master_id='A' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='"+dateas+"' group by head_id) as y on x.head_id=y.head_id order by head_id"; 
     DataTable dt = obj.table(qry); 
     a = dt.Rows.Count; 
     for (int i = 0; i < dt.Rows.Count; i++) 
     { 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[i].Cells[0].Value = dt.Rows[i]["head_id"]; 
      dataGridView1.Rows[i].Cells[1].Value = dt.Rows[i]["head_name"]; 
      dataGridView1.Rows[i].Cells[2].Value = dt.Rows[i]["op"]; 


     } 
     string qry2 = "select 'Total' as head_name,sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id, head_name,current_balance from heads where master_id='A' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='"+dateas+"' group by head_id) as y on x.head_id=y.head_id) as z"; 
     //string qry2 = "select 'Total' as head_name, sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id,head_name from heads where master_id='A'and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number= l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id) as z"; 
     DataTable dt2 = obj.table(qry2); 
     dataGridView1.Rows.Add(); 
     dataGridView1.Rows[a].Cells[0].Value = dt2.Rows[0]["head_name"]; 
     dataGridView1.Rows[a].Cells[3].Value = dt2.Rows[0]["op"]; 
     //////////////////////////////////////////////////////////////////////////////// 
     string qry1 = "select x.head_id, head_name, coalesce(op,0) as op from (select master_id, head_id, head_name, current_balance from heads where master_id='B' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id order by head_id"; 
     DataTable dt1 = obj.table(qry1); 
     b = dt1.Rows.Count; 
     for (int i = 0; i < dt1.Rows.Count; i++) 
     { 
      dataGridView2.Rows.Add(); 
      dataGridView2.Rows[i].Cells[0].Value = dt1.Rows[i]["head_id"]; 
      dataGridView2.Rows[i].Cells[1].Value = dt1.Rows[i]["head_name"]; 
      dataGridView2.Rows[i].Cells[2].Value = Convert.ToDecimal(dt1.Rows[i]["op"]) * -1; 
     } 
     string qry3 = "select 'Total' as head_name, sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id, head_name,current_balance from heads where master_id='B' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id) as z"; 
     DataTable dt3 = obj.table(qry3); 
     dataGridView2.Rows.Add(); 
     dataGridView2.Rows[b].Cells[0].Value = dt3.Rows[0]["head_name"]; 
     dataGridView2.Rows[b].Cells[3].Value = Convert.ToDecimal(dt3.Rows[0]["op"]) * -1; 

     string qry4 = "select 'Closing Stock' as head_name, sum(stock) as op from (select sum(costbase*current_stock) as stock from itemstock ik,items i where i.item_id=ik.item_id union select sum(debit-credit) as stock from view_total_trans where transdate >='"+dateas+"') as x"; 
     DataTable dt4 = obj.table(qry4); 
     dataGridView1.Rows.Add(); 
     dataGridView1.Rows[a + 1].Cells[0].Value = dt4.Rows[0]["head_name"]; 
     dataGridView1.Rows[a + 1].Cells[3].Value = dt4.Rows[0]["op"]; 

     opstk =Convert.ToDecimal(dataGridView1.Rows[a].Cells[3].Value) + Convert.ToDecimal(dataGridView1.Rows[a+1].Cells[3].Value); 
     clstk = Convert.ToDecimal(dataGridView2.Rows[b].Cells[3].Value); 
     val = opstk - clstk; 
     if(val>0) 
     { 
      dataGridView2.Rows.Add(); 
      dataGridView2.Rows[b + 1].Cells[0].Value = "Net Loss"; 
      dataGridView2.Rows[b + 1].Cells[3].Value = val; 
      dataGridView2.Rows[b + 1].DefaultCellStyle.Format = "0.00##"; 

      dataGridView2.Rows.Add(); 
      dataGridView2.Rows[b + 2].Cells[3].Value = clstk + val; 
      dataGridView2.Rows[b + 2].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      dataGridView2.Rows[b + 2].DefaultCellStyle.Format = "0.00##"; 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[a + 2].Cells[3].Value = opstk; 
      dataGridView1.Rows[a + 2].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      dataGridView1.Rows[a + 2].DefaultCellStyle.Format = "0.00##"; 
     } 
     else 
     { 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[a + 2].Cells[0].Value = "Net Profit"; 
      dataGridView1.Rows[a + 2].Cells[3].Value = val * -1; 
      dataGridView1.Rows[a + 2].DefaultCellStyle.Format = "0.00##"; 



      dataGridView2.Rows.Add(); 
      dataGridView2.Rows[b + 1].Cells[3].Value = clstk; 
      dataGridView2.Rows[b + 1].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      dataGridView2.Rows[b + 1].DefaultCellStyle.Format = "0.00##"; 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[a + 3].Cells[3].Value = opstk+Convert.ToDecimal(dataGridView1.Rows[a+2].Cells[3].Value); 
      dataGridView1.Rows[a + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      dataGridView1.Rows[a + 3].DefaultCellStyle.Format = "0.00##"; 
     } 
    }` 
+0

罫線 - だからラインを意味しますか?あなたはWindowsフォームまたはwpfを使用しますか? – Raizzen

答えて

0

です。 コードは次のとおりです

private void btnshow_Click(object sender, EventArgs e) 
    { 
     int a = 0, b = 0; 
     decimal opstk = 0, clstk = 0,val=0; 
     string dateas = dtpdate.Value.ToString("yyyy-MM-dd"); 
     dataGridView1.Rows.Clear(); 
     string qry = "select x.head_id, head_name,coalesce(op,0) as op from (select master_id, head_id, head_name, current_balance from heads where master_id='A' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id order by head_id"; 
     DataTable dt = obj.table(qry); 
     a = dt.Rows.Count; 
     for (int i = 0; i < dt.Rows.Count; i++) 
     { 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[i].Cells[0].Value = dt.Rows[i]["head_id"]; 
      dataGridView1.Rows[i].Cells[1].Value = dt.Rows[i]["head_name"]; 
      dataGridView1.Rows[i].Cells[2].Value = dt.Rows[i]["op"]; 
     } 
     //////////////////////////////////////////////////////////////////////////////// 
     string qry1 = "select x.head_id, head_name, coalesce(op,0) as op from (select master_id, head_id, head_name, current_balance from heads where master_id='B' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id order by head_id"; 
     DataTable dt1 = obj.table(qry1); 
     b = dt1.Rows.Count; 
     for (int i = 0; i < dt1.Rows.Count; i++) 
     { 
      dataGridView1.Rows.Add();// 
      dataGridView1.Rows[i].Cells[5].Value = dt1.Rows[i]["head_id"];// 
      dataGridView1.Rows[i].Cells[6].Value = dt1.Rows[i]["head_name"];// 
      dataGridView1.Rows[i].Cells[7].Value = Convert.ToDecimal(dt1.Rows[i]["op"]) * -1;// 
     } 
     /////////////////////////// 
     if (a > b) 
     { 
      string qry2 = "select 'Total' as head_name,sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id, head_name,current_balance from heads where master_id='A' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id) as z"; 
      DataTable dt2 = obj.table(qry2); 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[a].Cells[0].Value = dt2.Rows[0]["head_name"]; 
      dataGridView1.Rows[a].Cells[3].Value = dt2.Rows[0]["op"]; 
      string qry3 = "select 'Total' as head_name, sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id, head_name,current_balance from heads where master_id='B' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id) as z"; 
      DataTable dt3 = obj.table(qry3); 
      dataGridView1.Rows.Add();// 
      dataGridView1.Rows[a].Cells[5].Value = dt3.Rows[0]["head_name"];// 
      dataGridView1.Rows[a].Cells[8].Value = Convert.ToDecimal(dt3.Rows[0]["op"]) * -1;// 
      string qry4 = "select 'Closing Stock' as head_name, sum(stock) as op from (select sum(costbase*current_stock) as stock from itemstock ik,items i where i.item_id=ik.item_id union select sum(debit-credit) as stock from view_total_trans where transdate >='" + dateas + "') as x"; 
      DataTable dt4 = obj.table(qry4); 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[a + 1].Cells[0].Value = dt4.Rows[0]["head_name"]; 
      dataGridView1.Rows[a + 1].Cells[3].Value = dt4.Rows[0]["op"]; 
      opstk = Convert.ToDecimal(dataGridView1.Rows[a].Cells[3].Value) + Convert.ToDecimal(dataGridView1.Rows[a + 1].Cells[3].Value); 
      MessageBox.Show("opstk " + opstk); 
      clstk = Convert.ToDecimal(dataGridView1.Rows[a].Cells[8].Value); 
      MessageBox.Show("clstk " + clstk); 
      val = opstk - clstk; 
      //////////////////***********************************************************************************//////////////////////// 
      if (val > 0) 
      { 
       dataGridView1.Rows.Add();// 
       dataGridView1.Rows[a + 2].Cells[5].Value = "Net Loss";// 
       dataGridView1.Rows[a + 2].Cells[8].Value = val;// 
       dataGridView1.Rows.Add();// 
       dataGridView1.Rows[a + 3].Cells[8].Value = clstk + val;// 
       dataGridView1.Rows[a + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);// 
       dataGridView1.Rows.Add(); 
       dataGridView1.Rows[a + 3].Cells[3].Value = opstk; 
       dataGridView1.Rows[a + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      } 
      else 
      { 
       dataGridView1.Rows.Add(); 
       dataGridView1.Rows[a + 2].Cells[0].Value = "Net Profit"; 
       dataGridView1.Rows[a + 2].Cells[3].Value = val * -1; 
       dataGridView1.Rows.Add();// 
       dataGridView1.Rows[a + 3].Cells[8].Value = clstk;// 
       dataGridView1.Rows[a + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
       dataGridView1.Rows.Add(); 
       dataGridView1.Rows[a + 3].Cells[3].Value = opstk + Convert.ToDecimal(dataGridView1.Rows[a + 2].Cells[3].Value); 
       dataGridView1.Rows[a + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 

      } 
     } 

     else 
     { 
      string qry2 = "select 'Total' as head_name,sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id, head_name,current_balance from heads where master_id='A' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id) as z"; 
      DataTable dt2 = obj.table(qry2); 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[b].Cells[0].Value = dt2.Rows[0]["head_name"]; 
      dataGridView1.Rows[b].Cells[3].Value = dt2.Rows[0]["op"]; 
      string qry3 = "select 'Total' as head_name, sum(op) as op from(select x.head_id, head_name,coalesce(op,0) as op from(select head_id, head_name,current_balance from heads where master_id='B' and not is_group order by head_id) as x left join (select head_id, sum(debit_amount-credit_amount) as op from ledger_detail ld, ledger l where ld.ledger_number=l.ledger_number and ledger_date<='" + dateas + "' group by head_id) as y on x.head_id=y.head_id) as z"; 
      DataTable dt3 = obj.table(qry3); 
      dataGridView1.Rows.Add();// 
      dataGridView1.Rows[b].Cells[5].Value = dt3.Rows[0]["head_name"]; 
      dataGridView1.Rows[b].Cells[8].Value = Convert.ToDecimal(dt3.Rows[0]["op"]) * -1;// 
      string qry4 = "select 'Closing Stock' as head_name, sum(stock) as op from (select sum(costbase*current_stock) as stock from itemstock ik,items i where i.item_id=ik.item_id union select sum(debit-credit) as stock from view_total_trans where transdate >='" + dateas + "') as x"; 
      DataTable dt4 = obj.table(qry4); 
      dataGridView1.Rows.Add(); 
      dataGridView1.Rows[b + 1].Cells[0].Value = dt4.Rows[0]["head_name"]; 
      dataGridView1.Rows[b + 1].Cells[3].Value = dt4.Rows[0]["op"]; 
      opstk = Convert.ToDecimal(dataGridView1.Rows[b].Cells[3].Value) + Convert.ToDecimal(dataGridView1.Rows[b + 1].Cells[3].Value); 
      clstk = Convert.ToDecimal(dataGridView1.Rows[b].Cells[8].Value); 
      val = opstk - clstk; 
      //////////////////***********************************************************************************//////////////////////// 
      if (val > 0) 
      { 
       dataGridView1.Rows.Add();// 
       dataGridView1.Rows[b + 2].Cells[5].Value = "Net Loss";// 
       dataGridView1.Rows[b + 2].Cells[8].Value = val;// 
       dataGridView1.Rows.Add();// 
       dataGridView1.Rows[b + 3].Cells[8].Value = clstk + val;// 
       dataGridView1.Rows[b + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold);// 
       dataGridView1.Rows.Add(); 
       dataGridView1.Rows[b + 3].Cells[3].Value = opstk; 
       dataGridView1.Rows[b + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      } 
      else 
      { 
       dataGridView1.Rows.Add(); 
       dataGridView1.Rows[b + 2].Cells[0].Value = "Net Profit"; 
       dataGridView1.Rows[b + 2].Cells[3].Value = val * -1; 
       dataGridView1.Rows.Add();// 
       dataGridView1.Rows[b + 3].Cells[8].Value = clstk;// 
       dataGridView1.Rows[b + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
       dataGridView1.Rows.Add(); 
       dataGridView1.Rows[b + 3].Cells[3].Value = opstk + Convert.ToDecimal(dataGridView1.Rows[a + 2].Cells[3].Value); 
       dataGridView1.Rows[b + 3].DefaultCellStyle.Font = new Font("Arial", 9, FontStyle.Bold); 
      } 
     } 

     for (int i = 0; i < dataGridView1.Rows.Count; i++) 
     { 
      if (dataGridView1.Rows[i].Cells[0].Value == null && dataGridView1.Rows[i].Cells[2].Value == null && dataGridView1.Rows[i].Cells[3].Value == null) 
      { 
       dataGridView1.Rows.RemoveAt(i); 
       i--; 
      } 
     } 
    } 

私は必要な列を手動で追加します。

関連する問題