Example #1
0
        public ReservedFundView()
        {
            InitializeComponent();
            ReservedFund data = new ReservedFund();

            reservedFund.ItemsSource = data.GetData();
        }
        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 ReservedFund WHERE Reserved_Id = " + handle.FirstInput, con))
                    {
                        con.Open();
                        command.ExecuteNonQuery();
                        con.Close();
                    }

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

                    conn.CloseConnection();
                    ReservedFund data = new ReservedFund();
                    reservedFund.ItemsSource = data.GetData();
                    DataContext = data;
                }
            }
        }
Example #3
0
        protected void Save_Click(object sender, RoutedEventArgs e)
        {
            double previous = this.last_total();

            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", new DateTime(2017, 2, 23));
                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();
            }
            ReservedFund data = new ReservedFund();

            reservedFund.ItemsSource = data.GetData();
        }
        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;
        }