Ejemplo n.º 1
0
        async Task CreateLog(string NFCtag, int Inout, int Lognum) //Set Lognum to 0 if entry
        {
            EntryLog Elog = new EntryLog();

            newlog.ReferenceNFC = NFCtag;
            newlog.TimeLog      = DateTime.Now;
            newlog.VesselName   = currentvessel;
            newlog.UnitName     = currentunit;

            AnalyticsLog Alog = new AnalyticsLog();

            Alog.ReferenceNFC = NFCtag;
            Alog.InOut        = Inout;
            Alog.TimeLog      = DateTime.Now;
            Alog.VesselName   = currentvessel;
            Alog.UnitName     = currentunit;

            if (Inout == -1)
            {
                await App.Database.DeleteLog(Lognum);

                await App.Database.AddAnalyticsLog(Alog);
            }


            if (Inout == 1)
            {
                await App.Database.AddLog(newlog);

                await App.Database.AddAnalyticsLog(Alog);
            }
        }
Ejemplo n.º 2
0
        ///<summary>Inserts one EntryLog into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(EntryLog entryLog, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO entrylog (";

            if (!useExistingPK && isRandomKeys)
            {
                entryLog.EntryLogNum = ReplicationServers.GetKeyNoCache("entrylog", "EntryLogNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "EntryLogNum,";
            }
            command += "UserNum,FKeyType,FKey,LogSource,EntryDateTime) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(entryLog.EntryLogNum) + ",";
            }
            command +=
                POut.Long(entryLog.UserNum) + ","
                + POut.Int((int)entryLog.FKeyType) + ","
                + POut.Long(entryLog.FKey) + ","
                + POut.Int((int)entryLog.LogSource) + ","
                + DbHelper.Now() + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                entryLog.EntryLogNum = Db.NonQ(command, true, "EntryLogNum", "entryLog");
            }
            return(entryLog.EntryLogNum);
        }
Ejemplo n.º 3
0
        ///<summary>Inserts one EntryLog into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(EntryLog entryLog, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                entryLog.EntryLogNum = ReplicationServers.GetKey("entrylog", "EntryLogNum");
            }
            string command = "INSERT INTO entrylog (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "EntryLogNum,";
            }
            command += "UserNum,FKeyType,FKey,LogSource,EntryDateTime) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(entryLog.EntryLogNum) + ",";
            }
            command +=
                POut.Long(entryLog.UserNum) + ","
                + POut.Int((int)entryLog.FKeyType) + ","
                + POut.Long(entryLog.FKey) + ","
                + POut.Int((int)entryLog.LogSource) + ","
                + DbHelper.Now() + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                entryLog.EntryLogNum = Db.NonQ(command, true, "EntryLogNum", "entryLog");
            }
            return(entryLog.EntryLogNum);
        }
Ejemplo n.º 4
0
 ///<summary>Inserts one EntryLog into the database.  Returns the new priKey.</summary>
 public static long Insert(EntryLog entryLog)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         entryLog.EntryLogNum = DbHelper.GetNextOracleKey("entrylog", "EntryLogNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(entryLog, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     entryLog.EntryLogNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(entryLog, false));
     }
 }
Ejemplo n.º 5
0
        public string GetAccess(string PoiId, string Code)
        {
            try
            {
                int _PoiId = Int32.Parse(PoiId);

                var poi    = db.PointsOfAccess.FirstOrDefault(item => item.ID == _PoiId);
                var device = db.Devices.FirstOrDefault(item => item.Code == Code);

                var success = poi.RegisteredDevices.FirstOrDefault(reg => reg.Device.Code == Code) != null;

                var entryLog = new EntryLog
                {
                    DateCreated     = DateTime.Now,
                    DeviceID        = device.ID,
                    PointOfAccessID = poi.ID,
                    Success         = success
                };
                db.EntryLogs.Add(entryLog);
                db.SaveChanges();

                if (success)
                {
                    return("TRUE");
                }
                else
                {
                    return("FALSE");
                }
            }
            catch (Exception e)
            {
                return("EXCEPTION");
            }
        }
Ejemplo n.º 6
0
        static async public Task <int> AddLog(EntryLog newdata)
        {
            string payload = JsonConvert.SerializeObject(newdata);
            int    newID   = await AddAPI("PostLog", payload);

            return(newID);
        }
Ejemplo n.º 7
0
        public ActionResult DeleteConfirmed(int id)
        {
            EntryLog entryLog = db.EntryLogs.Find(id);

            db.EntryLogs.Remove(entryLog);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            RemoveDialogView handle = new RemoveDialogView();

            if (handle.ShowDialog() == true)
            {
                using (SqlConnection con = new SqlConnection(@Connection.ConnectionString))
                {
                    if (handle.FirstInput != handle.SecondInput)
                    {
                        MessageBox.Show("Entry No. did not match.Try again.\n", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                    Connection conn = new Connection();
                    conn.OpenConection();
                    int           isLogin = 0;
                    string        query   = "SELECT * From Stuff ";
                    SqlDataReader reader  = conn.DataReader(query);
                    while (reader.Read())
                    {
                        stuff_name = (string)reader["Stuff_Name"];
                        stuff_pass = (string)reader["Stuff_Password"];
                        if (stuff_name.Equals(Login.GlobalStuffName) && stuff_pass.Equals(handle.GetPassword))
                        {
                            isLogin = 1;
                            break;
                        }
                    }
                    if (isLogin != 1)
                    {
                        MessageBox.Show("Wrong Password.Try again.\n", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }

                    using (SqlCommand command = new SqlCommand("DELETE FROM LoanCollection WHERE LoanCollection_Id = " + handle.FirstInput, con))
                    {
                        con.Open();
                        command.ExecuteNonQuery();
                        con.Close();
                    }

                    Id       = Convert.ToInt32(handle.FirstInput);
                    dateTime = (DateTime)Login.GlobalDate;
                    string   table = "Loan Collection Ledger";
                    string   type  = "Removed";
                    string   color = "Red";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);

                    conn.CloseConnection();

                    LoanLedger data   = new LoanLedger();
                    int        tempId = Convert.ToInt32(Loan.Text);
                    DailyLedger.ItemsSource = data.GetDataIndividual(method, tempId, 2);
                    DataContext             = data;
                }
            }
        }
Ejemplo n.º 9
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            RemoveDialogView handle = new RemoveDialogView();

            handle.ChangeLabelForMember();
            if (handle.ShowDialog() == true)
            {
                using (SqlConnection con = new SqlConnection(@Connection.ConnectionString))
                {
                    if (handle.FirstInput != handle.SecondInput)
                    {
                        MessageBox.Show("Member ID did not match.Try again.\n", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }
                    Connection conn = new Connection();
                    conn.OpenConection();
                    int           isLogin = 0;
                    string        query   = "SELECT * From Stuff ";
                    SqlDataReader reader  = conn.DataReader(query);
                    while (reader.Read())
                    {
                        stuff_name = (string)reader["Stuff_Name"];
                        stuff_pass = (string)reader["Stuff_Password"];
                        if (stuff_name.Equals(Login.GlobalStuffName) && stuff_pass.Equals(handle.GetPassword))
                        {
                            isLogin = 1;
                            break;
                        }
                    }
                    if (isLogin != 1)
                    {
                        MessageBox.Show("Wrong Password.Try again.\n", "Warning", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        return;
                    }

                    using (SqlCommand command = new SqlCommand("DELETE FROM MonthlyDepositDetails WHERE MemberId = " + handle.FirstInput, con))
                    {
                        con.Open();
                        command.ExecuteNonQuery();
                        con.Close();
                    }

                    Id       = Convert.ToInt32(handle.FirstInput);
                    dateTime = DateTime.Today;
                    string   table = "MonthlyDepositDetails";
                    string   type  = "Removed";
                    string   color = "Red";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);

                    conn.CloseConnection();
                    GeneralLedger data = new GeneralLedger();
                    //next click
                }
            }
        }
Ejemplo n.º 10
0
 ///<summary>Inserts many EntryLogs into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <EntryLog> listEntryLogs)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle || PrefC.RandomKeys)
     {
         foreach (EntryLog entryLog in listEntryLogs)
         {
             Insert(entryLog);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         while (index < listEntryLogs.Count)
         {
             EntryLog      entryLog = listEntryLogs[index];
             StringBuilder sbRow    = new StringBuilder("(");
             bool          hasComma = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO entrylog (");
                 sbCommands.Append("UserNum,FKeyType,FKey,LogSource,EntryDateTime) VALUES ");
             }
             else
             {
                 hasComma = true;
             }
             sbRow.Append(POut.Long(entryLog.UserNum)); sbRow.Append(",");
             sbRow.Append(POut.Int((int)entryLog.FKeyType)); sbRow.Append(",");
             sbRow.Append(POut.Long(entryLog.FKey)); sbRow.Append(",");
             sbRow.Append(POut.Int((int)entryLog.LogSource)); sbRow.Append(",");
             sbRow.Append(DbHelper.Now()); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 if (index == listEntryLogs.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
Ejemplo n.º 11
0
        ///<summary>Updates one EntryLog in the database.</summary>
        public static void Update(EntryLog entryLog)
        {
            string command = "UPDATE entrylog SET "
                             + "UserNum      =  " + POut.Long(entryLog.UserNum) + ", "
                             + "FKeyType     =  " + POut.Int((int)entryLog.FKeyType) + ", "
                             + "FKey         =  " + POut.Long(entryLog.FKey) + ", "
                             + "LogSource    =  " + POut.Int((int)entryLog.LogSource) + " "
                             //EntryDateTime not allowed to change
                             + "WHERE EntryLogNum = " + POut.Long(entryLog.EntryLogNum);

            Db.NonQ(command);
        }
Ejemplo n.º 12
0
 public ActionResult Edit([Bind(Include = "ID,DateCreated,Success,PointOfAccessID,DeviceID")] EntryLog entryLog)
 {
     if (ModelState.IsValid)
     {
         db.Entry(entryLog).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DeviceID        = new SelectList(db.Devices, "ID", "Code", entryLog.DeviceID);
     ViewBag.PointOfAccessID = new SelectList(db.PointsOfAccess, "ID", "Name", entryLog.PointOfAccessID);
     return(View(entryLog));
 }
Ejemplo n.º 13
0
        public void UpdateTable(string collection, string method, string collector, string loan, string installment, double balance, DateTime nextDate, int id, object sender, RoutedEventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
            {
                SqlCommand CmdSql = new SqlCommand("Update [LoanCollection] SET LoanCollection_Date=@Date, LoanCollection_Collection=@Collection, LoanCollection_Method=@Method, LoanCollection_Collector=@Collector, LoanCollection_Loan=@Loan, LoanCollection_Installment=@Installment WHERE LoanCollection_Id=" + id, conn);
                conn.Open();
                CmdSql.Parameters.AddWithValue("@Date", Login.GlobalDate);
                CmdSql.Parameters.AddWithValue("@Collection", collection);
                CmdSql.Parameters.AddWithValue("@Method", method);
                CmdSql.Parameters.AddWithValue("@Collector", collector);
                CmdSql.Parameters.AddWithValue("@Loan", loan);
                CmdSql.Parameters.AddWithValue("@Installment", installment);
                CmdSql.ExecuteNonQuery();
                conn.Close();
                //Updating LoanDetails Table
                double   fine       = 0.00;
                double   newBalance = balance - Convert.ToDouble(collection);
                DateTime dtd        = nextDate;
                if (method == "Daily")
                {
                    dtd = dtd.AddDays(1);
                }
                else if (method == "Weekly")
                {
                    dtd = dtd.AddDays(7);
                }
                else if (method == "Monthly")
                {
                    dtd = dtd.AddMonths(1);
                }

                SqlCommand CmdSql2 = new SqlCommand("UPDATE [LoanDetails] SET LoanDetails_LastPaid = @Date , LoanDetails_NextDate = @NextDate, LoanDetails_Fine = @Fine, LoanDetails_Due = @Due, LoanDetails_Balance = @Balance WHERE LoanDetails_Id=" + loan, conn);
                conn.Open();

                CmdSql2.Parameters.AddWithValue("@Date", Login.GlobalDate);
                CmdSql2.Parameters.AddWithValue("@NextDate", dtd);
                CmdSql2.Parameters.AddWithValue("@Fine", fine);
                CmdSql2.Parameters.AddWithValue("@Due", 0);
                CmdSql2.Parameters.AddWithValue("@Balance", newBalance);

                CmdSql2.ExecuteNonQuery();
                conn.Close();

                //Inserting value in Entry table
                string   table = method + " Loan Ledger";
                string   type  = "Updated";
                string   color = "Blue";
                EntryLog entry = new EntryLog();
                entry.Add_Entry(table, type, id, Login.GlobalDate, color);
                MessageBox.Show("Successfully Updated");
            }
        }
Ejemplo n.º 14
0
        // GET: EntryLogs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EntryLog entryLog = db.EntryLogs.Find(id);

            if (entryLog == null)
            {
                return(HttpNotFound());
            }
            return(View(entryLog));
        }
Ejemplo n.º 15
0
 ///<summary>Inserts one EntryLog into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(EntryLog entryLog)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(entryLog, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             entryLog.EntryLogNum = DbHelper.GetNextOracleKey("entrylog", "EntryLogNum");                  //Cacheless method
         }
         return(InsertNoCache(entryLog, true));
     }
 }
Ejemplo n.º 16
0
        async public Task <int> AddLog(EntryLog entrylog)
        {
            int maxID; int minID; //minID for offline mode -ID creation
            //Determine max ID already pulled from server
            var internalcount = _connection.Table <EntryLog>().ToListAsync().Result;

            if (internalcount.Count == 0)
            {
                maxID = 0; minID = 0;
            }
            else
            {
                maxID = internalcount.Select(c => c.EntryID).Max();
                minID = internalcount.Select(c => c.EntryID).Min();
                if (minID > 0)
                {
                    minID = -1;
                }
            }

            if (Globals.OfflineMode == false)
            {
                //Add unit and retrieve assigned ID
                int newID = await APIServer.AddLog(entrylog);

                if (newID == maxID + 1) //New ID is provided by Db, no error handling similar to worker flags.
                {
                    //Add worker to local database
                    entrylog.EntryID = newID;
                    await _connection.InsertAsync(entrylog);
                }
                if (newID > maxID + 1) //Missing entries added by another user
                {
                    IEnumerable <EntryLog> tempE = await APIServer.GetAllEntryLogs(maxID.ToString());

                    await _connection.InsertAllAsync(tempE);
                }
                return(newID);
            }
            else
            {
                //For offline mode, do not update online db and use negative ID#s
                entrylog.EntryID = minID - 1;
                await _connection.InsertAsync(entrylog);

                return(1);
            }
        }
Ejemplo n.º 17
0
        // GET: EntryLogs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EntryLog entryLog = db.EntryLogs.Find(id);

            if (entryLog == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DeviceID        = new SelectList(db.Devices, "ID", "Code", entryLog.DeviceID);
            ViewBag.PointOfAccessID = new SelectList(db.PointsOfAccess, "ID", "Name", entryLog.PointOfAccessID);
            return(View(entryLog));
        }
Ejemplo n.º 18
0
        ///<summary>Updates one EntryLog in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(EntryLog entryLog, EntryLog oldEntryLog)
        {
            string command = "";

            if (entryLog.UserNum != oldEntryLog.UserNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "UserNum = " + POut.Long(entryLog.UserNum) + "";
            }
            if (entryLog.FKeyType != oldEntryLog.FKeyType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FKeyType = " + POut.Int((int)entryLog.FKeyType) + "";
            }
            if (entryLog.FKey != oldEntryLog.FKey)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FKey = " + POut.Long(entryLog.FKey) + "";
            }
            if (entryLog.LogSource != oldEntryLog.LogSource)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "LogSource = " + POut.Int((int)entryLog.LogSource) + "";
            }
            //EntryDateTime not allowed to change
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE entrylog SET " + command
                      + " WHERE EntryLogNum = " + POut.Long(entryLog.EntryLogNum);
            Db.NonQ(command);
            return(true);
        }
Ejemplo n.º 19
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <EntryLog> TableToList(DataTable table)
        {
            List <EntryLog> retVal = new List <EntryLog>();
            EntryLog        entryLog;

            foreach (DataRow row in table.Rows)
            {
                entryLog               = new EntryLog();
                entryLog.EntryLogNum   = PIn.Long(row["EntryLogNum"].ToString());
                entryLog.UserNum       = PIn.Long(row["UserNum"].ToString());
                entryLog.FKeyType      = (OpenDentBusiness.EntryLogFKeyType)PIn.Int(row["FKeyType"].ToString());
                entryLog.FKey          = PIn.Long(row["FKey"].ToString());
                entryLog.LogSource     = (OpenDentBusiness.LogSources)PIn.Int(row["LogSource"].ToString());
                entryLog.EntryDateTime = PIn.DateT(row["EntryDateTime"].ToString());
                retVal.Add(entryLog);
            }
            return(retVal);
        }
        public void Handle(AddEntryLogCommand message)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return;
            }

            var user     = userRepository.GetById(message.UserId);
            var project  = projectRepository.GetById(message.ProjectId);
            var entryLog = new EntryLog(Guid.NewGuid(), message.EntryDate, message.Hours, message.Description);

            entryLog.User    = user;
            entryLog.Project = project;

            entryLogRepository.Add(entryLog);
            Commit();
        }
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            if ((string)Save.Content == "Insert")
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    SqlCommand CmdSql = new SqlCommand("INSERT INTO [FixedDepositLedger] (FixedDate, FixedId, MemberId, FixedDetails, FixedDeposit, FixedWithdraw, FixedBalance) VALUES (@Date, @Id , @MemberId,@Details, @Deposit, @Withdraw, @Balance)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Id", AccountNo.Text);
                    CmdSql.Parameters.AddWithValue("@MemberId", data.MemberId);
                    CmdSql.Parameters.AddWithValue("@Details", Details.Text);
                    CmdSql.Parameters.AddWithValue("@Deposit", Deposit.Text);
                    CmdSql.Parameters.AddWithValue("@Withdraw", Withdraw.Text);
                    CmdSql.Parameters.AddWithValue("@Balance", data.Balance + Convert.ToDouble(Deposit.Text) - Convert.ToDouble(Withdraw.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table

                    Id       = Convert.ToInt32(EntryNo.Text);
                    dateTime = DateTime.Today;

                    string   table = "Fixed Deposit Ledger";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                    MessageBox.Show("Successfully Inserted");
                }
            }

            // code for updating record
            else
            {
            }
            int tempId = Convert.ToInt32(AccountNo.Text);

            generalDepositLedger.ItemsSource = data.GetDataLedger(tempId, 2);
            DataContext = data;
        }
Ejemplo n.º 22
0
 ///<summary>Returns true if Update(EntryLog,EntryLog) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(EntryLog entryLog, EntryLog oldEntryLog)
 {
     if (entryLog.UserNum != oldEntryLog.UserNum)
     {
         return(true);
     }
     if (entryLog.FKeyType != oldEntryLog.FKeyType)
     {
         return(true);
     }
     if (entryLog.FKey != oldEntryLog.FKey)
     {
         return(true);
     }
     if (entryLog.LogSource != oldEntryLog.LogSource)
     {
         return(true);
     }
     //EntryDateTime not allowed to change
     return(false);
 }
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForError(Current) || CheckForError(Paid))
            {
                MessageBox.Show("Error!Check Input Again");
                return;
            }
            if ((string)Save.Content == "Save")
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    double     previous = this.last_remains();
                    SqlCommand CmdSql   = new SqlCommand("INSERT INTO [CooperativeDevelopment] (Cooperative_Date, Cooperative_Current, Cooperative_Paid, Cooperative_Previous, Cooperative_Remains) VALUES (@Date, @Current, @Paid, @Previous, @Remains)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Current", Current.Text);
                    CmdSql.Parameters.AddWithValue("@Paid", Paid.Text);
                    CmdSql.Parameters.AddWithValue("@Previous", previous);
                    CmdSql.Parameters.AddWithValue("@Remains", previous + Convert.ToDouble(Current.Text) - Convert.ToDouble(Paid.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table
                    Connection conn2 = new Connection();

                    string query = "SELECT TOP 1 * FROM CooperativeDevelopment ORDER BY Cooperative_Id DESC";
                    conn2.OpenConection();
                    SqlDataReader reader = conn2.DataReader(query);
                    while (reader.Read())
                    {
                        Id       = (int)reader["Cooperative_Id"];
                        dateTime = (DateTime)reader["Cooperative_Date"];
                    }
                    conn2.CloseConnection();

                    string   table = "Co-operative developement";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                    MessageBox.Show("Successfully Inserted!");
                }
            }

            else
            {
                int        temp_id = Id;
                Connection con     = new Connection();
                string     query   = "SELECT * FROM CooperativeDevelopment Order by Cooperative_Id Asc";
                con.OpenConection();
                SqlDataReader reader = con.DataReader(query);
                while (reader.Read())
                {
                    string rid     = reader["Cooperative_Id"].ToString();
                    int    r_id    = Convert.ToInt32(rid);
                    string cur     = reader["Cooperative_Current"].ToString();
                    double curint  = Convert.ToDouble(cur);
                    string paid    = reader["Cooperative_Paid"].ToString();
                    double paidint = Convert.ToDouble(paid);
                    string prev    = reader["Cooperative_Previous"].ToString();
                    double prevint = Convert.ToDouble(paid);

                    //code (if block) for updating rest of the table
                    if (temp_id < r_id)
                    {
                        Id = r_id;
                        double prevs = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [CooperativeDevelopment] SET Cooperative_Date = @Date , Cooperative_Paid = @Paid, Cooperative_Current = @Current, Cooperative_Remains = @Remain, Cooperative_Previous = @Previous WHERE Cooperative_Id=" + r_id, conn);
                            conn.Open();

                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Current", cur);
                            CmdSql.Parameters.AddWithValue("@Paid", paid);
                            CmdSql.Parameters.AddWithValue("@Previous", prevs);
                            CmdSql.Parameters.AddWithValue("@Remain", prevs + curint - paidint);
                            CmdSql.ExecuteNonQuery();
                            conn.Close();
                        }
                    }

                    //Code (else if block) for updating expected row
                    else if (temp_id == r_id)
                    {
                        double prevs = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [CooperativeDevelopment] SET Cooperative_Date = @Date , Cooperative_Current = @Current, Cooperative_Paid = @Paid, Cooperative_Previous = @Previous, Cooperative_Remains = @Remains WHERE Cooperative_Id=" + EntryNo.Text, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Current", Current.Text);
                            CmdSql.Parameters.AddWithValue("@Paid", Paid.Text);
                            CmdSql.Parameters.AddWithValue("@Previous", prevs);
                            CmdSql.Parameters.AddWithValue("@Remains", prevs + Convert.ToDouble(Current.Text) - Convert.ToDouble(Paid.Text));
                            CmdSql.ExecuteNonQuery();
                            conn.Close();

                            //Inserting value in Entry table

                            Id       = Convert.ToInt32(EntryNo.Text);
                            dateTime = DateTime.Today;

                            string   table = "Cooperative Development";
                            string   type  = "Updated";
                            string   color = "Blue";
                            EntryLog entry = new EntryLog();
                            entry.Add_Entry(table, type, Id, dateTime, color);
                        }

                        Save.Content = "Save";
                        MessageBox.Show("Successfully Updated!");
                    }
                }
                con.CloseConnection();
            }

            CooperativeDevelopment data = new CooperativeDevelopment();

            cooperativeDevelopment.ItemsSource = data.GetData();
            DataContext = data;
        }
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForError(Details) || CheckForError(Expenses))
            {
                MessageBox.Show("Error!Check Input Again");
                return;
            }

            double previous = this.last_total();

            if ((string)Save.Content == "Save")
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    SqlCommand CmdSql = new SqlCommand("INSERT INTO [Miscellaneous] (ME_Date, ME_Details, ME_Expenses, ME_Total) VALUES (@Date, @Details, @Expenses, @Total)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Details", Details.Text);
                    CmdSql.Parameters.AddWithValue("@Expenses", Expenses.Text);
                    CmdSql.Parameters.AddWithValue("@Total", previous + Convert.ToDouble(Expenses.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table
                    Connection conn2 = new Connection();

                    string query = "SELECT TOP 1 * FROM Miscellaneous ORDER BY ME_Id DESC";
                    conn2.OpenConection();
                    SqlDataReader reader = conn2.DataReader(query);
                    while (reader.Read())
                    {
                        Id       = (int)reader["ME_Id"];
                        dateTime = (DateTime)reader["ME_Date"];
                    }
                    conn2.CloseConnection();



                    string   table = "Miscellaneous Expenses";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                    MessageBox.Show("Successfully Saved");
                }
            }

            else
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    SqlCommand CmdSql = new SqlCommand("UPDATE [Miscellaneous] SET ME_Date = @Date , ME_Details = @Details, ME_Expenses = @Expenses, ME_Total = @Total WHERE ME_Id=" + EntryNo.Text, conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Details", Details.Text);
                    CmdSql.Parameters.AddWithValue("@Expenses", Expenses.Text);
                    CmdSql.Parameters.AddWithValue("@Total", previous + Convert.ToDouble(Expenses.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table

                    Id       = Convert.ToInt32(EntryNo.Text);
                    dateTime = DateTime.Today;

                    string   table = "Miscellaneous Expenses";
                    string   type  = "Updated";
                    string   color = "Blue";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                }
                Save.Content = "Save";
                MessageBox.Show("Successfully Updated");
            }

            Miscellaneous data = new Miscellaneous();

            Miscellaneous.ItemsSource = data.GetData();
            DataContext = data;
        }
Ejemplo n.º 25
0
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForError(Interest) || CheckForError(Deposit) || CheckForError(Withdraw) || CheckForError(ServiceCharge))
            {
                MessageBox.Show("Error!Check Input Again");
                return;
            }

            double remains = this.last_remains();

            if ((string)Save.Content == "Save")
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    SqlCommand CmdSql = new SqlCommand("INSERT INTO [BankAccount] (BankAccount_Date, BankAccount_Interest, BankAccount_Deposit, BankAccount_Withdraw, BankAccount_ServiceCharge,BankAccount_Remains) VALUES (@Date, @Interest, @Deposit, @Withdraw,@ServiceCharge, @Remains)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Interest", Interest.Text);
                    CmdSql.Parameters.AddWithValue("@Deposit", Deposit.Text);
                    CmdSql.Parameters.AddWithValue("@Withdraw", ServiceCharge.Text);
                    CmdSql.Parameters.AddWithValue("@ServiceCharge", Withdraw.Text);
                    CmdSql.Parameters.AddWithValue("@Remains", remains + Convert.ToDouble(Deposit.Text) + Convert.ToDouble(Interest.Text) - Convert.ToDouble(Withdraw.Text) - Convert.ToDouble(ServiceCharge.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table
                    Connection conn2 = new Connection();

                    string query = "SELECT TOP 1 * FROM BankAccount ORDER BY BankAccount_Id DESC";
                    conn2.OpenConection();
                    SqlDataReader reader = conn2.DataReader(query);
                    while (reader.Read())
                    {
                        Id       = (int)reader["BankAccount_Id"];
                        dateTime = (DateTime)reader["BankAccount_Date"];
                    }
                    conn2.CloseConnection();



                    string   table = "Bank Account";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                }
            }

            else
            {
                int        temp_id = Id;
                Connection con     = new Connection();
                string     query   = "SELECT * FROM BankAccount Order by BankAccount_Id Asc";
                con.OpenConection();
                SqlDataReader reader = con.DataReader(query);
                while (reader.Read())
                {
                    string rid     = reader["BankAccount_Id"].ToString();
                    int    r_id    = Convert.ToInt32(rid);
                    string dep     = reader["BankAccount_Deposit"].ToString();
                    double depint  = Convert.ToDouble(dep);
                    string with    = reader["BankAccount_Withdraw"].ToString();
                    double withint = Convert.ToDouble(with);
                    string intr    = reader["BankAccount_Deposit"].ToString();
                    double intint  = Convert.ToDouble(intr);
                    string sc      = reader["BankAccount_ServiceCharge"].ToString();
                    double scint   = Convert.ToDouble(sc);

                    //code (if block) for updating rest of the table
                    if (temp_id < r_id)
                    {
                        Id = r_id;
                        double remain = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [BankAccount] SET BankAccount_Date = @Date , BankAccount_Deposit = @Deposit, BankAccount_Withdraw = @Withdraw, BankAccount_Interest = @Interest, BankAccount_Remains = @Remains WHERE BankAccount_Id=" + r_id, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Interest", intr);
                            CmdSql.Parameters.AddWithValue("@Deposit", dep);
                            CmdSql.Parameters.AddWithValue("@Withdraw", with);
                            CmdSql.Parameters.AddWithValue("@ServiceCharge", sc);
                            CmdSql.Parameters.AddWithValue("@Remains", remain + depint + intint - withint - scint);
                            CmdSql.ExecuteNonQuery();
                            conn.Close();
                        }
                    }

                    //Code (else if block) for updating expected row
                    else if (temp_id == r_id)
                    {
                        double remain = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [BankAccount] SET BankAccount_Date = @Date , BankAccount_ServiceCharge = @ServiceCharge, BankAccount_Interest = @Interest, BankAccount_Deposit = @Deposit, BankAccount_Withdraw = @Withdraw, BankAccount_Remains = @Remains WHERE BankAccount_Id=" + EntryNo.Text, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Interest", Interest.Text);
                            CmdSql.Parameters.AddWithValue("@Deposit", Deposit.Text);
                            CmdSql.Parameters.AddWithValue("@Withdraw", Withdraw.Text);
                            CmdSql.Parameters.AddWithValue("@ServiceCharge", ServiceCharge.Text);
                            CmdSql.Parameters.AddWithValue("@Remains", remain + Convert.ToDouble(Deposit.Text) + Convert.ToDouble(Interest.Text) - Convert.ToDouble(Withdraw.Text) - Convert.ToDouble(ServiceCharge.Text));
                            CmdSql.ExecuteNonQuery();
                            conn.Close();

                            //Inserting value in Entry table

                            Id       = Convert.ToInt32(EntryNo.Text);
                            dateTime = DateTime.Today;

                            string   table = "Bank Account";
                            string   type  = "Updated";
                            string   color = "Blue";
                            EntryLog entry = new EntryLog();
                            entry.Add_Entry(table, type, Id, dateTime, color);
                        }
                        Save.Content = "Save";
                    }
                }
                con.CloseConnection();
            }

            BankAccountInformation data = new BankAccountInformation();

            bankAccountInformation.ItemsSource = data.GetData();
            DataContext = data;
        }
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForError(Deposit) || CheckForError(Expenses))
            {
                MessageBox.Show("Error!Check Input Again");
                return;
            }

            double remains = this.last_remains();

            if ((string)Save.Content == "Save")
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    SqlCommand CmdSql = new SqlCommand("INSERT INTO [CashInformation] (Cash_Date, Cash_Previous, Cash_Deposit, Cash_Expenses, Cash_Remains,Cash_Total) VALUES (@Date, @Previous, @Deposit, @Expenses, @Remains,@Total)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Previous", remains);
                    CmdSql.Parameters.AddWithValue("@Deposit", Deposit.Text);
                    CmdSql.Parameters.AddWithValue("@Expenses", Expenses.Text);
                    CmdSql.Parameters.AddWithValue("@Remains", remains + Convert.ToDouble(Deposit.Text) - Convert.ToDouble(Expenses.Text));
                    CmdSql.Parameters.AddWithValue("@Total", remains + Convert.ToDouble(Deposit.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table
                    Connection conn2 = new Connection();

                    string query = "SELECT TOP 1 * FROM CashInformation ORDER BY Cash_Id DESC";
                    conn2.OpenConection();
                    SqlDataReader reader = conn2.DataReader(query);
                    while (reader.Read())
                    {
                        Id       = (int)reader["Cash_Id"];
                        dateTime = (DateTime)reader["Cash_Date"];
                    }
                    conn2.CloseConnection();

                    MessageBox.Show("Successfully Inserted!");


                    string   table = "Cash Information";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                }
            }

            else
            {
                int        temp_id = Id;
                Connection con     = new Connection();
                string     query   = "SELECT * FROM CashInformation Order by Cash_Id Asc";
                con.OpenConection();
                SqlDataReader reader = con.DataReader(query);
                while (reader.Read())
                {
                    string rid    = reader["Cash_Id"].ToString();
                    int    r_id   = Convert.ToInt32(rid);
                    string dep    = reader["Cash_Deposit"].ToString();
                    double depint = Convert.ToDouble(dep);
                    string exp    = reader["Cash_Expenses"].ToString();
                    double expint = Convert.ToDouble(exp);

                    //code (if block) for updating rest of the table
                    if (temp_id < r_id)
                    {
                        Id = r_id;
                        double remain = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [CashInformation] SET Cash_Date = @Date , Cash_Deposit = @Deposit, Cash_Expenses = @Expenses, Cash_Remains = @Remains, Cash_Total = @Total WHERE Cash_Id=" + r_id, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Deposit", dep);
                            CmdSql.Parameters.AddWithValue("@Expenses", exp);
                            CmdSql.Parameters.AddWithValue("@Remains", remain + depint - expint);
                            CmdSql.Parameters.AddWithValue("@Total", remain + depint);
                            CmdSql.ExecuteNonQuery();
                            conn.Close();
                        }
                    }

                    //Code (else if block) for updating expected row
                    else if (temp_id == r_id)
                    {
                        double remain = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [CashInformation] SET Cash_Date = @Date , Cash_Previous = @Previous, Cash_Deposit = @Deposit, Cash_Expenses = @Expenses, Cash_Total = @Total, Cash_Remains = @Remains WHERE Cash_Id=" + EntryNo.Text, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Previous", remain);
                            CmdSql.Parameters.AddWithValue("@Deposit", Deposit.Text);
                            CmdSql.Parameters.AddWithValue("@Expenses", Expenses.Text);
                            CmdSql.Parameters.AddWithValue("@Remains", remain + Convert.ToDouble(Deposit.Text) - Convert.ToDouble(Expenses.Text));
                            CmdSql.Parameters.AddWithValue("@Total", remain + Convert.ToDouble(Deposit.Text));
                            CmdSql.ExecuteNonQuery();
                            conn.Close();

                            //Inserting value in Entry table

                            Id       = Convert.ToInt32(EntryNo.Text);
                            dateTime = DateTime.Today;

                            string   table = "Cash Information";
                            string   type  = "Updated";
                            string   color = "Blue";
                            EntryLog entry = new EntryLog();
                            entry.Add_Entry(table, type, Id, dateTime, color);
                        }
                        Save.Content = "Save";
                        MessageBox.Show("Successfully Updated");
                    }
                }
            }


            CashInformation data = new CashInformation();

            cashInformation.ItemsSource = data.GetData();
            DataContext = data;
        }
Ejemplo n.º 27
0
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForError(Amount) || CheckForError(Bonus))
            {
                MessageBox.Show("Error!Check Input Again");
                return;
            }
            //double remains = this.last_remains();
            using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
            {
                if ((string)Save.Content == "Save")
                {
                    SqlCommand CmdSql = new SqlCommand("INSERT INTO [Salary] (Salary_Date, Salary_Amount, Salary_Bonus, Salary_Total) VALUES (@Date, @Amount, @Bonus, @Total)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@Amount", Amount.Text);
                    CmdSql.Parameters.AddWithValue("@Bonus", Bonus.Text);
                    CmdSql.Parameters.AddWithValue("@Total", Convert.ToDouble(Amount.Text) + Convert.ToDouble(Bonus.Text));
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table
                    Connection conn2 = new Connection();

                    string query = "SELECT TOP 1 * FROM Salary ORDER BY Salary_Id DESC";
                    conn2.OpenConection();
                    SqlDataReader reader = conn2.DataReader(query);
                    while (reader.Read())
                    {
                        Id       = (int)reader["Salary_Id"];
                        dateTime = (DateTime)reader["Salary_Date"];
                    }
                    conn2.CloseConnection();



                    string   table = "Salary";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                }
                else
                {
                    using (SqlConnection con = new SqlConnection(@Connection.ConnectionString))
                    {
                        SqlCommand CmdSql = new SqlCommand("UPDATE [Salary] SET Salary_Date = @Date , Salary_Amount = @Amount, Salary_Bonus = @Bonus, Salary_Total = @Total WHERE Salary_Id=" + EntryNo.Text, conn);
                        conn.Open();
                        CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                        CmdSql.Parameters.AddWithValue("@Amount", Amount.Text);
                        CmdSql.Parameters.AddWithValue("@Bonus", Bonus.Text);
                        CmdSql.Parameters.AddWithValue("@Total", Convert.ToDouble(Amount.Text) + Convert.ToDouble(Bonus.Text));
                        CmdSql.ExecuteNonQuery();
                        conn.Close();

                        //Inserting value in Entry table

                        Id       = Convert.ToInt32(EntryNo.Text);
                        dateTime = DateTime.Today;

                        string   table = "Reserved Fund";
                        string   type  = "Updated";
                        string   color = "Blue";
                        EntryLog entry = new EntryLog();
                        entry.Add_Entry(table, type, Id, dateTime, color);
                        Save.Content = "Save";
                        MessageBox.Show("Successfully Updated");
                    }
                }
            }
            Salary data = new Salary();

            salary.ItemsSource = data.GetData();
            DataContext        = data;
        }
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            if (CheckForError(Current) || CheckForError(Withdraw))
            {
                MessageBox.Show("Error!Check Input Again");
                return;
            }
            double previous = this.last_total();

            if ((string)Save.Content == "Save")
            {
                using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                {
                    SqlCommand CmdSql = new SqlCommand("INSERT INTO [ReservedFund] (Reserved_Date, Reserved_Remaining, Reserved_Current, Reserved_Previous, Reserved_Total,Reserved_Withdraw) VALUES (@ReservedFund_date, @ReservedFund_remainig, @ReservedFund_current, @ReservedFund_previous, @ReservedFund_total,@ReservedFund_withdraw)", conn);
                    conn.Open();
                    CmdSql.Parameters.AddWithValue("@ReservedFund_date", Date.SelectedDate);
                    CmdSql.Parameters.AddWithValue("@ReservedFund_remainig", Convert.ToDouble(Current.Text) - Convert.ToDouble(Withdraw.Text));
                    CmdSql.Parameters.AddWithValue("@ReservedFund_current", Current.Text);
                    CmdSql.Parameters.AddWithValue("@ReservedFund_previous", previous);
                    CmdSql.Parameters.AddWithValue("@ReservedFund_total", previous + Convert.ToDouble(Current.Text) - Convert.ToDouble(Withdraw.Text));
                    CmdSql.Parameters.AddWithValue("@ReservedFund_withdraw", Withdraw.Text);
                    CmdSql.ExecuteNonQuery();
                    conn.Close();

                    //Inserting value in Entry table
                    Connection conn2 = new Connection();

                    string query = "SELECT TOP 1 * FROM ReservedFund ORDER BY Reserved_Id DESC";
                    conn2.OpenConection();
                    SqlDataReader reader = conn2.DataReader(query);
                    while (reader.Read())
                    {
                        dateTime = (DateTime)reader["Reserved_Date"];
                    }
                    conn2.CloseConnection();

                    string   table = "Reserved Fund";
                    string   type  = "Inserted";
                    string   color = "Green";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                    MessageBox.Show("Successfully Inserted");
                }
            }
            else
            {
                int        temp_id = Id;
                Connection con     = new Connection();
                string     query   = "SELECT * FROM ReservedFund Order by Reserved_Id Asc";
                con.OpenConection();
                SqlDataReader reader = con.DataReader(query);
                while (reader.Read())
                {
                    string rid     = reader["Reserved_Id"].ToString();
                    int    r_id    = Convert.ToInt32(rid);
                    string cur     = reader["Reserved_Current"].ToString();
                    double curint  = Convert.ToDouble(cur);
                    string with    = reader["Reserved_Withdraw"].ToString();
                    double withint = Convert.ToDouble(with);

                    //code (if block) for updating rest of the table
                    if (temp_id < r_id)
                    {
                        Id = r_id;
                        double previous_edit = this.edited_total();
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [ReservedFund] SET Reserved_Date = @Date , Reserved_Current = @Current, Reserved_Withdraw = @Withdraw, Reserved_Total = @Total, Reserved_Previous = @Previous, Reserved_Remaining = @Remaining WHERE Reserved_Id=" + r_id, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Current", cur);
                            CmdSql.Parameters.AddWithValue("@Withdraw", with);
                            CmdSql.Parameters.AddWithValue("@Previous", previous_edit);
                            CmdSql.Parameters.AddWithValue("@Total", previous_edit + curint - withint);
                            CmdSql.Parameters.AddWithValue("@Remaining", curint - withint);
                            CmdSql.ExecuteNonQuery();
                            conn.Close();
                        }
                        Console.Write(Id + " " + r_id + " " + temp_id + "...");
                    }

                    //Code (else if block) for updating expected row
                    else if (temp_id == r_id)
                    {
                        double previous_edit = this.edited_total();

                        Console.Write(Id + " " + r_id + " " + temp_id + "---");
                        using (SqlConnection conn = new SqlConnection(@Connection.ConnectionString))
                        {
                            SqlCommand CmdSql = new SqlCommand("UPDATE [ReservedFund] SET Reserved_Date = @Date , Reserved_Current = @Current, Reserved_Withdraw = @Withdraw, Reserved_Total = @Total, Reserved_Previous = @Previous, Reserved_Remaining = @Remaining WHERE Reserved_Id=" + EntryNo.Text, conn);
                            conn.Open();
                            CmdSql.Parameters.AddWithValue("@Date", Date.SelectedDate);
                            CmdSql.Parameters.AddWithValue("@Current", Current.Text);
                            CmdSql.Parameters.AddWithValue("@Withdraw", Withdraw.Text);
                            CmdSql.Parameters.AddWithValue("@Previous", previous_edit);
                            CmdSql.Parameters.AddWithValue("@Total", previous_edit + Convert.ToDouble(Current.Text) - Convert.ToDouble(Withdraw.Text));
                            CmdSql.Parameters.AddWithValue("@Remaining", Convert.ToDouble(Current.Text) - Convert.ToDouble(Withdraw.Text));
                            CmdSql.ExecuteNonQuery();
                            conn.Close();

                            //Inserting value in Entry table

                            Id       = Convert.ToInt32(EntryNo.Text);
                            dateTime = DateTime.Today;

                            string   table = "Reserved Fund";
                            string   type  = "Updated";
                            string   color = "Blue";
                            EntryLog entry = new EntryLog();
                            entry.Add_Entry(table, type, Id, dateTime, color);
                            Save.Content = "Save";
                            MessageBox.Show("Successfully Updated");
                        }
                    }
                }
                con.CloseConnection();
            }
            ReservedFund data = new ReservedFund();

            reservedFund.ItemsSource = data.GetData();
            DataContext = data;
        }
Ejemplo n.º 29
0
        //Refresh and Seed entire database
        async public Task RefreshDatabase()
        {
            Unit         unit   = new Unit();
            Vessel       vessel = new Vessel();
            Worker       worker = new Worker();
            EntryLog     newlog = new EntryLog();
            AnalyticsLog Alog   = new AnalyticsLog();
            Random       rnd    = new Random();

            //Add list of workers
            List <string> workerfirst = new List <string> {
                "Carl", "Sam", "Nisbit", "Johnny", "Earl", "Pete", "Douglas", "Cara", "Avril", "Betty-Sue", "Dougy", "Alex", "Tom", "Tara", "Indy", "Brad", "Stu", "Eddy", "Nero", "Carl", "Sam", "Nisbit", "Johnny", "Earl", "Pete", "Douglas", "Cara", "Avril", "Betty-Sue", "Dougy", "Alex", "Tom", "Tara", "Indy", "Brad", "Stu", "Eddy", "Nero"
            };
            List <string> workerlast = new List <string> {
                "Johnson", "Black", "Trout", "Smith", "Rogers", "Jury", "Slick", "Salty", "Hardy", "Bolton", "Carter", "Silversmith", "Snake", "Black", "White", "Wattson", "Ericson", "Edge", "Winter", "Ruderson-Jergen", "Johnson", "Black", "Trout", "Smith", "Rogers", "Jury", "Slick", "Salty", "Hardy", "Bolton", "Carter", "Silversmith", "Snake", "Black", "White", "Wattson", "Ericson", "Edge"
            };
            List <string> companyname = new List <string> {
                "IOL", "IOL", "IOL", "IOL", "CEDA", "CEDA", "TEAM", "TEAM", "TEAM", "TAMS", "TAMS", "TAMS", "TAMS", "Curren", "Curren", "Curren", "Safway", "Safway", "Safway", "IOL", "IOL", "IOL", "IOL", "CEDA", "CEDA", "TEAM", "TEAM", "TEAM", "TAMS", "TAMS", "TAMS", "TAMS", "Curren", "Curren", "Curren", "Safway", "Safway", "Safway"
            };
            List <string> nfclist = new List <string> {
                "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138"
            };
            string DB = "QQQ";

            for (int i = 0; i <= workerfirst.Count - 1; i++)
            {
                worker.FirstName   = workerfirst[i];
                worker.LastName    = workerlast[i];
                worker.Company     = companyname[i];
                worker.CreatedTime = DateTime.Now;
                worker.Activated   = 1;
                Globals.NFCtempcount++;
                worker.ReferenceNFC = DB + "_" + nfclist[i];
                await AddWorker(worker);
            }

            string[] unitname = new string[]  { "Office Building", "Plant 1", "Construction Site" };
            foreach (string t in unitname)
            {
                //Add Unit from unitname list
                unit.Name = t;
                await App.Database.AddUnit(unit);

                //Add a random vessel tag for each unit (x3-6)
                int VperU = rnd.Next(3, 7);
                for (int i = 1; i <= VperU; i++)
                {
                    int    VorT = (int)rnd.Next(1, 3);
                    string Vtype;
                    if (VorT == 1)
                    {
                        Vtype = "Entrance";
                    }
                    else
                    {
                        Vtype = "Checkpoint";
                    }
                    int Vnum = rnd.Next(100, 400);
                    vessel.Name     = Vtype + "-" + Vnum;
                    vessel.Unitname = t;
                    await AddVessel(vessel);

                    //50% Chance for active entry to be present on added vessel
                    int status = rnd.Next(0, 2);
                    if (status == 1)
                    {
                        int Logs     = 6;
                        int EntriesV = rnd.Next(0, Logs + 1); //Random number of entries per vessel

                        //Create worker name temp lists to allow temporary removal as 'workers enter vessels'
                        List <string> Ctemp = new List <string>(); Ctemp.AddRange(companyname);
                        List <string> Ftemp = new List <string>(); Ftemp.AddRange(workerfirst);
                        List <string> Ltemp = new List <string>(); Ltemp.AddRange(workerlast);
                        List <string> Ntemp = new List <string>(); Ntemp.AddRange(nfclist);
                        for (int k = 0; k < EntriesV; k++)
                        {
                            //Randomize worker selection and datetime stamp
                            int W         = rnd.Next(0, workerfirst.Count - k);
                            int timestamp = rnd.Next(1, 10);

/*                            //Create workerID Redundent due to NFC tie to worker
 *                          newlog.WorkerID = W+1;
 *                          newlog.Company = Ctemp[W];
 *                          newlog.FirstName = Ftemp[W];
 *                          newlog.LastName = Ltemp[W];*/
                            newlog.ReferenceNFC = DB + "_" + Ntemp[W];
                            newlog.TimeLog      = DateTime.Now.AddHours(-timestamp);
                            newlog.VesselName   = vessel.Name;
                            newlog.UnitName     = vessel.Unitname;
                            await AddLog(newlog);

                            //Create analytics log (z days of data)
                            for (int z = 1; z < 4; z++)
                            {
                                //adding time randomizers
                                int      xhour  = rnd.Next(1, 8);
                                int      xhour2 = rnd.Next(1, 8);
                                int      xmin   = rnd.Next(0, 59);
                                int      xmin2  = rnd.Next(0, 59);
                                DateTime xtime  = new DateTime();

                                //Create entry log
                                Alog.ReferenceNFC = DB + "_" + Ntemp[W];
                                Alog.InOut        = 1;
                                xtime             = DateTime.Now.AddHours(-(24 * z + xhour));
                                xtime             = xtime.AddMinutes(-xmin);
                                Alog.TimeLog      = xtime;
                                Alog.VesselName   = vessel.Name;
                                Alog.UnitName     = vessel.Unitname;
                                await APIServer.AddRecord(Alog);

                                //create exit log
                                Alog.ReferenceNFC = DB + "_" + Ntemp[W];
                                Alog.InOut        = -1;
                                xtime             = DateTime.Now.AddHours(-(24 * z - xhour2));
                                xtime             = xtime.AddMinutes(+xmin2);
                                Alog.TimeLog      = xtime;
                                Alog.VesselName   = vessel.Name;
                                Alog.UnitName     = vessel.Unitname;
                                await APIServer.AddRecord(Alog);
                            }

                            // matching most recent entry of  Entrylog
                            Alog.ReferenceNFC = DB + "_" + Ntemp[W];
                            Alog.InOut        = 1;
                            Alog.TimeLog      = DateTime.Now.AddHours(-timestamp);
                            Alog.VesselName   = vessel.Name;
                            Alog.UnitName     = vessel.Unitname;
                            await APIServer.AddRecord(Alog);

                            //Removing worker from list to avoid duplication
                            Ctemp.RemoveAt(W); Ftemp.RemoveAt(W); Ltemp.RemoveAt(W); Ntemp.RemoveAt(W);
                        }
                        //Populate analytics list with database
                        IEnumerable <AnalyticsLog> tempA = await APIServer.GetAllAnalyticsLogs("0");

                        _connection.DropTableAsync <AnalyticsLog>().Wait();
                        _connection.CreateTableAsync <AnalyticsLog>().Wait();
                        await _connection.InsertAllAsync(tempA);
                    }
                }
            }

            return;// Task.CompletedTask;
        }
Ejemplo n.º 30
0
 ///<summary>Inserts one EntryLog into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(EntryLog entryLog)
 {
     return(InsertNoCache(entryLog, false));
 }