public CooperativeDevelopmentView()
        {
            InitializeComponent();
            CooperativeDevelopment data = new CooperativeDevelopment();

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

                    Id       = Convert.ToInt32(handle.FirstInput);
                    dateTime = DateTime.Today;
                    string   table = "CooperativeDevelopment";
                    string   type  = "Removed";
                    string   color = "Red";
                    EntryLog entry = new EntryLog();
                    entry.Add_Entry(table, type, Id, dateTime, color);
                    MessageBox.Show("Successfully Deleted!");

                    conn.CloseConnection();
                    CooperativeDevelopment data = new CooperativeDevelopment();
                    cooperativeDevelopment.ItemsSource = data.GetData();
                    DataContext = data;
                }
            }
        }
        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;
        }