Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
GeneralRe: Interop Pin
Dave Kreskowiak31-May-04 1:15
mveDave Kreskowiak31-May-04 1:15 
GeneralThe Error Pin
satanic_cult31-May-04 7:34
satanic_cult31-May-04 7:34 
GeneralRe: The Error Pin
Dave Kreskowiak31-May-04 7:44
mveDave Kreskowiak31-May-04 7:44 
GeneralRe: The Error Pin
satanic_cult31-May-04 12:15
satanic_cult31-May-04 12:15 
GeneralRe: The Error Pin
Dave Kreskowiak1-Jun-04 0:27
mveDave Kreskowiak1-Jun-04 0:27 
GeneralRe: The Error Pin
satanic_cult1-Jun-04 9:43
satanic_cult1-Jun-04 9:43 
GeneralRe: The Error Pin
Dave Kreskowiak1-Jun-04 15:36
mveDave Kreskowiak1-Jun-04 15:36 
GeneralRe: The Error Pin
satanic_cult1-Jun-04 22:01
satanic_cult1-Jun-04 22:01 
this is my database handling code..and my databaser is in access...so please lemme know where i have to make the required changes with OleDB...sorry for the trouble i am causing you..


using System;
using System.Data;
using System.Collections;
using System.Windows.Forms;

namespace WindowsApplication9
{
///
/// Summary description for DatabaseController.
///

public class DatabaseController
{
private ADODataSetCommand AdoCmd = new ADODataSetCommand("SELECT * FROM Activities", "Provider=Microsoft.JET.OLEDB.4.0;data source= calendar.mdb" );
private ADODataSetCommand AdoCmdAll = new ADODataSetCommand("SELECT * FROM Activities", "Provider=Microsoft.JET.OLEDB.4.0;data source=calendar.mdb" );
public ArrayList AlarmList = new ArrayList();

public DatabaseController()
{
//
// TODO: Add Constructor Logic here
//
}

private void FillArrayWithPopulatedRows(DataTable aTable, RowData[] rowArray)
{
try
{
int nRow = 0;
foreach( DataRow dtRow in aTable.Rows)
{
int nCount = CalcRow(dtRow);
rowArray[nCount].m_nTime = dtRow["Time"].ToString().ToInt32();
rowArray[nCount].m_nCount = nRow;
rowArray[nCount].m_nKey = dtRow["ID"].ToString().ToInt32();
rowArray[nCount].m_bAM = dtRow["IsAM"].ToString().ToBoolean();
rowArray[nCount].m_bAlarm = dtRow["IsAlarm"].ToString().ToBoolean();
nRow++;
}
}
catch(Exception exx)
{
System.Console.WriteLine(exx.Message.ToString());
}
}

public bool IsRowAM(int nRow)
{
if (nRow > 2)
{
return false;
}

return true;

}

public int Time2Integer(string strTime)
{
string strResult = strTime;
int index = strResult.IndexOf(":");
int nResult = strResult.Substring(0, index).ToInt32();
return nResult;
}

private DataRow FindRow(DataTable dTable, int nKey)
{
foreach (DataRow dtRow in dTable.Rows)
{
if (dtRow["ID"].ToString().ToInt32() == nKey)
{
return dtRow;
}
}

return null;
}

public void WriteOutActivities(System.DateTime TheDate, ListView listView1, ArrayList MarkedRows)
{
try
{
string strDate = TheDate.ToShortDateString();

if (MarkedRows.Count == 0)
{
return; // nothing to write, precondition
}

AdoCmd.SelectCommand.CommandText = "SELECT * FROM Activities WHERE Date = #" + strDate + "#";
// AdoCmd.UpdateCommand.CommandText = "UPDATE Activities SET Activity = ?, [Date] = ?, ID = ?, IsAM = ?, [Time] = ? WHERE (ID = ?)";
AdoCmd.TableMappings.All = new System.Data.Internal.DataTableMapping[1] {new System.Data.Internal.DataTableMapping ("Table", "Activities", new System.Data.Internal.DataColumnMapping[5] {new System.Data.Internal.DataColumnMapping ("Activity", "Activity"), new System.Data.Internal.DataColumnMapping ("Date", "Date"), new System.Data.Internal.DataColumnMapping ("ID", "ID"), new System.Data.Internal.DataColumnMapping ("IsAM", "IsAM"), new System.Data.Internal.DataColumnMapping ("Time", "Time")})};
DataSet dtSet = new DataSet();
DataSet dtSetAll = new DataSet();
// for (int i = 0; i < AdoCmd.TableMappings.Count; i++)
int i = 0;
AdoCmd.FillDataSet(dtSet, "Activities");

AdoCmdAll.SelectCommand.CommandText = "SELECT * FROM Activities ORDER BY ID";
AdoCmdAll.FillDataSet(dtSetAll, "Activities");

DataTable dTable = dtSet.Tables[i];
RowData[] rowArray = new RowData[15]
{
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
new RowData(),
};

rowArray.Initialize(); // doesn't seem to do anything
FillArrayWithPopulatedRows(dTable, rowArray);
for (i = 0; i < MarkedRows.Count; i++)
{
int index = (int)MarkedRows[i];
// if (rowArray[i].m_nCount > -1)
// {
// DataRow dtRow = dTable.Rows.Find(rowArray[i].m_nKey);
// do the hard way, doesn't seem to think the primary key exists
// DataRow dtRow = FindRow(dTable, rowArray[i].m_nKey);
// if (dtRow != null)
{
// dtRow["ID"] = rowArray[i].m_nKey;
// dtRow["Date"] = strDate;
// dtRow["Time"] = Time2Integer(listView1.ListItems[i].Text);
// }
// }
// else
// {
string strActivity = listView1.ListItems[index].SubItems[0].Trim();
if ( (strActivity.Length > 0) || (rowArray[index].m_nCount > -1))
{
if (strActivity.Length == 0) // delete it if its there
{
if (rowArray[index].m_nCount > -1)
{
dTable.Rows[rowArray[index].m_nCount].Delete();
}
}
else
{
if (rowArray[index].m_nCount > -1) // existing row
{
// only update if the activity text has changed
string testString = dTable.Rows[rowArray[index].m_nCount]["Activity"].ToString();
bool bAlarm = dTable.Rows[rowArray[index].m_nCount]["IsAlarm"].ToString().ToBoolean();
if ( (testString != listView1.ListItems[index].SubItems[0]) || (bAlarm != (listView1.ListItems[index].ImageIndex == 1)))
{
dTable.Rows[rowArray[index].m_nCount].Delete();
dTable.Rows.AddUpdate(new object[]
{
rowArray[index].m_nKey,
strDate,
Time2Integer(listView1.ListItems[index].Text),
IsRowAM(index),
listView1.ListItems[index].SubItems[0],
(listView1.ListItems[index].ImageIndex == 1)
});
}
}
else
{
int nMax = 0;
DataTable dTableAll = dtSetAll.Tables[0];
if (dTableAll.Rows.Count > 0)
{
nMax = dTableAll.Rows[dTableAll.Rows.Count - 1]["ID"].ToString().ToInt32() + 1;
}
if (nMax < 0)
{
nMax = 0;
}
dTableAll.Rows.AddUpdate(new object[]
{
nMax,
strDate,
Time2Integer(listView1.ListItems[index].Text),
IsRowAM(index),
listView1.ListItems[index].SubItems[0],
(listView1.ListItems[index].ImageIndex == 1)
});
}
}

}
// new row
}
}

AdoCmd.Update(dtSet, "Activities");
AdoCmd.Update(dtSetAll, "Activities");
// dTable.AcceptChanges();
}
catch(Exception exx)
{
System.Console.WriteLine(exx.Message.ToString());
}
}


public void ReadInActivities(System.DateTime TheDate, ListView listView1)
{
try
{
string strDate = TheDate.ToShortDateString();

AdoCmd.SelectCommand.CommandText = "SELECT * FROM Activities WHERE Date = #" + strDate + "#";

DataSet dtSet = new DataSet();
// for (int i = 0; i < AdoCmd.TableMappings.Count; i++)
int i = 0;
AdoCmd.FillDataSet(dtSet, "Activities");
DataTable dTable = dtSet.Tables[i];
int nCount = 0;
foreach( DataRow dtRow in dTable.Rows)
{
// if (dtRow["Date"].ToString().ToDateTime() == TheDate) // until we find out what's wrong with the where clause, we need to do it the hard way
// {
nCount = CalcRow(dtRow);
listView1.ListItems[nCount].SetSubItem(0 , dtRow["Activity"].ToString());
if (dtRow["IsAlarm"].ToString().ToBoolean() == true)
{
listView1.ListItems[nCount].ImageIndex = 1;
}
else
{
listView1.ListItems[nCount].ImageIndex = 0;
}


// }

}

}
catch(Exception exx)
{
System.Console.WriteLine(exx.Message.ToString());
}
}

public void RemoveAlarmFromList(int nAlarmKey)
{
for (int i = 0; i < AlarmList.Count; i++)
{
if (((RowData)AlarmList[i]).m_nKey == nAlarmKey)
{
AlarmList.RemoveAt(i);
}
}
}


public void ReadInAlarms()
{
try
{

AdoCmd.SelectCommand.CommandText = "SELECT * FROM Activities WHERE IsAlarm = TRUE";

DataSet dtSet = new DataSet();
AdoCmd.FillDataSet(dtSet, "Activities");
DataTable dTable = dtSet.Tables[0];
foreach( DataRow dtRow in dTable.Rows)
{
RowData theData = new RowData();
theData.m_bAlarm = dtRow["IsAlarm"].ToString().ToBoolean();
theData.m_bAM = dtRow["IsAM"].ToString().ToBoolean();
theData.m_nTime = dtRow["Time"].ToString().ToInt32();
theData.m_Date = dtRow["Date"].ToString().ToDateTime();
theData.m_strActivity = dtRow["Activity"].ToString();
theData.m_nKey = dtRow["ID"].ToString().ToInt32();
theData.m_nCount = this.CalcRow(dtRow);
AlarmList.Add(theData);
}

}
catch(Exception exx)
{
System.Console.WriteLine(exx.Message.ToString());
}
}

public int LookupAlarmKey(RowData theData)
{
try
{

AdoCmd.SelectCommand.CommandText = "SELECT * FROM Activities WHERE IsAlarm = TRUE AND Date = #" + theData.m_Date.ToShortDateString() + "# AND Time = " + theData.m_nTime.ToString() + " AND IsAM = " + theData.m_bAM.ToString();

DataSet dtSet = new DataSet();
AdoCmd.FillDataSet(dtSet, "Activities");
DataTable dTable = dtSet.Tables[0];
foreach( DataRow dtRow in dTable.Rows)
{
return dtRow["ID"].ToString().ToInt32();
}


}
catch(Exception exx)
{
System.Console.WriteLine(exx.Message.ToString());
}

return -1;

}

public void DeleteAlarm(int nKey)
{
try
{

AdoCmd.SelectCommand.CommandText = "SELECT * FROM Activities WHERE ID = " + nKey.ToString();

DataSet dtSet = new DataSet();
AdoCmd.FillDataSet(dtSet, "Activities");
DataTable dTable = dtSet.Tables[0];
foreach( DataRow dtRow in dTable.Rows)
{
dtRow.BeginEdit();
dtRow["IsAlarm"] = false;
dtRow.EndEdit();
// dtRow.Delete();
}

AdoCmd.Update(dtSet, "Activities");
}
catch(Exception exx)
{
System.Console.WriteLine(exx.Message.ToString());
}
}



private int CalcRow(DataRow dtRow)
{
int nTime = dtRow["Time"].ToString().ToInt32();
bool bAM = dtRow["IsAM"].ToString().ToBoolean();
if (!bAM)
{
if (nTime != 12)
{
nTime = nTime + 12;
}
}

// offset by starting time, which is 9
nTime -= 9;
return nTime;

}

}
}
GeneralRe: The Error Pin
Dave Kreskowiak2-Jun-04 0:25
mveDave Kreskowiak2-Jun-04 0:25 
Questionwhat happen ? Pin
sreejith ss nair30-May-04 20:57
sreejith ss nair30-May-04 20:57 
QuestionHow can get IP Address from local machine? Pin
quocbao30-May-04 17:55
quocbao30-May-04 17:55 
AnswerRe: How can get IP Address from local machine? Pin
Aryadip30-May-04 18:10
Aryadip30-May-04 18:10 
GeneralRe: How can get IP Address from local machine? Pin
Uwe Keim30-May-04 22:28
sitebuilderUwe Keim30-May-04 22:28 
QuestionWrap Datagrid Column in WinApp Project? Pin
Tuwing.Sabado30-May-04 17:10
Tuwing.Sabado30-May-04 17:10 
AnswerRe: Wrap Datagrid Column in WinApp Project? Pin
Mazdak30-May-04 20:17
Mazdak30-May-04 20:17 
GeneralRe: Wrap Datagrid Column in WinApp Project? Pin
Tuwing.Sabado30-May-04 20:20
Tuwing.Sabado30-May-04 20:20 
QuestionHow can I effectively access the object collection of form1 to another form in WinApp Project? Pin
Tuwing.Sabado30-May-04 17:02
Tuwing.Sabado30-May-04 17:02 
AnswerRe: How can I effectively access the object collection of form1 to another form in WinApp Project? Pin
Aryadip30-May-04 18:21
Aryadip30-May-04 18:21 
GeneralRe: How can I effectively access the object collection of form1 to another form in WinApp Project? Pin
Tuwing.Sabado30-May-04 20:45
Tuwing.Sabado30-May-04 20:45 
GeneralRe: How can I effectively access the object collection of form1 to another form in WinApp Project? Pin
Aryadip30-May-04 21:48
Aryadip30-May-04 21:48 
GeneralRe: How can I effectively access the object collection of form1 to another form in WinApp Project? Pin
Tuwing.Sabado30-May-04 22:50
Tuwing.Sabado30-May-04 22:50 
GeneralRe: How can I effectively access the object collection of form1 to another form in WinApp Project? Pin
Aryadip31-May-04 2:44
Aryadip31-May-04 2:44 
AnswerRe: How can I effectively access the object collection of form1 to another form in WinApp Project? Pin
partyganger31-May-04 5:26
partyganger31-May-04 5:26 
Generalweb chat! Pin
Silly Boy30-May-04 16:48
Silly Boy30-May-04 16:48 
GeneralRe: web chat! Pin
Wackatronic1-Jun-04 10:05
Wackatronic1-Jun-04 10:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.