예제 #1
0
        public void saveInfrastructure(Infrastructure Inf)
        {
            cmd.CommandText = "INSERT INTO infrastructure(name, quantity, price, status)" +
                        " values(@name, @quantity,@price, @status)";
            cmd.Parameters.AddWithValue("@name", Inf.getName());
            cmd.Parameters.AddWithValue("@quantity", Inf.getQuantity());
            cmd.Parameters.AddWithValue("@price", Inf.getPrice());
            cmd.Parameters.AddWithValue("@status", Inf.getStatus());

            cmd.ExecuteNonQuery();
            conn.Close();
        }
예제 #2
0
        public void updateInfrastructure(Infrastructure Inf)
        {
            cmd.CommandText = " UPDATE infrastructure SET name = @name, quantity = @quantity, " +
                              " price = @price, status = @status " +
                              " where id = @id ";
            cmd.Parameters.AddWithValue("@id", Inf.getId());
            cmd.Parameters.AddWithValue("@name", Inf.getName());
            cmd.Parameters.AddWithValue("@quantity", Inf.getQuantity());
            cmd.Parameters.AddWithValue("@price", Inf.getPrice());
            cmd.Parameters.AddWithValue("@status", Inf.getStatus());

            cmd.ExecuteNonQuery();
            conn.Close();
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to add an infrastructure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    name = textBoxName.Text;
                    quantity = double.Parse(textBoxQuantity.Text);
                    price = double.Parse(textBoxPrice.Text);
                    status = textBoxStatus.Text;
                    Inf = new Infrastructure(name, quantity, price, status);
                    if (Inf.repOK())
                    {
                        InfMan = new InfrastructureManager();
                        InfMan.saveInfrastructure(Inf);

                        //write text file
                        //MessageBox.Show(cus.toString());
                        DateTime now = DateTime.Now;
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"property.txt", true);
                        file.WriteLine("Add Infrastructure{" + Inf.toString() + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Add Infrastructure successfully.");

                    }
                    else
                    {
                        MessageBox.Show("Invalid Infrastructure.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to delete an infrastructure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        id = table1.Rows[selectedIndex].Cells[0].Value.ToString();

                        InfMan = new InfrastructureManager();
                        InfMan.deleteInfrastructure(id);

                        //write text file
                        //MessageBox.Show(cus.toString());
                        Inf = new Infrastructure();
                        DateTime now = DateTime.Now;
                        date = now.ToString("yyyy-MM-dd");
                        System.IO.StreamWriter file = new System.IO.StreamWriter(@"property.txt", true);
                        file.WriteLine("Delete Infrastructure{" + id + "}" + "    " + now);
                        file.Close();
                        tableGetData();
                        MessageBox.Show("Delete Infrastructure successfully.");

                    }
                    else
                    {
                        MessageBox.Show("Select an infrastructure to delete.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Are you sure to update an infrastructure?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int selectedIndex = table1.CurrentCell.RowIndex;
                    if (selectedIndex >= 0)
                    {
                        id = table1.Rows[selectedIndex].Cells[0].Value.ToString();
                        name = textBoxName.Text;
                        quantity = double.Parse(textBoxQuantity.Text);
                        price = double.Parse(textBoxPrice.Text);
                        status = textBoxStatus.Text;
                        Inf = new Infrastructure(name, quantity, price, status);
                        Inf = new Infrastructure(id, name, quantity, price, status);
                        if (Inf.repOK())
                        {
                            InfMan = new InfrastructureManager();
                            InfMan.updateInfrastructure(Inf);

                            //write text file
                            DateTime now = DateTime.Now;
                            date = now.ToString("yyyy-MM-dd");
                            System.IO.StreamWriter file = new System.IO.StreamWriter(@"property.txt", true);
                            file.WriteLine("Update Infrastructure{" + Inf.toString() + "}" + "    " + now);
                            file.Close();
                            tableGetData();
                            MessageBox.Show("Update Infrastructure successfully.");

                        }
                        else
                        {
                            MessageBox.Show("Invalid Infrastructure.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Select an infrastructure to update.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }