예제 #1
0
        private void materialRaisedButton6_Click(object sender, EventArgs e)
        {
            //Untuk Validasi Room
            FileStream   bd   = new FileStream("Room.txt", FileMode.Open, FileAccess.Read);
            StreamReader bdd  = new StreamReader(bd);
            string       line = bdd.ReadLine();

            string[] dataroom2;
            int      flag = 0;

            while (line != null)
            {
                dataroom2 = line.Split('#');
                if (materialSingleLineTextField1.Text == dataroom2[0])
                {
                    flag = 1;
                }
                else
                {
                }
                line = bdd.ReadLine();
            }
            bdd.Close();
            bd.Close();

            //Load Data
            declaredata();

            //Membersihkan Error
            errorProvider1.Clear();

            //Check Data Kosong
            if (RoomNumber.Trim().Length != 0)
            {
                if (comboBox1.Text != "- Select Room Class -")
                {
                    if (Capacityroom.Trim().Length != 0)
                    {
                        if (Price.Trim().Length != 0)
                        {
                            if (comboBox2.Text != "- Select Room Status -")
                            {
                                if (comboBox3.Text != "- Select Room Condition -")
                                {
                                    if (flag != 1)
                                    {
                                        FileStream   fs       = new FileStream("Room.txt", FileMode.Append, FileAccess.Write);
                                        StreamWriter sw       = new StreamWriter(fs);
                                        string       savedata = RoomNumber + "#" + Roomclass + "#" + Capacityroom + "#" + Price + "#" + Roomstatus + "#" + Roomcondition + "#";
                                        sw.WriteLine(savedata);
                                        sw.Close();
                                        fs.Close();
                                        MessageBox.Show("Data has been added.", "SUCCESS!");
                                        this.Hide();
                                        var tc = new Technic();
                                        tc.Closed += (s, args) => this.Close();
                                        tc.Show();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Sorry room already exists!", "FAILED!");
                                        this.Hide();
                                        var tc = new Technic();
                                        tc.Closed += (s, args) => this.Close();
                                        tc.Show();
                                    }
                                }
                                else
                                {
                                    errorProvider1.SetError(comboBox3, "Please select room condition!");
                                }
                            }
                            else
                            {
                                errorProvider1.SetError(comboBox2, "Please select room status!");
                            }
                        }
                        else
                        {
                            errorProvider1.SetError(materialSingleLineTextField3, "Must be filled!");
                        }
                    }
                    else
                    {
                        errorProvider1.SetError(materialSingleLineTextField2, "Must be filled!");
                    }
                }
                else
                {
                    errorProvider1.SetError(comboBox1, "Please select roomclass!");
                }
            }
            else
            {
                errorProvider1.SetError(materialSingleLineTextField1, "Must be filled!");
            }
        }
예제 #2
0
        private void materialRaisedButton1_Click(object sender, EventArgs e)
        {
            string       room1      = materialSingleLineTextField6.Text;
            FileStream   ambildata1 = new FileStream("Room.txt", FileMode.Open, FileAccess.Read);
            StreamReader bacadata1  = new StreamReader(ambildata1);
            string       linee      = bacadata1.ReadLine();

            while (linee != null)
            {
                // Console.Clear();
                string[] dataroom = linee.Split('#');
                if (room1 == dataroom[0])
                {
                    dataroom0 = dataroom[0];
                    dataroom1 = dataroom[1];
                    dataroom2 = dataroom[2];
                    dataroom3 = dataroom[3];
                    dataroom4 = dataroom[4];
                    dataroom5 = dataroom[5];
                }
                else
                {
                }
                linee = bacadata1.ReadLine();
            }
            bacadata1.Close();
            ambildata1.Close();
            if (room1 == dataroom0)
            {
                //Load Data
                declaredata();

                //Membersihkan Error
                errorProvider1.Clear();

                //Check Data Kosong
                if (RoomNumber.Trim().Length != 0)
                {
                    if (comboBox1.Text != "- Select Room Class -")
                    {
                        if (Capacityroom.Trim().Length != 0)
                        {
                            if (Price.Trim().Length != 0)
                            {
                                if (comboBox2.Text != "- Select Room Status -")
                                {
                                    if (comboBox3.Text != "- Select Room Condition -")
                                    {
                                        string old    = dataroom0 + "#" + dataroom1 + "#" + dataroom2 + "#" + dataroom3 + "#" + dataroom4 + "#" + dataroom5 + "#";
                                        string neww   = RoomNumber + "#" + Roomclass + "#" + Capacityroom + "#" + Price + "#" + Roomstatus + "#" + Roomcondition + "#";
                                        string update = File.ReadAllText("Room.txt");
                                        update = update.Replace(old, neww);
                                        File.WriteAllText("Room.txt", update);
                                        MessageBox.Show("Data has been updated.", "SUCCESS!");
                                        this.Hide();
                                        var tc = new Technic();
                                        tc.Closed += (s, args) => this.Close();
                                        tc.Show();
                                    }
                                    else
                                    {
                                        errorProvider1.SetError(comboBox3, "Please select room condition!");
                                    }
                                }
                                else
                                {
                                    errorProvider1.SetError(comboBox2, "Please select room status!");
                                }
                            }
                            else
                            {
                                errorProvider1.SetError(materialSingleLineTextField3, "Must be filled!");
                            }
                        }
                        else
                        {
                            errorProvider1.SetError(materialSingleLineTextField2, "Must be filled!");
                        }
                    }
                    else
                    {
                        errorProvider1.SetError(comboBox1, "Please select roomclass!");
                    }
                }
                else
                {
                    errorProvider1.SetError(materialSingleLineTextField1, "Must be filled!");
                }
            }
            else
            {
                MessageBox.Show("Data not found, Try again!", "WRONG DATA!");
                materialSingleLineTextField6.Text = "";
                materialSingleLineTextField6.Focus();
            }
        }