private void fillGrid()
{
System.Data.SqlClient.SqlConnection conn=new System.Data.SqlClient.SqlConnection(NN.Tool.Data.Common.ConnectionString);
conn.Open();
string sql = "select Customers.CustomerId,Customers.Description as Customer,EFT.Amount as EFT,sum(Checks.Amount) as DirectDeposit,'Note' as Note,EFT.EFTId,ACHBATCHS.ACHBatchId as ACHId from ToolCheckBatches inner join AchBatchs on AchBatchs.ToolCheckBatchId = ToolCheckBatches.ToolCheckBatchId inner join AchBatchItems on AchBatchItems.AchBatchId = AchBatchs.AchBatchId inner join Invoices on Invoices.InvoiceId = ToolCheckBatches.InvoiceId full outer join EFT on EFT.InvoiceId = Invoices.InvoiceId inner join Customers on Customers.CustomerId = ToolCheckBatches.CustomerId inner join ToolChecks on ToolChecks.ToolCheckId=AchBatchItems.ToolCheckId inner join Checks on Checks.CheckId=ToolChecks.CheckId group by Customers.CustomerId,Customers.Description,EFT.Amount,EFT.EFTId,AchBatchs.AchBatchId";
System.Data.SqlClient.SqlDataAdapter Adp=new System.Data.SqlClient.SqlDataAdapter(sql,conn);
Adp.Fill(this.eftAndACH1.Tables[0]);
conn.Close();
Adp.Dispose();
}
private void c1TrueDBGrid1_RowColChange(object sender, C1.Win.C1TrueDBGrid.RowColChangeEventArgs e)
{
C1.Win.C1TrueDBGrid.Style rStyle = new C1.Win.C1TrueDBGrid.Style();
C1.Win.C1TrueDBGrid.Style gStyle = new C1.Win.C1TrueDBGrid.Style();
rStyle.BackColor=System.Drawing.Color.Red;
gStyle.BackColor=System.Drawing.Color.Green;
if (c1TrueDBGrid1.Col==2)
{
//EFT
if (eftItems.AddOrRemove(Convert.ToInt32(this.eftAndACH1.Tables[0].Rows[this.c1TrueDBGrid1.Row][5]),Convert.ToDecimal(this.eftAndACH1.Tables[0].Rows[this.c1TrueDBGrid1.Row][2])))
{
c1TrueDBGrid1.Splits[0].DisplayColumns[c1TrueDBGrid1.Col].AddCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.CurrentCell,gStyle);
}
else
{
c1TrueDBGrid1.Splits[0].DisplayColumns[c1TrueDBGrid1.Col].AddCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.CurrentCell,rStyle);
}
}
if (c1TrueDBGrid1.Col==3)
{
//ACH
if (achItems.AddOrRemove(Convert.ToInt32(this.eftAndACH1.Tables[0].Rows[this.c1TrueDBGrid1.Row][6]),Convert.ToDecimal(this.eftAndACH1.Tables[0].Rows[this.c1TrueDBGrid1.Row][3])))
{
c1TrueDBGrid1.Splits[0].DisplayColumns[c1TrueDBGrid1.Col].AddCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.CurrentCell,gStyle);
}
else
{
c1TrueDBGrid1.Splits[0].DisplayColumns[c1TrueDBGrid1.Col].AddCellStyle(C1.Win.C1TrueDBGrid.CellStyleFlag.CurrentCell,rStyle);
}
}
this.c1TrueDBGrid1.Col=1;
this.UpdateAmounts();
}
private ACHItems achItems = new ACHItems();
private EFTItems eftItems = new EFTItems();
private void UpdateAmounts()
{
this.textBox1.Text=eftItems.TotalAmount.ToString("c");
this.textBox2.Text=achItems.TotalAmount.ToString("c");
}
private void c1TrueDBGrid1_FetchCellStyle(object sender, C1.Win.C1TrueDBGrid.FetchCellStyleEventArgs e)
{
C1.Win.C1TrueDBGrid.Style rStyle = new C1.Win.C1TrueDBGrid.Style();
C1.Win.C1TrueDBGrid.Style gStyle = new C1.Win.C1TrueDBGrid.Style();
rStyle.BackColor=System.Drawing.Color.Red;
gStyle.BackColor=System.Drawing.Color.Green;
if (e.Col==2)
{
//EFT
if (eftItems.Exists(Convert.ToInt32(this.eftAndACH1.Tables[0].Rows[e.Row][5])))
{
e.CellStyle.BackColor=System.Drawing.Color.Green;
}
else
{
e.CellStyle.BackColor=System.Drawing.Color.Red;
}
}
if (e.Col==3)
{
//ACH
if (achItems.Exists(Convert.ToInt32(this.eftAndACH1.Tables[0].Rows[e.Row][6])))
{
e.CellStyle.BackColor=System.Drawing.Color.Green;
}
else
{
e.CellStyle.BackColor=System.Drawing.Color.Red;
}
}
}
private void c1TrueDBGrid1_Click_1(object sender, System.EventArgs e)
{
//if(c1TrueDBGrid1.Col==2 || c1TrueDBGrid1.Col==3)
//MessageBox.Show("Hi");
}
private void c1TrueDBGrid1_ColEdit(object sender, C1.Win.C1TrueDBGrid.ColEventArgs e)
{
}
private void c1TrueDBGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
//this.c1TrueDBGrid1.invo
}
}
public class ACHItem
{
public int ACHId;
public decimal Amount;
public ACHItem(int myACHId,decimal myAmount)
{
ACHId=myACHId;
Amount=myAmount;
}
}
public class EFTItem
{
public int EFTId;
public decimal Amount;
public EFTItem(int myEFTId,decimal myAmount)
{
EFTId=myEFTId;
Amount=myAmount;
}
}
public class ACHItems
{
public decimal TotalAmount=0;
public System.Collections.ArrayList ACHS=new ArrayList();
public ACHItems()
{
}
private void Add(ACHItem item)
{
this.TotalAmount=TotalAmount+item.Amount;
ACHS.Add(item);
}
private void Remove(int index)
{
this.TotalAmount=TotalAmount-((ACHItem)ACHS[index]).Amount;
ACHS.RemoveAt(index);
}
public bool AddOrRemove(int myACHId,decimal Amount)
{
bool myFound=false;
for (int i=0;i==ACHS.Count-1;i++)
{
ACHItem item=(ACHItem)ACHS[i];
if (item.ACHId==myACHId)
{
Remove(i);
myFound=true;
}
}
if(myFound)
return false;
else
{
Add(new ACHItem(myACHId,Amount));
return true;
}
}
public bool Exists(int myACHId)
{
bool myFound=false;
for (int i=0;i==ACHS.Count-1;i++)
{
ACHItem item=(ACHItem)ACHS[i];
if (item.ACHId==myACHId)
{
//Remove(i);
myFound=true;
}
}
if(myFound)
return true;
else
{
//Add(new ACHItem(myACHId,Amount));
return false;
}
}
}
public class EFTItems
{
public decimal TotalAmount=0;
public System.Collections.ArrayList EFTS=new ArrayList();
public EFTItems()
{
}
private void Add(EFTItem item)
{
this.TotalAmount=TotalAmount+item.Amount;
EFTS.Add(item);
}
private void Remove(int index)
{
this.TotalAmount=TotalAmount-((EFTItem)EFTS[index]).Amount;
EFTS.RemoveAt(index);
}
public bool AddOrRemove(int myeftId,decimal Amount)
{
bool myFound=false;
for (int i=0;i==EFTS.Count-1;i++)
{
EFTItem item=(EFTItem)EFTS[i];
if (item.EFTId==myeftId)
{
Remove(i);
myFound=true;
}
}
if(myFound)
return false;
else
{
Add(new EFTItem(myeftId,Amount));
return true;
}
}
public bool Exists(int myeftId)
{
bool myFound=false;
for (int i=0;i==EFTS.Count-1;i++)
{
EFTItem item=(EFTItem)EFTS[i];
if (item.EFTId==myeftId)
{
//Remove(i);
myFound=true;
}
}
if(myFound)
return true;
else
{
// Add(new EFTItem(myeftId,Amount));
return false;
}
}
}