Ejemplo n.º 1
0
        /// <summary>
        /// Inserts day into data base
        /// </summary>
        /// <param name="day"></param>
        public void InsertDay(Day day)
        {
            Debug.WriteLine("Insert day");
            if (day == null)
            {
                return;
            }
            try
            {
                using (SerilizeSqlCommand command = new SerilizeSqlCommand($"INSERT INTO {ToTimeTableName(CurrentUserName)} VALUES(@Date, @TimeIn, @TimeOut, @Details)"))
                {
                    command.AddParameter(new SqlParameter("Date", day.Date));
                    command.AddParameter(new SqlParameter("TimeIn", new DateTime().TimeOfDay));
                    command.AddParameter(new SqlParameter("TimeOut", new DateTime().TimeOfDay));
                    command.AddParameter(new SqlParameter("Details", day.Details));
                    AddCommand(command);
                }

                using (SerilizeSqlCommand command = new SerilizeSqlCommand($"INSERT INTO {ToDayTableName(CurrentUserName)} VALUES(@Date, @TimeIn, @TimeOut, @Details)"))
                {
                    command.AddParameter(new SqlParameter("Date", day.Date));
                    command.AddParameter(new SqlParameter("TimeIn", new DateTime().TimeOfDay));
                    command.AddParameter(new SqlParameter("TimeOut", new DateTime().TimeOfDay));
                    command.AddParameter(new SqlParameter("Details", day.Details));
                    AddCommand(command);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                throw;
            }
        }
Ejemplo n.º 2
0
 public void InsertTime(Time time)
 {
     if (!SqlEnabled)
     {
         return;
     }
     Debug.WriteLine("Insert time");
     if (time == null)
     {
         return;
     }
     try
     {
         using (SerilizeSqlCommand command = new SerilizeSqlCommand($"INSERT INTO {ToTimeTableName(CurrentUserName)} VALUES(@Date, @TimeIn, @TimeOut, @Details)"))
         {
             command.AddParameter(new SqlParameter("Date", time.TimeIn.Date));
             command.AddParameter(new SqlParameter("TimeIn", time.TimeIn.TimeOfDay));
             command.AddParameter(new SqlParameter("TimeOut", time.TimeOut.TimeOfDay));
             command.AddParameter(new SqlParameter("Details", ""));
             AddCommand(command);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
         throw;
     }
 }
Ejemplo n.º 3
0
        private void AddToPump(MySqlCommand command)
        {
            SerilizeSqlCommand serializedSqlCommand = new SerilizeSqlCommand(command.CommandText);

            serializedSqlCommand.Type = SerilizeSqlCommand.SqlType.MySql;
            foreach (MySqlParameter commandParameter in command.Parameters)
            {
                serializedSqlCommand.AddParameter(commandParameter);
            }
            _buffer.Add(serializedSqlCommand);

            UpdateChangedEvent?.Invoke(_buffer.Buffer());

            if (ServerState == State.Connected)
            {
                if (UpdateMode == UpdateModes.Async)
                {
                    PumpSqlAsync(_buffer.Buffer());
                }
                else
                {
                    PumpSql(_buffer.Buffer());
                }
            }
        }
Ejemplo n.º 4
0
 public void UpdateDetails(Day day)
 {
     if (!SqlEnabled)
     {
         return;
     }
     Debug.WriteLine("Update details");
     if (day.Details == "" && day.Times.Count == 0) // day is removed in local data if no time and details == ""
     {
         RemoveDay(day.Date);
     }
     else
     {
         using (SerilizeSqlCommand cmd = new SerilizeSqlCommand($"UPDATE {ToDayTableName(CurrentUserName)} SET Details = @Details WHERE( Date = '" + day.Date + "' AND TimeIn = '" + new TimeSpan() + "')"))
         {
             cmd.AddParameter(new SqlParameter("Details", day.Details));
             AddCommand(cmd);
         }
     }
 }