Exemplo n.º 1
0
        // Read the Data from the  Data field 
        public void ReadData(TabPage currentTab, string ID)
        {
         
            string Fname     =null;
            string Lname     = null;
            string Phone     = null;
            string Addres    = null;
            string cusomer_id = null;
            int Sum=0 ;
            int price = 0;

            #region Read_out
            // Check the personal datas and read from the text Boxes 
            foreach (Control lapok in currentTab.Controls)
            {
                if (lapok.GetType().ToString() == "System.Windows.Forms.TextBox")
                {
                    switch (lapok.Name)
                    {
                        case "Fname":
                               
                                 if (  lapok.Text.Length <2)
                                 {
                                     MessageBox.Show("Please type in your Firs Name");
                                     return;
                                 }
                                 Fname = lapok.Text;
                                 
                    
                            break;
                            
                        case "Lname":

                            if (lapok.Text.Length < 2)
                            {
                                MessageBox.Show("Please type in your Last Name");
                                return;
                            }
                            Lname = lapok.Text;
                            break;

                        case "ID":

                            if (lapok.Text.Length < 1)
                            {
                                MessageBox.Show("Please type in your ID");
                                return;
                            }
                            cusomer_id = lapok.Text;
                            break;
                        case "Addres":

                            if (lapok.Text.Length < 2)
                            {
                                MessageBox.Show("Please type in your Addres");
                                return;
                            }
                            Addres = lapok.Text;
                            break;
               
                        case "Phone":
                            if (lapok.Text.Length < 2)
                            {
                               
                                MessageBox.Show("Please type in your Phone Number");
                                return;
                            }
                            Phone = lapok.Text;
                       
                            break;

                       
                        case "Sum":
                            if (lapok.Text.Length > 2)
                            {

                                if (int.TryParse(lapok.Text, out Sum))
                                {
                                    Sum = int.Parse(lapok.Text);
                                
                                }
                                else
                                {
                                    MessageBox.Show("Please type in a valid amount");
                                    return;
                                }
                            }
                            else
                            {
                                MessageBox.Show("Please type in the amount");
                                return;
                            }
                            
                            break;
                      
                    }
 
                }

            }
            #endregion

            // Insert data into Ugyfel class
            SqlCeCommand cmd;
                cmd = new SqlCeCommand("INSERT INTO Ugyfelek (ID,Kereszt_nev, Vezetek_nev, Cim, Telefon) VALUES (@Id,@Fname,@Lname, @Addres, @Phone)", Form1.con);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@Fname", Fname);
                cmd.Parameters.AddWithValue("@Lname", Lname);
                cmd.Parameters.AddWithValue("@Id", cusomer_id);
                cmd.Parameters.AddWithValue("@Phone", Phone);
                cmd.Parameters.AddWithValue("@Addres", Addres);


             // Check if the price is  correct 
                SqlCeCommand newcmd = new SqlCeCommand("SELECT *FROM  Autok  WHERE ID=@Car", Form1.con);
                newcmd.Parameters.AddWithValue("@Car", ID);
                SqlCeDataReader reader = newcmd.ExecuteReader();

                while (reader.Read())
                {
                    price = (int)reader["Eladasi_ar"];
        
                }

                if (Sum < price)
                {
                    MessageBox.Show("The Price you typed is not enough!");

                    return;
                }
                else
                {
                    // Update the Eladas Database with the customer personal data
                    cmd.ExecuteNonQuery();
                    cmd = new SqlCeCommand("INSERT INTO Eladas (Auto_ID,Ugyfel_ID,Eladasi_datum,Fizetett) VALUES (@Car,@Customer,@Date,@Price)", Form1.con);
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@Car", ID);
                    cmd.Parameters.AddWithValue("@Customer", cusomer_id);
                    cmd.Parameters.AddWithValue("@Date", DateTime.Now.ToShortDateString());
                    cmd.Parameters.AddWithValue("@Price", Sum);
                    cmd.ExecuteNonQuery();
                    cmd = new SqlCeCommand("UPDATE Autok SET Allapot ='eladva' WHERE ID=@Id", Form1.con);
                    cmd.Parameters.AddWithValue("@Id", ID);

                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Sold");

                    this.tabControl1.TabPages.Remove(currentTab);
                    this.Close();
                    Buy form3 = new Buy();
                    form3.Show();
                   


                }     
        }
Exemplo n.º 2
0
 private void button2_Click_1(object sender, EventArgs e)
 {
     //"Buy" menu
     Buy form3 = new Buy();
     form3.Show();
 }