|
OK. Did you reference any ActiveX components? What references have you made?
Plus, post the top of your code also, through the Windows Form Designer section.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
the top od my code looks like this..
using System;
using System.Drawing;
using Microsoft.Win32.Interop;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication9
{......
|
|
|
|
|
There's your problem... Get rid of the line using Microsoft.Win32.Interop . There is no namespace by that name so it's not going to work. Where did that come from? No application I've seen needs that line, which won't work anyway...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i am posting the entire program i am tryin to run...i deleted the interop part from namespace but now i am getting the following errors...
"The type or namespace name 'ADO' does not exist in the class or namespace 'System.Data' (are you missing an assembly reference?)"
"The type or namespace name 'ADODataSetCommand' could not be found (are you missing a using directive or an assembly reference?)"
" The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)"
namespace WindowsApplication9
{
using System;
using System.Drawing;
using Microsoft.Win32;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
///
/// Required designer variable.
///
private System.ComponentModel.Container components;
private System.Windows.Forms.MenuItem Exit;
private System.Windows.Forms.MenuItem SetAlarm;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ImageList imageList1;
private System.Data.ADO.ADOConnection adoConnection1;
private System.Data.ADO.ADODataSetCommand adoDataSetCommand1;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private DatabaseController DBController = new DatabaseController();
private int OldSelection = 0;
private DateTime OldDate = new DateTime(DateTime.Today.Ticks);
private ArrayList MyMarkedDates = new ArrayList();
public int CurrentRow = 0;
private const int kArrowDownKey = 40;
private const int kArrowUpKey = 38;
private const int kEnterKey = 13;
const long TicksInAnHour = 36000000000;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
timer1.Enabled = true;
textBox1.Focus();
this.TabStop = false;
DBController.ReadInActivities(DateTime.Today, listView1);
DBController.ReadInAlarms();
SetupTextBox(0);
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private int NextSelection()
{
OldSelection = CurrentRow;
CurrentRow++;
if (CurrentRow > 14)
{
CurrentRow = 0;
}
return CurrentRow;
}
private int PreviousSelection()
{
OldSelection = CurrentRow;
CurrentRow--;
if (CurrentRow < 0)
{
CurrentRow = 14;
}
return CurrentRow;
}
public void SetupTextBox(int nItem)
{
Rectangle r1 = listView1.ListItems[nItem].GetBounds(ItemBoundsPortion.Entire.ToInt32());
int columnStart = listView1.Columns[0].Width;
int columnWidth = listView1.Columns[1].Width;
Rectangle rtPortion = new Rectangle(r1.Left + columnStart, r1.Top, columnWidth, r1.Height);
Point aPoint = new Point(listView1.Left, listView1.Top);
rtPortion.Offset(aPoint);
// rtPortion.Inflate(-3, -7); // kludge since the get bounds doesn't seem to work exactly right
// rtPortion.Offset(0, -6);
// aPoint = this.PointToClient(aPoint);
textBox1.SetBounds(rtPortion.X, rtPortion.Y, rtPortion.Width, rtPortion.Height);
textBox1.Text = listView1.ListItems[nItem].SubItems[0];
// this.AutoScrollPosition.Y = rtPortion.Y;
}
///
/// Clean up any resources being used.
///
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(Form1));
this.components = new System.ComponentModel.Container ();
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar ();
this.imageList1 = new System.Windows.Forms.ImageList ();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader ();
this.SetAlarm = new System.Windows.Forms.MenuItem ();
this.mainMenu1 = new System.Windows.Forms.MainMenu ();
this.listView1 = new System.Windows.Forms.ListView ();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader ();
this.Exit = new System.Windows.Forms.MenuItem ();
this.menuItem1 = new System.Windows.Forms.MenuItem ();
this.statusBar1 = new System.Windows.Forms.StatusBar ();
this.adoDataSetCommand1 = new System.Data.ADO.ADODataSetCommand ();
this.adoConnection1 = new System.Data.ADO.ADOConnection ();
this.textBox1 = new System.Windows.Forms.TextBox ();
this.timer1 = new System.Windows.Forms.Timer (this.components);
//@this.TrayHeight = 90;
//@this.TrayLargeIcon = false;
//@this.TrayAutoArrange = true;
monthCalendar1.Location = new System.Drawing.Point (304, 8);
monthCalendar1.TabIndex = 0;
monthCalendar1.TabStop = true;
monthCalendar1.DateChanged += new System.Windows.Formss.DateRangeEventHandler (this.monthCalendar1_DateChanged);
//@imageList1.SetLocation (new System.Drawing.Point (282, 7));
imageList1.ImageSize = new System.Drawing.Size (16, 16);
imageList1.ImageStream = (System.WinForms.ImageListStreamer) resources.GetObject ("imageList1.ImageStream");
imageList1.ColorDepth = System.WinForms.ColorDepth.Depth8Bit;
imageList1.TransparentColor = System.Drawing.Color.Transparent;
columnHeader1.Text = "Time";
columnHeader1.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
SetAlarm.Text = "Toggle Alarm...";
SetAlarm.Index = 0;
SetAlarm.Click += new System.EventHandler (this.SetAlarm_Click);
//@mainMenu1.SetLocation (new System.Drawing.Point (446, 7));
mainMenu1.MenuItems.All = new System.Windows.Forms.MenuItem[1] {this.menuItem1};
listView1.Location = new System.Drawing.Point (8, 8);
listView1.Size = new System.Drawing.Size (280, 288);
listView1.FullRowSelect = true;
listView1.View = System.Windows.Forms.View.Report;
listView1.ForeColor = System.Drawing.SystemColors.WindowText;
listView1.Font = new System.Drawing.Font ("Microsoft Sans Serif", 10);
listView1.GridLines = true;
listView1.TabIndex = 1;
listView1.SmallImageList = this.imageList1;
listView1.DoubleClick += new System.EventHandler (this.listView1_DoubleClick);
listView1.MouseUp += new System.Windows.Forms.MouseEventHandler (this.listView1_MouseUp);
listView1.SelectedIndexChanged += new System.EventHandler (this.listView1_SelectedIndexChanged);
listView1.Columns.All = new System.Windows.Forms.ColumnHeader[2] {this.columnHeader1, this.columnHeader2};
listView1.ListItems.All = new System.Windows.Forms.ListItem[15] {new System.Windows.Forms.ListItem ("9:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("10:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("11:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("12:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("1:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("2:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("3:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("4:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("5:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("6:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("7:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("8:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("9:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("10:00", 0, new string[1] {null}), new System.Windows.Forms.ListItem ("11:00", 0, new string[1] {null})};
columnHeader2.Text = "Activity";
columnHeader2.Width = 215;
columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
Exit.Text = "Exit";
Exit.Index = 1;
Exit.Click += new System.EventHandler (this.Exit_Click);
menuItem1.Text = "File";
menuItem1.Index = 0;
menuItem1.MenuItems.All = new System.Windows.Forms.MenuItem[2] {this.SetAlarm, this.Exit};
statusBar1.BackColor = System.Drawing.SystemColors.Control;
statusBar1.Location = new System.Drawing.Point (0, 312);
statusBar1.Size = new System.Drawing.Size (504, 21);
statusBar1.TabIndex = 4;
statusBar1.Text = "Ready...";
//@adoDataSetCommand1.SetLocation (new System.Drawing.Point (7, 7));
adoDataSetCommand1.UpdateCommand = new System.Data.ADO.ADOCommand (this.adoConnection1, "UPDATE Activities SET Activity = ?, [Date] = ?, ID = ?, IsAM = ?, [Time] = ? WHERE (ID = ?)", System.Data.CommandType.Text, false, new System.Data.ADO.ADOParameter[6] {new System.Data.ADO.ADOParameter ("Activity", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "Activity", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("Date", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "Date", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("IsAM", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "IsAM", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("Time", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "Time", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("Original_ID", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "ID", System.Data.DataRowVersion.Original, null), new System.Data.ADO.ADOParameter ("New_ID", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "ID", System.Data.DataRowVersion.Current, null)}, System.Data.UpdateRowSource.Both);
adoDataSetCommand1.DeleteCommand = new System.Data.ADO.ADOCommand (this.adoConnection1, "DELETE FROM Activities WHERE (ID = ?)", System.Data.CommandType.Text, false, new System.Data.ADO.ADOParameter[1] {new System.Data.ADO.ADOParameter ("ID", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "ID", System.Data.DataRowVersion.Current, null)}, System.Data.UpdateRowSource.Both);
adoDataSetCommand1.InsertCommand = new System.Data.ADO.ADOCommand (this.adoConnection1, "INSERT INTO Activities( Activity, [Date], ID, IsAM, [Time] ) VALUES( ?, ?, ?, ?, ? )", System.Data.CommandType.Text, false, new System.Data.ADO.ADOParameter[5] {new System.Data.ADO.ADOParameter ("Activity", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "Activity", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("Date", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "Date", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("IsAM", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "IsAM", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("Time", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "Time", System.Data.DataRowVersion.Current, null), new System.Data.ADO.ADOParameter ("Key_ID", System.Data.ADO.ADODBType.VarWChar, 510, System.Data.ParameterDirection.Input, false, 255, 255, "ID", System.Data.DataRowVersion.Current, null)}, System.Data.UpdateRowSource.Both);
adoDataSetCommand1.SelectCommand = new System.Data.ADO.ADOCommand (this.adoConnection1, "SELECT Activity, [Date], ID, IsAM, [Time] FROM Activities", System.Data.CommandType.Text, false, new System.Data.ADO.ADOParameter[] {}, System.Data.UpdateRowSource.Both);
adoDataSetCommand1.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")})};
//@adoConnection1.SetLocation (new System.Drawing.Point (162, 7));
adoConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Mike\\My Documents\\Visual Studio Projects\\WindowsApplication9\\bin\\Debug\\calendar.mdb;Persist Security Info=False";
textBox1.Location = new System.Drawing.Point (72, 56);
textBox1.Text = "textBox1";
textBox1.TabIndex = 2;
textBox1.Size = new System.Drawing.Size (216, 20);
//@timer1.SetLocation (new System.Drawing.Point (375, 7));
timer1.Interval = 900000;
timer1.Tick += new System.EventHandler (this.timer1_Tick);
this.Text = "Scheduling Book";
this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
this.KeyPreview = true;
this.Menu = this.mainMenu1;
this.ClientSize = new System.Drawing.Size (504, 333);
this.KeyDown += new System.Windows.Forms.KeyEventHandler (this.Form1_KeyDown);
this.Click += new System.EventHandler (this.Form1_Click);
this.Closing += new System.ComponentModel.CancelEventHandler (this.Form1_Closing);
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler (this.Form1_KeyPress);
this.Controls.Add (this.statusBar1);
this.Controls.Add (this.textBox1);
this.Controls.Add (this.listView1);
this.Controls.Add (this.monthCalendar1);
}
protected void Exit_Click (object sender, System.EventArgs e)
{
SaveTheData(monthCalendar1.SelectionStart); // save data before exiting
Application.Exit();
}
protected void SetAlarm_Click (object sender, System.EventArgs e)
{
ListItem anItem = listView1.ListItems[CurrentRow];
ToggleAlarm(anItem);
}
protected void Form1_Click (object sender, System.EventArgs e)
{
}
protected long GetAlarmInTicks(RowData theData)
{
long lResult = 0;
lResult = theData.m_Date.Ticks + (theData.m_nTime * TicksInAnHour);
if ((theData.m_bAM == false) && (theData.m_nTime != 12))
{
lResult += (12 * TicksInAnHour);
}
return lResult;
}
protected void timer1_Tick (object sender, System.EventArgs e)
{
for (int i = 0; i < DBController.AlarmList.Count; i++)
{
RowData theData = (RowData)DBController.AlarmList[i];
long nTicks = GetAlarmInTicks(theData);
long diffTicks = DateTime.Now.Ticks - nTicks;
double fDiffHours = diffTicks.ToDouble()/TicksInAnHour;
if (diffTicks > 0)
{
System.Windows.Forms.MessageBox.Show(theData.m_strActivity);
DBController.DeleteAlarm(theData.m_nKey);
DBController.RemoveAlarmFromList(theData.m_nKey);
listView1.ListItems[theData.m_nCount].ImageIndex = 0;
}
}
}
protected int TimeString2Int(string strTime)
{
int index = strTime.IndexOf(':');
string strNum = strTime.Substring(0, index);
return strNum.ToInt32();
}
protected bool IsAM(int itemIndex)
{
bool bAM = false;
if (itemIndex > 2)
{
bAM = false;
}
else
{
bAM = true;
}
return bAM;
}
protected RowData Item2Data(ListItem anItem)
{
RowData theData = new RowData();
theData.m_Date = monthCalendar1.SelectionStart;
theData.m_bAlarm = true;
theData.m_bAM = IsAM(anItem.Index);
theData.m_nTime = TimeString2Int(anItem.Text);
theData.m_nCount = anItem.Index;
if (anItem.SubItems.Length > 0)
{
theData.m_strActivity = anItem.SubItems[0];
}
return theData;
}
protected void ToggleAlarm(ListItem anItem)
{
if (anItem.ImageIndex == 0)
{
anItem.ImageIndex = 1;
DBController.AlarmList.Add(Item2Data(anItem));
}
else
{
anItem.ImageIndex = 0;
int nKey = DBController.LookupAlarmKey(Item2Data(anItem));
DBController.DeleteAlarm(nKey);
DBController.RemoveAlarmFromList(nKey);
}
}
protected void listView1_DoubleClick (object sender, System.EventArgs e)
{
ListItem anItem = listView1.SelectedItems[0];
ToggleAlarm(anItem);
}
protected void Form1_Closing (object sender, System.ComponentModel.CancelEventArgs e)
{
SaveTheData(monthCalendar1.SelectionStart); // save data before exiting
}
protected void Form1_KeyDown (object sender, System.Windows.Forms.KeyEventArgs e)
{
int l = (int)e.KeyData;
switch(l)
{
case kArrowDownKey:
NextSelection();
HandleTextBoxData();
break;
case kArrowUpKey:
PreviousSelection();
HandleTextBoxData();
break;
case kEnterKey:
NextSelection();
HandleTextBoxData();
break;
default:
break;
}
}
protected override bool ProcessTabKey(bool Forward)
{
NextSelection();
HandleTextBoxData();
return false;
// return base.ProcessCmdKey(msg, keyData);
}
protected void Form1_KeyPress (object sender, System.Windows.Forms.KeyPressEventArgs e)
{
char c = e.KeyChar.ToChar();
}
protected void SaveTheData(DateTime theDate)
{
GetDataFromTextBox(); // force data into listview
MarkOldSelection();
DBController.WriteOutActivities(theDate, listView1, MyMarkedDates);
MyMarkedDates.Clear();
statusBar1.Text = "Saved Data...";
}
protected void SaveButton_Click (object sender, System.EventArgs e)
{
SaveTheData(monthCalendar1.SelectionStart); // save the data
}
protected void listView1_MouseUp (object sender, System.Windows.Forms.MouseEventArgs e)
{
textBox1.Focus();
}
protected void GetDataFromTextBox()
{
listView1.ListItems[OldSelection].SetSubItem(0, textBox1.Text);
}
protected void MarkOldSelection()
{
MyMarkedDates.Add(OldSelection); // only add items that have changed
}
protected void HandleTextBoxData()
{
GetDataFromTextBox();
MarkOldSelection();
SetupTextBox(CurrentRow);
OldSelection = CurrentRow;
}
protected void listView1_SelectedIndexChanged (object sender, System.EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
CurrentRow = listView1.SelectedItems[0].Index;
HandleTextBoxData();
statusBar1.Text = "Ready...";
}
}
protected void monthCalendar1_DateChanged (object sender, System.Windows.Forms.DateRangeEventArgs e)
{
SaveTheData(OldDate); // save the previous screen
ClearSubItems();
textBox1.Text = "";
DBController.ReadInActivities(monthCalendar1.SelectionStart, listView1);
OldSelection = CurrentRow;
SetupTextBox(CurrentRow);
OldDate = monthCalendar1.SelectionStart;
textBox1.Focus();
}
protected void ClearSubItems()
{
for (int i = 0; i < listView1.ListItems.Count; i++)
{
listView1.ListItems[i].SetSubItem(0, ""); // erase old view
listView1.ListItems[i].ImageIndex = 0;
}
}
///
/// The main entry point for the application.
///
public static void Main(string[] args)
{
Application.Run(new Form1());
}
}
}
|
|
|
|
|
Ummmm...The databae code that your using is coming from a really OLD sample that worked under VS.NET Beta 1. The ADO namespace was replaced by SqlClient and OleDB namespaces back in VS.NET Beta 2, I think!
You'll have to rewrite your database handling code to the newer namespaces, depending on where your database is, either SQLClient for an SQL Server, or OleDB for an Access database.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
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;
}
}
}
|
|
|
|
|
I can't wrewrite your code for you because I simply don't hvae the time. I can point you to a page that will show you how to get a connection to an Access database, then you can follow the links, for retrieving records and such, from there.
MSDN - Creating Connections to Access Databases[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i used Gatagrid.Item and Datagrid.Coloums property in VS.NET previously. Now i am using ver 1.1. here i didn't found the above mentioned properties of Datagrid. do you found this in datagrid property collection.
Please feel free to contact.
Sreejith S S Nair - Bangalore
|
|
|
|
|
please help me!
How can get IP Address from local machine?
Thank you very much!
|
|
|
|
|
hi,
Use the following code to get the local IP address
System.Net.Dns.GetHostByName("localhost").AddressList[0].ToString();
If you are not intending to use "localhost" then you can use the name of your computer as well.
Hope this solves your problem.
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
|
Hi Everybody
How can I wrap the text of specific column in datagrid in WinApp Project?
Thanks.
|
|
|
|
|
mydatagrid[rowindex,coluumnindex]
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
thanks for the response... but i need a code for wrapping. do you know how to wrap? please give me sample.
|
|
|
|
|
I having difficulty accessing the object from form1 to another form in WinApp Project, unlike in Visual Studio 6 that you can access directly the object by Form1.Object1.text.
How can I do this either in VB.NET or C# in WinApp Project?
Thanks
|
|
|
|
|
Hi,
You can access an object of one form in another by 3 ways...
1) Make the object public or internal
2) Keep the object private but expose a public property for the same.
3) Pass the object in the constructor of the second form and then in the second form declare a private variable, initialize it in the constructor and access the object.
class form1
{
private ArrayList array = new ArrayList();
....
...
button1_click(...)
{
form2 = new form2(array);
form2.Show();
}
}
class form2
{
private ArrayList objArray;
form2(ArrayList obj)
{
objArray = obj;
}
button2_click(...)
{
MessageBox.Show(objArray.Count.ToString());
}
}
Hope this code helps you to understand the 3rd possibility...
and also hope that I haven't misunderstood your question.
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Thanks for the response.... but i still don't get it....
This is the scenario, I have two forms one is a parent form and the second is the lookup form. I need to access one of the textbox in parent and retrieve the value given by the lookup vise versa.
How can I access the specific textbox in parent and lookup form?
Thanks again..
|
|
|
|
|
hi,
look what you can do in this senario is :
On the button click event (before showing the 2nd form)...
Store the value of the textbox in a public variable...
Pass the object the the parent class to the 2nd form thru constructor
In the 2nd form use the parent form's object to access the public variable of the parent.
Now to access the textbox of the 2nd form from the parent:
declare a public variable in the 2nd form and set itz value with the text box value...
In the parent form you already have the object of the send... bcoz you r showing the 2nd from the parent...
So use the object to access the public variable of the 2nd form...
for example:
// the parent form
class parent : Form
{
// public variable in parent form to hold the textbox value
public string textVal = "";
...
...
// button click event delegate in parent form
private void button_click(...)
{
// store the textbox value in the public variable
textVal = textBox1.Text;
// instantiate child form with parent object in the constructor
childForm form2 = new childForm(this);
// showing the child form as modal dialog
form2.ShowDialog();
// after dialog is closed accessing the textbox value of the child form
MessageBox.Show(form2.textValChild);
// destroying the child form
form2.Close();
}
}
// the child form class
class childForm : Form
{
// public variable in the child form to store the textbox value of the child
public string textValChild = "";
private Form objparent = null;
// child form constructor with the parent form object
public childForm(Form parent)
{
this.objparent = parent;
}
...
...
// in the button click event delegate
private void Textbox2_Click(...)
{
// displaying the parent form textbox value
MessageBox.Show(this.objparent.textVal);
// storing the child form textbox value
this.textValChild = TextBox2.Text;
//hiding the child form... don't close otherwise itz object will be destroyed
this.Hide();
}
}
Hope this helps you...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
hi,
I already pass the value of parent form to the second form.
This time the value passed by the parent form already displayed by the second form in textbox for editing. After editing the second form must pass this value to the parent form.
Now I need to pass the value of the second form back to parent form without declaring another object of the parent form.
Note : The Second form is in MODAL STATE or DIALOG STATE.
Thanks And More Power!
|
|
|
|
|
hi,
no need to declare another object of the parent form... look at my previous code carefully... I have set the value of the second form textbox in the click event of childForm and then instead of closing the second form I have hidden it...has come back to the parent form and then accessed the second form value from the parent...
Please go thru the code carefully to understand what I'm saying... read the Click events carefully...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
When creating the child Form in the Parent form, set the Child form's Owner property to be the parent.
Then make some get property in the parent or a set property in the child to be get/set whenever the Object in the parent form chages (using events usually does the trick..)
|
|
|
|
|
Hi every body!
I want to write a web chat program (.net), But i don't know how to begin!
have you get any source code or link about this? please send me!
Thanks!
xyz
|
|
|
|
|
Please use the search capabilities of Code Project and also try Google. No one here is going to do your searches for you. This is why your posts are being ignored.
Regards,
Eric C. Tomlinson
I won't dignify your question with an answer. Yes, I program in VB6, but only because I'm addicted to eating!
|
|
|
|
|
I have hit a stumbling block......in my code I create a number of tab pages on a tab control. This can differ from person to person.
On each tabpage I have the following:
- Panel1 (name tab?_panel1) which contains:
-- treeview (tab?_treeview)
-- listbox (tab?_listbox)
- Panel2 (name tab?_panel2) which contains:
-- listview (tab?_listview)
-- richtextbox (tab?_richtext)
The "?" obviously refers to the tabpage that owns the control (tab0, tab1 etc.).
Where I've gotten stuck is this....how do I refer back to these controls elsewhere in my code? Specifically....I'm using a common event handler, getting the name of the parent (tabpage) of the parent (panel) from object sender. So I *know* the treeview on tab0 sent the event....how do I do "something" with the listview that is on tab0 (tab0_listview) based on the event tossed by tab0_treeview?
Thanks.....
|
|
|
|
|
What I usually do in this type of situation is to give the controls a name that I can rebuild later (much like you do) and create a lookup routine to find them. Doesn't make much sense without an example, huh.
I would name the controls (as I create them) with a name that can be easily parsed from within any event handlers invoked by the control. In keeping with your example,
Panel1 would be named 'tab_1_panel' and would contain
-- tab_1_treeview
-- tab_1_listbox
Panel2 would be named 'tab_2_panel' and would contain
-- tab_2_treeview
-- tab_2_listbox
In this way when an event is fired, I can parse the '1' or '2' out of the name of the invoking control, build the name of the control I need to access and look it up withing the parent's 'control' collection. If the tab_1_treeview fired an event and I needed access to the tab_1_listbox control, I would do the following from the event handler:
Step1 - ParseName
-- string[] sValues = oSender.Name.Split('_'); // returns an array with 3 elements 'tab', '1' and 'treeview'
-- int nIndex = sValues[1];
Step2 - Build listbox name
-- string sName = "tab_" + nIndex.ToString() + "_listbox";
Step3 - Retrieve control from the parent's controls collection
-- ListBox oListbox = this.Parent.Controls[sName];
Let me know if this works for you
|
|
|
|
|