Exemplo n.º 1
0
        private void btnew_Click(object sender, EventArgs e)
        {
            urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
            Panel       panel1 = (Panel)form1.Controls["panel"];

            panel1.Controls.Add(newaccount.Instance);
            newaccount.Instance.Dock = DockStyle.Fill;
            newaccount.Instance.BringToFront();
            this.tbpassword.Text = string.Empty;
            this.tbusername.Text = string.Empty;
        }
Exemplo n.º 2
0
        private void btevaluate_Click(object sender, EventArgs e)
        {
            Program.idservice = Convert.ToInt32((sender as Button).Tag);
            urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
            Panel       panel1 = (Panel)form1.Controls["panel"];

            panel1.AutoScroll = false;
            panel1.Controls.Add(evaluation.Instance);
            evaluation.Instance.Dock = DockStyle.Fill;
            evaluation.Instance.BringToFront();
        }
Exemplo n.º 3
0
        private void btrent_Click(object sender, EventArgs e)
        {
            if (lbcurrentstate.Text == "Não")
            {
                MessageBox.Show("Esta Viatura encontra-se indisponivel de momento.", "DriveMi - UrbanMShare");
                return;
            }
            DialogResult rentconfirm = MessageBox.Show("Confirma o aluguer desta viatura?", "DriveMi - UrbanMShare", MessageBoxButtons.YesNo);

            if (rentconfirm == DialogResult.Yes)
            {
                sqlconn.Open();

                SqlCommand qry2 = new SqlCommand(@"INSERT INTO [0502Service] (
                                                 [IDclient], [IDvehicle], [ReservDateStart], [ReservDateEnd],[PickUpPlace],
                                                 [SimPrice],[CurrentState])
                                                 VALUES (@IDclient, @IDvehicle, @ReservDateStart, @ReservDateEnd, @PickUpPlace, 
                                                 @SimPrice, @CurrentState)", sqlconn);

                qry2.Parameters.Add("@IDclient", SqlDbType.VarChar).Value        = Program.idclient;
                qry2.Parameters.Add("@IDvehicle", SqlDbType.VarChar).Value       = Program.idrent;
                qry2.Parameters.Add("@ReservDateStart", SqlDbType.VarChar).Value = daterent.Value.ToString("yyyy-MM-dd HH:mm:ss");;
                qry2.Parameters.Add("@ReservDateEnd", SqlDbType.VarChar).Value   = datedelivery.Value.ToString("yyyy-MM-dd HH:mm:ss");;
                qry2.Parameters.Add("@PickUpPlace", SqlDbType.VarChar).Value     = idlocality;
                qry2.Parameters.Add("@SimPrice", SqlDbType.VarChar).Value        = simprice;
                qry2.Parameters.Add("@CurrentState", SqlDbType.VarChar).Value    = 1;

                qry2.ExecuteScalar();

                SqlCommand qry3 = new SqlCommand(@"UPDATE [0501Vehicle] SET [0501Vehicle].CurrentState = 0 WHERE [0501Vehicle].IDvehicle = @IDvehicle;", sqlconn);

                qry3.Parameters.Add("@IDvehicle", SqlDbType.VarChar).Value = Program.idrent;

                qry3.ExecuteScalar();

                sqlconn.Close();

                urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
                Panel       panel1 = (Panel)form1.Controls["panel"];
                panel1.AutoScroll = false;
                panel1.Controls.Add(services.Instance);
                services.Instance.Dock = DockStyle.Fill;
                services.Instance.BringToFront();
                services.Instance.cleanfilters();
                services.Instance.createform();

                MessageBox.Show("Viatura alugada com sucesso." + Environment.NewLine + "Pode proceder ao levantamnto da mesma.", "DriveMi - UrbanMShare");
            }
        }
Exemplo n.º 4
0
        private void bcancel_Click(object sender, EventArgs e)
        {
            urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
            Panel       panel1 = (Panel)form1.Controls["panel"];

            panel1.Width = 950;
            panel1.Left  = 0;
            foreach (Control c in this.Controls)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    ((TextBox)(c)).Text = string.Empty;
                }
                if (c.GetType() == typeof(MaskedTextBox))
                {
                    ((MaskedTextBox)(c)).Text = string.Empty;
                }
            }
            panel1.Controls.Add(login.Instance);
            login.Instance.Dock = DockStyle.Fill;
            login.Instance.BringToFront();
        }
Exemplo n.º 5
0
        private void ahpmethod()
        {
            double impF3F2;
            double impF2F3;
            double impF3F1;
            double impF1F3;
            double impF2F1;
            double impF1F2;
            double generalCIsum;

            double[,] general = new double[3, 5];

            if (tb1.Value > 8)
            {
                impF2F3 = Math.Abs(tb1.Value - 7);
                impF3F2 = Convert.ToDouble(1.0 / Math.Abs(tb1.Value - 7));
            }
            else
            {
                impF3F2 = Math.Abs(tb1.Value - 9);
                impF2F3 = Convert.ToDouble(1.0 / Math.Abs(tb1.Value - 9));
            }

            if (tb2.Value > 8)
            {
                impF1F2 = Math.Abs(tb2.Value - 7);
                impF2F1 = Convert.ToDouble(1.0 / Math.Abs(tb2.Value - 7));
            }
            else
            {
                impF2F1 = Math.Abs(tb2.Value - 9);
                impF1F2 = Convert.ToDouble(1.0 / Math.Abs(tb2.Value - 9));
            }

            if (tb3.Value > 8)
            {
                impF1F3 = Math.Abs(tb3.Value - 7);
                impF3F1 = Convert.ToDouble(1.0 / Math.Abs(tb3.Value - 7));
            }
            else
            {
                impF3F1 = Math.Abs(tb3.Value - 9);
                impF1F3 = Convert.ToDouble(1.0 / Math.Abs(tb3.Value - 9));
            }

            general[0, 0] = 1.0;
            general[0, 1] = impF1F2;
            general[0, 2] = impF1F3;
            general[0, 3] = Math.Pow(general[0, 0] * general[0, 1] * general[0, 2], 1.0 / 3.0);
            general[1, 0] = impF2F1;
            general[1, 1] = 1.0;
            general[1, 2] = impF2F3;
            general[1, 3] = Math.Pow(general[1, 0] * general[1, 1] * general[1, 2], 1.0 / 3.0);
            general[2, 0] = impF3F1;
            general[2, 1] = impF3F2;
            general[2, 2] = 1.0;
            general[2, 3] = Math.Pow(general[2, 0] * general[2, 1] * general[2, 2], 1.0 / 3.0);
            generalCIsum  = Convert.ToDouble(general[0, 3] + general[1, 3] + general[2, 3]);
            general[0, 4] = general[0, 3] / generalCIsum;
            general[1, 4] = general[1, 3] / generalCIsum;
            general[2, 4] = general[2, 3] / generalCIsum;

            sqlconn.Open();
            SqlCommand qry1 = new SqlCommand(@"SELECT [IDvehicle], [EvTopic1], [EvTopic2], [EvTopic3]
                                             FROM [0601EvaluationAvg] ORDER BY [IDvehicle]", sqlconn);

            reader = qry1.ExecuteReader();

            int n = 0;

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    n += 1;
                }
            }
            reader.Close();

            double[,] evaluation = new double[n, 5];
            double[,] factor_1   = new double[n, n + 2];
            double[,] factor_2   = new double[n, n + 2];
            double[,] factor_3   = new double[n, n + 2];

            reader = qry1.ExecuteReader();

            if (reader.HasRows)
            {
                int i = 0;
                while (reader.Read())
                {
                    evaluation[i, 0] = Convert.ToDouble(reader["IDvehicle"]);
                    evaluation[i, 1] = Convert.ToDouble(reader["EvTopic1"]);
                    evaluation[i, 2] = Convert.ToDouble(reader["EvTopic2"]);
                    evaluation[i, 3] = Convert.ToDouble(reader["EvTopic3"]);
                    i += 1;
                }
            }
            reader.Close();
            sqlconn.Close();

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    factor_1[i, j] = Convert.ToDouble(evaluation[i, 1] / evaluation[j, 1]);
                    factor_2[i, j] = Convert.ToDouble(evaluation[i, 2] / evaluation[j, 2]);
                    factor_3[i, j] = Convert.ToDouble(evaluation[i, 3] / evaluation[j, 3]);
                }
                factor_1[i, n] = 1;
                factor_2[i, n] = 1;
                factor_3[i, n] = 1;
            }

            double factor1CIsum = 0, factor2CIsum = 0, factor3CIsum = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    factor_1[i, n] *= factor_1[i, j];
                    factor_2[i, n] *= factor_2[i, j];
                    factor_3[i, n] *= factor_3[i, j];
                }
                factor_1[i, n] = Math.Pow(factor_1[i, n], 1.0 / n);
                factor1CIsum  += factor_1[i, n];
                factor_2[i, n] = Math.Pow(factor_2[i, n], 1.0 / n);
                factor2CIsum  += factor_2[i, n];
                factor_3[i, n] = Math.Pow(factor_3[i, n], 1.0 / n);
                factor3CIsum  += factor_3[i, n];
            }

            for (int i = 0; i < n; i++)
            {
                factor_1[i, n + 1] = factor_1[i, n] / factor1CIsum;
                factor_2[i, n + 1] = factor_2[i, n] / factor2CIsum;
                factor_3[i, n + 1] = factor_3[i, n] / factor3CIsum;
            }

            for (int i = 0; i < n; i++)
            {
                evaluation[i, 4] = factor_1[i, n + 1] * general[0, 4] + factor_2[i, n + 1] * general[1, 4] + factor_3[i, n + 1] * general[2, 4];
            }

            double[] scores = new double[n];

            for (int i = 0; i < n; i++)
            {
                scores[i] = evaluation[i, 4];
            }

            Array.Sort(scores);
            Array.Reverse(scores);

            Program.ahp_order = " ORDER BY CASE [0501Vehicle].IDvehicle ";
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (evaluation[j, 4] == scores[i])
                    {
                        Program.ahp_order += " WHEN " + evaluation[j, 0] + " THEN " + (i + 1);
                    }
                }
            }
            Program.ahp_order += " End";
            Program.qrystate   = 1;
            urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
            Panel       panel1 = (Panel)form1.Controls["panel"];

            panel1.AutoScroll = true;
            services.Instance.BringToFront();
            services.Instance.cleanfilters();
        }
Exemplo n.º 6
0
        private void btsave_Click(object sender, EventArgs e)
        {
            Regex    reg = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); //formato de email
            int      parsedValue;
            DateTime tmpDate, cartaValidadeDate, cPagValidadeDate, birthdayDate;

            if (DateTime.TryParse(tblicenceval.Text, out tmpDate))
            {
                cartaValidadeDate = DateTime.ParseExact(tblicenceval.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                cartaValidadeDate = DateTime.ParseExact("01-01-1000", "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            if (DateTime.TryParse(tbcardval.Text, out tmpDate))
            {
                cPagValidadeDate = DateTime.ParseExact(tbcardval.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                cPagValidadeDate = DateTime.ParseExact("01-01-1000", "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            if (DateTime.TryParse(tbbirthday.Text, out tmpDate))
            {
                birthdayDate = DateTime.ParseExact(tbbirthday.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }
            else
            {
                birthdayDate = DateTime.ParseExact("01-01-1000", "dd-MM-yyyy", CultureInfo.InvariantCulture);
            }

            if (tbusername.Text == "" || tbusername.Text == null || int.TryParse(tbusername.Text, out parsedValue))
            {
                MessageBox.Show("Campo nome de utilizador não preenchido devidamente.", "DriveMi - UrbanMShare");
            }
            else if (tbpassword.Text == "" || tbpassword.Text == null)
            {
                MessageBox.Show("Campo nome de Senha não preenchido devidamente.", "DriveMi - UrbanMShare");
            }
            else if (tbname.Text == "" || tbname.Text == null || int.TryParse(tbname.Text, out parsedValue))
            {
                MessageBox.Show("Campo nome não preenchido devidamente.", "DriveMi - UrbanMShare");
            }
            else if (tbaddress.Text == "" || tbaddress.Text == null || int.TryParse(tbaddress.Text, out parsedValue))
            {
                MessageBox.Show("Campo morada não preenchido devidamente.", "DriveMi - UrbanMShare");
            }
            else if (tbpostal1.Text == "" || tbpostal1.Text == null)
            {
                MessageBox.Show("Campo do código postal não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tbpostal1.Text.Length != 4)
            {
                MessageBox.Show("Insira um código postal válido.", "DriveMi - UrbanMShare");
            }
            else if (tbpostal2.Text == "" || tbpostal2.Text == null)
            {
                MessageBox.Show("Campo do código postal não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tblocality.Text == "" || tblocality.Text == null || int.TryParse(tblocality.Text, out parsedValue))
            {
                MessageBox.Show("Campo localidade não preenchid devidamente.", "DriveMi - UrbanMShare");
            }
            else if (tbfiscal.Text == "" || tbfiscal.Text == null)
            {
                MessageBox.Show("Campo número fiscal não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tbfiscal.Text.Length != 9)
            {
                MessageBox.Show("Insira um NIF válido.", "DriveMi - UrbanMShare");
            }
            else if (tbbirthday.Text == "" || tbbirthday.Text == null || birthdayDate.ToString() == "01-01-1000 00:00:00")
            {
                MessageBox.Show("Campo da data de nascimento com data inválida.", "DriveMi - UrbanMShare");
            }
            else if (tblicence.Text == "" || tblicence.Text == null)
            {
                MessageBox.Show("Campo do número da carta de condução não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tblicenceval.Text == "" || tblicenceval.Text == null || cartaValidadeDate.ToString() == "01-01-1000 00:00:00")
            {
                MessageBox.Show("Campo da validade da carta de condução com data inválida.", "DriveMi - UrbanMShare");
            }
            else if (cartaValidadeDate < DateTime.Now)
            {
                MessageBox.Show("A validade da carta de condução está expirada.", "DriveMi - UrbanMShare");
            }
            else if (tbcard.Text == "" || tbcard.Text == null)
            {
                MessageBox.Show("Campo do cartão de pagamento não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tbcard.Text.Length != 16)
            {
                MessageBox.Show("Insira um número de cartão de pagamento válido.", "DriveMi - UrbanMShare");
            }
            else if (tbcardval.Text == "" || tbcardval.Text == null || cPagValidadeDate.ToString() == "01-01-1000 00:00:00")
            {
                MessageBox.Show("Campo da validade do cartão com data inválida", "DriveMi - UrbanMShare");
            }
            else if (cPagValidadeDate < DateTime.Now)
            {
                MessageBox.Show("A validade do cartão de pagamento está expirada.", "DriveMi - UrbanMShare");
            }
            else if (tbemail.Text == "" || tbemail.Text == null)
            {
                MessageBox.Show("Campo email não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tbphone.Text == "" || tbphone.Text == null)
            {
                MessageBox.Show("Campo contacto não preenchido.", "DriveMi - UrbanMShare");
            }
            else if (tbphone.Text.Length != 9)
            {
                MessageBox.Show("Insira um número de contacto válido.", "DriveMi - UrbanMShare");
            }
            else if (!reg.IsMatch(tbemail.Text))
            {
                MessageBox.Show("Introduza um email válido.", "DriveMi - UrbanMShare");
            }
            else if (!int.TryParse(tbfiscal.Text, out parsedValue))
            {
                MessageBox.Show("O NIF que inseriu não são numéricos.", "DriveMi - UrbanMShare");
            }
            else
            {
                string   fullName   = tbname.Text;
                string[] names      = fullName.Split(' ');
                DateTime cardval    = DateTime.ParseExact(tbcardval.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                DateTime licenceval = DateTime.ParseExact(tblicenceval.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);
                DateTime birthday   = DateTime.ParseExact(tbbirthday.Text, "dd-MM-yyyy", CultureInfo.InvariantCulture);

                SqlConnection sqlconn = new SqlConnection(Program.strconn_str);
                sqlconn.Open();
                SqlCommand qry = new SqlCommand("SELECT count([IDperson]) FROM [00Autentication] Where [Usrname]=@username;", sqlconn);
                qry.Parameters.Add("@username", SqlDbType.VarChar).Value = tbusername.Text;
                int usercount = Convert.ToInt32(qry.ExecuteScalar());
                sqlconn.Close();

                if (usercount > 1)
                {
                    MessageBox.Show("O nome de utilizador escolhido já existe.", "DriveMi - UrbanMShare");
                    return;
                }

                sqlconn.Open();
                SqlCommand qry2 = new SqlCommand(@"INSERT INTO [0401Client] (
                                            [IDaddress], [IDlocality], [RegDate], [Name],[Address],[FiscalNr],
                                            [PayCardNr],[PayCardValidity],[LicenceNr],[LicenceNrValidity],
                                            [DateBirth],[SmallName])
                                            output INSERTED.IDclient VALUES ( 
                                            @IDaddress, @IDlocality, @RegDate, @Name, @Address, @FiscalNr, 
                                            @PayCardNr, @PayCardValidity, @LicenceNr, @LicenceNrValidity, 
                                            @DateBirth, @SmallName)"
                                                 , sqlconn);

                qry2.Parameters.Add("@IDaddress", SqlDbType.VarChar).Value         = tbpostal2.Text;
                qry2.Parameters.Add("@IDlocality", SqlDbType.VarChar).Value        = tbpostal1.Text;
                qry2.Parameters.Add("@RegDate", SqlDbType.VarChar).Value           = DateTime.Now.ToString("yyyy/MM/dd");
                qry2.Parameters.Add("@Name", SqlDbType.VarChar).Value              = tbname.Text;
                qry2.Parameters.Add("@Address", SqlDbType.VarChar).Value           = tbaddress.Text;
                qry2.Parameters.Add("@FiscalNr", SqlDbType.VarChar).Value          = tbfiscal.Text;
                qry2.Parameters.Add("@PayCardNr", SqlDbType.VarChar).Value         = tbcard.Text;
                qry2.Parameters.Add("@PayCardValidity", SqlDbType.VarChar).Value   = cardval.ToString("yyyy-MM-dd");
                qry2.Parameters.Add("@LicenceNr", SqlDbType.VarChar).Value         = tblicence.Text;
                qry2.Parameters.Add("@LicenceNrValidity", SqlDbType.VarChar).Value = licenceval.ToString("yyyy-MM-dd");
                qry2.Parameters.Add("@DateBirth", SqlDbType.VarChar).Value         = birthday.ToString("yyyy-MM-dd");
                qry2.Parameters.Add("@SmallName", SqlDbType.VarChar).Value         = names.First() + " " + names.Last();

                int iduser = Convert.ToInt32(qry2.ExecuteScalar());

                SqlCommand qry3 = new SqlCommand(@"INSERT INTO [00Autentication] (
                                            [IDperson], [IDpersonType], [Usrname], [Usrpass],[CurrentState])
                                            VALUES ( 
                                            @IDperson, @IDpersontype, @Usrname, @Usrpass, @CurrentState)"
                                                 , sqlconn);

                qry3.Parameters.Add("@IDperson", SqlDbType.VarChar).Value     = iduser;
                qry3.Parameters.Add("@IDpersontype", SqlDbType.VarChar).Value = 24;
                qry3.Parameters.Add("@Usrname", SqlDbType.VarChar).Value      = tbusername.Text;
                qry3.Parameters.Add("@Usrpass", SqlDbType.VarChar).Value      = Program.GetMD5(tbpassword.Text);
                qry3.Parameters.Add("@CurrentState", SqlDbType.VarChar).Value = 1;

                qry3.ExecuteScalar();

                SqlCommand qry4 = new SqlCommand(@"INSERT INTO [0403Contact] (
                                        [IDperson], [IDcontactType], [IDpersonType], [Contact],[Obs])
                                        VALUES (@IDperson, @IDcontactType, @IDpersonType, @Contact, @Obs)", sqlconn);

                qry4.Parameters.Add("@IDperson", SqlDbType.VarChar).Value      = iduser;
                qry4.Parameters.Add("@IDcontactType", SqlDbType.VarChar).Value = 4;
                qry4.Parameters.Add("@IDpersonType", SqlDbType.VarChar).Value  = 24;
                qry4.Parameters.Add("@Contact", SqlDbType.VarChar).Value       = tbemail.Text;
                qry4.Parameters.Add("@Obs", SqlDbType.VarChar).Value           = "Contacto de email guardado durante o registo.";

                qry4.ExecuteScalar();

                SqlCommand qry5 = new SqlCommand(@"INSERT INTO [0403Contact] (
                                    [IDperson], [IDcontactType], [IDpersonType], [Contact],[Obs])
                                    VALUES (@IDperson, @IDcontactType, @IDpersonType, @Contact, @Obs)", sqlconn);

                qry5.Parameters.Add("@IDperson", SqlDbType.VarChar).Value      = iduser;
                qry5.Parameters.Add("@IDcontactType", SqlDbType.VarChar).Value = 1;
                qry5.Parameters.Add("@IDpersonType", SqlDbType.VarChar).Value  = 24;
                qry5.Parameters.Add("@Contact", SqlDbType.VarChar).Value       = tbphone.Text;
                qry5.Parameters.Add("@Obs", SqlDbType.VarChar).Value           = "Contacto telefónico guardado durante o registo.";

                qry5.ExecuteScalar();

                sqlconn.Close();

                urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
                Panel       panel1 = (Panel)form1.Controls["panel"];
                panel1.Controls.Add(login.Instance);
                login.Instance.Dock = DockStyle.Fill;
                login.Instance.BringToFront();
                login.Instance.tbusername.Text = tbusername.Text;
                login.Instance.tbpassword.Text = tbpassword.Text;

                foreach (Control c in this.Controls)
                {
                    if (c.GetType() == typeof(TextBox))
                    {
                        ((TextBox)(c)).Text = string.Empty;
                    }
                    if (c.GetType() == typeof(MaskedTextBox))
                    {
                        ((MaskedTextBox)(c)).Text = string.Empty;
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void services_Load(object sender, EventArgs e)
        {
            while (Controls.Count > 0)
            {
                Controls[0].Dispose();
            }
            InitializeComponent();
            createform();

            sqlconn.Open();
            SqlCommand qry3 = new SqlCommand("SELECT [Brand] FROM [0302CarBrand] ORDER BY [Brand] ;", sqlconn);

            reader = qry3.ExecuteReader();
            cbbrand.Items.Add("Todas");
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cbbrand.Items.Add(reader["Brand"].ToString());
                }
            }
            reader.Close();

            SqlCommand qry4 = new SqlCommand("SELECT [DataValue] FROM [01BaseData] Where [DataType] = 2 Order by [DataValue] ;", sqlconn);

            reader = qry4.ExecuteReader();
            cbcolour.Items.Add("Todas");
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cbcolour.Items.Add(reader["DataValue"].ToString());
                }
            }
            reader.Close();

            SqlCommand qry5 = new SqlCommand("SELECT [DataValue] FROM [01BaseData] Where [DataType] = 8 Order by [DataValue] ;", sqlconn);

            reader = qry5.ExecuteReader();
            cbfueltype.Items.Add("Todas");
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cbfueltype.Items.Add(reader["DataValue"].ToString());
                }
            }
            reader.Close();

            SqlCommand qry6 = new SqlCommand("SELECT Distinct [Locality] FROM [0203Locality] ORDER BY [Locality];", sqlconn);

            reader = qry6.ExecuteReader();
            cblocalization.Items.Add("Todas");
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    cblocalization.Items.Add(reader["Locality"].ToString());
                }
            }
            reader.Close();

            sqlconn.Close();

            cbbrand.Text        = cbbrandtext;
            cbcolour.Text       = cbcolourtext;
            cbfueltype.Text     = cbfueltypetext;
            cblocalization.Text = cblocalizatontext;
            cbavailability.Text = cbavailabilitytext;
            cborder.Text        = cbordertext;

            urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
            Panel       panel1 = (Panel)form1.Controls["panel"];

            panel1.AutoScroll = false;
            panel1.AutoScroll = true;
        }
Exemplo n.º 8
0
        private void btlogin_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection sqlconn = new SqlConnection(Program.strconn_str);

                SqlCommand cmd = new SqlCommand(@"SELECT 
                                                [0401Client].IDclient, 
                                                [0401Client].SmallName, 
                                                [00Autentication].Usrname, 
                                                [00Autentication].Usrpass, 
                                                [00Autentication].CurrentState, 
                                                [0203Locality].Locality
                                                FROM (
                                                [00Autentication] INNER JOIN [0401Client] ON 
                                                [00Autentication].IDperson = [0401Client].IDclient) INNER JOIN [0203Locality] 
                                                ON [0401Client].IDlocality = [0203Locality].IDlocality
                                                WHERE [00Autentication].Usrname = @user and [00Autentication].Usrpass = @password;", sqlconn);

                cmd.Parameters.Add("@user", SqlDbType.VarChar).Value     = tbusername.Text;
                cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = Program.GetMD5(tbpassword.Text);

                sqlconn.Open();

                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        if (Convert.ToInt32(reader["CurrentState"]) == 0)
                        {
                            MessageBox.Show("O utilizador encontra-se desativado", "DriveMi - UrbanMShare");
                            this.tbpassword.Text = string.Empty;
                            this.tbusername.Text = string.Empty;
                            return;
                        }

                        Program.smallname = reader["SmallName"].ToString();
                        Program.idclient  = Convert.ToInt32(reader["IDclient"]);
                        urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
                        Panel       panel1 = (Panel)form1.Controls["panel"];
                        panel1.AutoScroll        = true;
                        panel1.AutoScrollMargin  = new System.Drawing.Size(20, 490);
                        panel1.AutoScrollMinSize = new System.Drawing.Size(20, 490);
                        panel1.Controls.Add(services.Instance);
                        panel1.Width           = 790;
                        panel1.Left            = 160;
                        services.Instance.Dock = DockStyle.Fill;
                        services.Instance.BringToFront();
                        this.tbpassword.Text = string.Empty;
                        this.tbusername.Text = string.Empty;
                    }
                }
                else
                {
                    MessageBox.Show("Utilizador ou password incorretos.", "DriveMi - UrbanMShare");
                    this.tbpassword.Text = string.Empty;
                    this.tbusername.Text = string.Empty;
                }
                reader.Close();
                sqlconn.Close();
            }
            catch (SqlException)
            {
                MessageBox.Show("Erro na ligação à base de dados", "DriveMi - UrbanMShare");
                this.tbpassword.Text = string.Empty;
                this.tbusername.Text = string.Empty;
            }
        }
Exemplo n.º 9
0
        private void btevaluate_Click(object sender, EventArgs e)
        {
            if (factor1 == 0 || factor2 == 0 || factor3 == 0)
            {
                MessageBox.Show("Para submeter a sua avaliação todos os fatores deverão ser avaliados.", "DriveMi - UrbanMShare");
            }
            else
            {
                sqlconn.Open();
                SqlCommand qry1 = new SqlCommand(@"INSERT INTO [0602Evaluation] (
                                                [IDservice], [EvTopic1], [EvTopic2], [EvTopic3])
                                                VALUES ( 
                                                @IDservice, @factor1, @factor2, @factor3)", sqlconn);

                qry1.Parameters.Add("@IDservice", SqlDbType.VarChar).Value = Program.idservice;
                qry1.Parameters.Add("@factor1", SqlDbType.VarChar).Value   = factor1;
                qry1.Parameters.Add("@factor2", SqlDbType.VarChar).Value   = factor2;
                qry1.Parameters.Add("@factor3", SqlDbType.VarChar).Value   = factor3;

                qry1.ExecuteScalar();

                SqlCommand qry2 = new SqlCommand(@"SELECT [0502Service].IDvehicle
                                                FROM [0602Evaluation] INNER JOIN [0502Service] ON 
                                                [0602Evaluation].IDservice = [0502Service].IDservice
                                                WHERE [0602Evaluation].IDservice=@IDservice;", sqlconn);

                qry2.Parameters.Add("@IDservice", SqlDbType.VarChar).Value = Program.idservice;

                int IdVehicle = Convert.ToInt32(qry2.ExecuteScalar());

                SqlCommand qry3 = new SqlCommand(@"UPDATE [0601EvaluationAvg]
                                                SET
                                                [0601EvaluationAvg].EvTopic1 = [updavg].EvTopic1,
                                                [0601EvaluationAvg].EvTopic2 = [updavg].EvTopic2,
	                                            [0601EvaluationAvg].EvTopic3 = [updavg].EvTopic3
                                                FROM [0601EvaluationAvg]
                                                INNER JOIN 
	                                                (SELECT 
	                                                [0502Service].IDvehicle, 
	                                                Avg([0602Evaluation].EvTopic1) AS EvTopic1, 
	                                                Avg([0602Evaluation].EvTopic2) AS EvTopic2, 
	                                                Avg([0602Evaluation].EvTopic3) AS EvTopic3
	                                                FROM ([0602Evaluation] INNER JOIN [0502Service] ON 
	                                                [0602Evaluation].IDservice = [0502Service].IDservice) INNER JOIN [0501Vehicle] ON 
	                                                [0502Service].IDvehicle = [0501Vehicle].IDvehicle
	                                                GROUP BY [0502Service].IDvehicle) AS [updavg]
                                                ON [0601EvaluationAvg].IDvehicle = [updavg].IDvehicle
                                                WHERE [updavg].IDvehicle = @IDVehicle", sqlconn);

                qry3.Parameters.Add("@IDVehicle", SqlDbType.VarChar).Value = IdVehicle;

                qry3.ExecuteScalar();

                MessageBox.Show("A UrbanMShare agradece a sua avaliação.", "DriveMi - UrbanMShare");

                urbanmshare form1  = (urbanmshare)Application.OpenForms["urbanmshare"];
                Panel       panel1 = (Panel)form1.Controls["panel"];
                panel1.AutoScroll = false;
                panel1.Controls.Add(historic.Instance);
                historic.Instance.Dock = DockStyle.Fill;
                historic.Instance.BringToFront();
                historic.Instance.createform();

                sqlconn.Close();
            }
        }