public static string near(string str, string keyWord, Int32 padding) { /// Will search the string for a key word and return padding characters on each side /// Int32 location = 0; StringBuilder sb = new StringBuilder(); try { // get the first location of keyword location = str.IndexOf(keyWord, StringComparison.CurrentCultureIgnoreCase); while (location >= 0) { // adjust what will be displayed to whole words Int32 starting = nextWhiteSpace(ref str, location - 10, false); Int32 ending = nextWhiteSpace(ref str, location + padding, true); sb.AppendLine(str.Substring(starting, (ending - starting)) + "..."); // get full words now location = str.IndexOf(keyWord, (++ending > str.Length) ? str.Length : ending, StringComparison.CurrentCultureIgnoreCase); } if (sb.Length > 0) { str = sb.ToString(); } } catch (Exception ex) { TextLog.LogErr(String.Format("Error in Function near string:{0}, keyword: {1}, \n padding:{2}. \n {3}", str, keyWord, padding, ex.ToString())); } //TextLog.Logit(string.Format("Function near returning string of {0} length.", str.Length)); return(str); }
public static Int32 calcHoursToday(daily d) { // if start of day is midnight return // if start of day is valid and start lunch is entered //morning can be calculated //if end of lunch is entered and end of day is entered // afternoon can be calculated // if all 4 times or begin and end of day are entered then you can calculate the day Int32 fullDay = 0; Int32 lunch = 0; try { if ((d.start_day != null) && (d.end_day != null)) { fullDay = timeElapsed(d.start_day, d.end_day); } lunch = d.lunchDuration; if (fullDay != 0.0 && lunch != 0.0) { fullDay -= lunch; } } catch (Exception) { TextLog.LogErr(string.Format("Error in calcHoursToday, start {0}, lunchDuration{1}, DayEnd{2}", d.start_day, d.lunchDuration, d.end_day)); } return(fullDay); }
/************************* * [C#] * string ConnString = Utils.GetConnString(); * string SqlString = "Select * From Contacts Where FirstName = ? And LastName = ?"; * using (OleDbConnection conn = new OleDbConnection(ConnString)) * { * using (OleDbCommand cmd = new OleDbCommand(SqlString, conn)) * { * cmd.CommandType = CommandType.Text; * cmd.Parameters.AddWithValue("FirstName", txtFirstName.Text); * cmd.Parameters.AddWithValue("LastName", txtLastName.Text); * * conn.Open(); * using (OleDbDataReader reader = cmd.ExecuteReader()) * { * while (reader.Read()) * { * Response.Write(reader["FirstName"].ToString() + " " + reader["LastName"].ToString()); * } * } * } * } * *****************************************/ public DataTable SearchFor(string match, Boolean inNotes, string stop) { string str = string.Empty; string orderby = string.Empty; DataSet DS = new DataSet(); DataTable DT = new DataTable(); match = "%" + match + "%"; stop = "#" + stop + "#"; if (inNotes) { str = string.Format("Select date, Notes from 2002 where [date] > {0} AND Notes like ?", stop); orderby = " order by [date] desc"; } else { str = string.Format("Select ToDoDesc, Notes,Priority from ToDo where LastActivity > {0} AND Notes like ?", stop); orderby = " order by Created desc"; } //str += '"' + "%" + match + "%" + '"' + orderby; str += orderby; try { using (OleDbCommand cmd = new OleDbCommand(str, conn)) { cmd.CommandType = CommandType.Text; //if (inNotes) // cmd.Parameters.AddWithValue("[date]", stop); // HACK Can't get the [date] parameter to not error cmd.Parameters.AddWithValue("Notes", match); if (conn.State != ConnectionState.Open) { conn.Open(); } using (OleDbDataAdapter DA = new OleDbDataAdapter(cmd)) { DA.Fill(DS); if (DS.Tables.Count > 0) { DT = DS.Tables[0]; } } } } catch (Exception ex) { TextLog.LogErr(ex.ToString()); throw; } finally { if (DS != null) { DS = null; } closeConn(); } return(DT); }
public string mostRecentTask() { string str = string.Empty; try { dr = getDataReader("SELECT TOP 1 ToDo.ToDoDesc, ToDo.Created FROM ToDo ORDER BY ToDo.Created DESC;"); if (dr.HasRows) { dr.Read(); str = dr[0].ToString(); } } catch (Exception ex) { TextLog.LogErr(ex.ToString()); str = ex.ToString(); } finally { if (dr != null) { dr.Close(); } if (conn != null) { conn.Close(); } } return(str); //return "This is a test"; //SELECT TOP 1 ToDo.ToDoDesc, ToDo.Created FROM ToDo ORDER BY ToDo.Created DESC; }
public string dailys_Save(daily d) { string result = string.Empty; string cmdStr = string.Empty; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); if (noteExists(d)) { cmdStr = "update 2002 set start_day = ?, lunchDuration = ?, end_day = ?, Notes = ? where [date] = ?"; } else { cmdStr = "Insert into 2002 (start_day, lunchDuration, end_day, Notes, [date]) values (?,?,?,?,?)"; } try { using (OleDbCommand cmd = new OleDbCommand(cmdStr, conn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("start_day", d.start_day.ToString()); cmd.Parameters.AddWithValue("lunchDuration", d.lunchDuration.ToString()); cmd.Parameters.AddWithValue("end_day", d.end_day.ToString()); cmd.Parameters.AddWithValue("Notes", d.Notes); cmd.Parameters.AddWithValue("[date]", d.date.ToShortDateString()); if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.ExecuteNonQuery(); } } catch (Exception ex) { TextLog.LogErr(ex.ToString()); throw; } finally { closeConn(); stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. //TextLog.Logit(string.Format("Saved {0} in {1} Ms.", d.date.ToString(), ts.Milliseconds / 10)); } return(result); }
public static Int32 hoursMinutesToMinutes(string hoursMinutes) { try { if (hoursMinutes.ToLower() == "lunch") { return(0); } TimeSpan ts = TimeSpan.Parse(hoursMinutes); return((ts.Hours * 60) + ts.Minutes); } catch { TextLog.LogErr(string.Format("Attempted to convert {0} to minutes", hoursMinutes)); return(0); } }
public static Int32 timeElapsed(DateTime time1, DateTime time2) { Int32 result = 0; try { if (time1 < time2) { TimeSpan diffResult = time2.Subtract(time1); return(diffResult.Hours * 60 + diffResult.Minutes); } } catch (Exception ex) { TextLog.LogErr(string.Format("Error in timeElapsed, time1 = {0}, time1={1}.", time1.ToShortTimeString(), time2.ToShortTimeString())); TextLog.LogErr(ex.ToString()); } return(result); }
public DataTable getDataTable(string cmdString) { //TextLog.Logit("getDataTable: " + cmdString); DataSet DS = new DataSet(); DataTable DT = new DataTable(); try { OleDbCommand cmd = new OleDbCommand(cmdString, conn); if (conn.State != ConnectionState.Open) { conn.Open(); } cmd.CommandType = CommandType.Text; cmd.CommandText = cmdString; cmd.Connection = conn; using (OleDbDataAdapter DA = new OleDbDataAdapter(cmd)) { DA.Fill(DS); if (DS.Tables.Count > 0) { DT = DS.Tables[0]; } } } catch (Exception ex) { TextLog.LogErr(ex.ToString()); throw; } finally { if (DS != null) { DS = null; } closeConn(); } return(DT); }
public static List <DateTime> weekStartEndDates(DateTime theDay) { /// returns Key value pair /// firstOfWeek: date /// endOfWeek: date /// List <DateTime> dates = new List <DateTime>();; try { double dow = Convert.ToDouble(theDay.DayOfWeek); theDay = theDay.AddDays(-dow); // should be the start of the week DateTime eow = theDay.AddDays(7D); dates.Add(theDay); dates.Add(eow); } catch (Exception ex) { TextLog.LogErr(String.Format("Error in weekStartEndDates func: {0}", ex.ToString())); throw; } return(dates); }
public void task_Save(ToDo d) { string cmdStr = string.Empty; using (OleDbCommand cmd = new OleDbCommand(cmdStr, conn)) { cmd.CommandType = CommandType.Text; StringBuilder sb = new StringBuilder(); StringBuilder val = new StringBuilder(") values ("); Boolean bAnInsert = false; if (taskIDExists(d)) { sb.Append("UPDATE ToDo SET "); } else { sb.Append("INSERT INTO ToDo ("); bAnInsert = true; } cmd.Parameters.AddWithValue("ToDoDesc", d.ToDoDesc.ToString()); if (bAnInsert) // have to have a description { sb.Append("TodoDesc "); val.Append("? "); } else { sb.Append("ToDoDesc = ? "); } cmd.Parameters.AddWithValue("Notes", d.Notes.ToString()); if (bAnInsert) { sb.Append(", Notes "); val.Append(", ?"); } else { sb.Append(",Notes = ? "); } // end of the gotta haves if (d.Created.ToString() != string.Empty) { cmd.Parameters.AddWithValue("Creted", d.Created.ToString()); if (bAnInsert) { sb.Append(", Created "); val.Append(", ? "); } else { sb.Append(", Created = ? "); } } if (d.TaskStatus >= 0) { cmd.Parameters.AddWithValue("TaskStatus", d.TaskStatus.ToString()); if (bAnInsert) { sb.Append(", TaskStatus "); val.Append(", ? "); } else { sb.Append(", TaskStatus = ?"); } } if (d.Priority.ToString() != string.Empty) { cmd.Parameters.AddWithValue("Priority", d.Priority.ToString()); if (bAnInsert) { sb.Append(", Priority"); val.Append(", ?"); } else { sb.Append(", Priority = ?"); } } if (d.LOE.ToString() != string.Empty) { cmd.Parameters.AddWithValue("LOE", d.LOE.ToString()); if (bAnInsert) { sb.Append(", LOE"); val.Append(", ?"); } else { sb.Append(", LOE = ?"); } } if (d.LastActivity.ToString() != string.Empty) { cmd.Parameters.AddWithValue("LastActivity", DateTime.Now.ToShortDateString()); // //cmd.Parameters.AddWithValue("LastActivity", d.LastActivity.ToString()); if (bAnInsert) { sb.Append(",LastActivity"); val.Append(", ?"); } else { sb.Append(", LastActivity = ?"); } } if (bAnInsert) { sb.Append(val + ")"); } else { sb.Append(" where [TaskID] = ?"); cmd.Parameters.AddWithValue("TaskID", d.TaskID.ToString()); } cmd.CommandText = sb.ToString(); if (conn.State != ConnectionState.Open) { conn.Open(); } try { // Stopwatch stopWatch = new Stopwatch(); // stopWatch.Start(); cmd.ExecuteNonQuery(); // stopWatch.Stop(); // // Get the elapsed time as a TimeSpan value. // TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. //TextLog.Logit(string.Format("Saved Task {0} in {1} Ms.", d.ToDoDesc.ToString(), ts.Milliseconds / 10)); } catch (Exception ex) { TextLog.LogErr(ex.ToString()); throw; } if (bAnInsert) { d.TaskID = getTaskID(d); // find out what ID was assigned to this task } } if (conn.State == ConnectionState.Open) { conn.Close(); } }