Example #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form lista_Equipamentos = new Lista_Equipamentos();

            lista_Equipamentos.Closed += (s, args) => this.Close();
            lista_Equipamentos.Show();
        }
Example #2
0
        private void listaEquipamentosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form lista_equipamentos = new Lista_Equipamentos();

            lista_equipamentos.Closed += (s, args) => this.Close();
            lista_equipamentos.Show();
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime dataReq  = DateTime.Now;
            string   nameFile = "Ficheiros de Texto/Requisicoes/R_" + dataReq.ToString("ddMMyy");

            string[] parts;
            string   idEquipamento = "";
            int      id            = 1;//= Convert.ToInt16(parts[0]);

            if (comboBox1.Text != "")
            {//Cria ficheiro de texto para o dia se nao existir e escreve o user, data,hora,sala,tipo_objeto
                StreamWriter sw;
                StreamReader sr = File.OpenText("Ficheiros de texto/userLogged");
                String.Format("{0:MM dd yy}", dataReq);
                string categoria = "";
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (this.dataGridView1.SelectedRows.Count == 1)
                    {
                        // get information of 1st column from the row
                        string selected = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                        categoria     = selected;
                        idEquipamento = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    }
                }
                if (this.dataGridView1.SelectedRows[0].Cells[4].Value.ToString() == "disponivel" && this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString() != "0")
                {
                    if (File.Exists(nameFile))
                    {
                        var lastLine = File.ReadLines(nameFile).Last();
                        parts = lastLine.Split(';');
                        id    = Convert.ToInt16(parts[0]) + 1;
                        sw    = File.AppendText(nameFile);
                    }
                    else
                    {
                        sw = File.CreateText(nameFile);
                    }
                    string user = sr.ReadLine();
                    sr.Close();
                    string data = dataReq.ToString("dd-MM-yyyy");;
                    string hora = String.Format("{0:t}", dataReq).ToString();
                    string sala = comboBox1.Text;
                    string line;
                    string cat = "";


                    StreamReader file = new StreamReader("Ficheiros de texto/categorias.txt");
                    while ((line = file.ReadLine()) != null)
                    {
                        parts = line.Split(';');


                        if (parts[1] == categoria)
                        {
                            cat = parts[0];
                            break;
                        }
                    }

                    string idObjeto = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    sw.WriteLine("\n" + id + ";" + user + ";" + data + ";" + hora + ";" + sala + ";" + idObjeto + "; ; ");
                    //BAIXAR STOCK----------------------------------------------------------
                    string       fileName = "Ficheiros de Texto/equipamentos.txt";
                    StreamReader reader   = new StreamReader(fileName);
                    //Read the first line of text
                    line = reader.ReadLine();
                    int    a            = 0;
                    char   delimiters   = ';';
                    string linhaSaved   = "";
                    int    linhaAlterar = -1;
                    parts = line.Split(delimiters);
                    while (line != null)
                    {
                        parts = line.Split(delimiters);
                        if (parts[0] == idEquipamento)
                        {
                            linhaAlterar = a;
                            int stock = Convert.ToInt16(parts[3]) - 1;
                            linhaSaved = parts[0] + ";" + parts[1] + ";" + parts[2] + ";" + stock.ToString() + ";" + parts[4];
                        }
                        line = reader.ReadLine();
                        a++;
                    }
                    reader.Close();
                    string[] lines1 = File.ReadAllLines(fileName);
                    lines1[linhaAlterar] = linhaSaved;
                    File.WriteAllLines(fileName, lines1);
                    var lines = File.ReadAllLines(fileName).Where(arg => !string.IsNullOrWhiteSpace(arg));
                    File.WriteAllLines(fileName, lines);



                    MessageBox.Show("Requisitado!");
                    sw.Close();
                    this.Hide();
                    Form lista_Equipamento = new Lista_Equipamentos();
                    lista_Equipamento.Closed += (s, args) => this.Close();
                    lista_Equipamento.Show();
                }
                else
                {
                    MessageBox.Show("Equipamento Indisponivel de momento");
                }
            }
            else
            {
                MessageBox.Show("É obrigatório escolher uma sala!");
            }
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            String       line;
            StreamReader sr = new StreamReader("Ficheiros de Texto/utilizadores.txt");

            //Read the first line of text
            line = sr.ReadLine();

            //Continue to read until you reach end of file
            while (line != null)
            {
                username = textBox1.Text;
                password = textBox2.Text;
                char     delimiters = ';';
                string[] parts      = line.Split(delimiters);

                if (parts[1] == username)
                {
                    if (parts[3] == password)
                    {
                        //se login == successful

                        utilizador.setNome(username);
//                        MessageBox.Show( "TOKEN \t" + WindowsIdentity.GetCurrent().Token.ToString());
                        StreamWriter sw = File.CreateText("Ficheiros de Texto/userLogged");
                        sw.WriteLine(username);
                        sw.Close();
                        MessageBox.Show("Bem vindo: " + utilizador.getNome());
                        this.Hide();
                        Form home = new Lista_Equipamentos();
                        home.Closed += (s, args) => this.Close();
                        home.Show();
                        break;
                    }
                    else
                    {
                        MessageBox.Show("Password Errada");
                    }
                }

                //write the lie to console window
                //Console.WriteLine(line);
                //Read the next line
                line = sr.ReadLine();
            }

            /* {
             *   MessageBox.Show("O user não existe");
             * }*/

            //close the file
            sr.Close();

            //NOTIFICACAO INTELIGENTE
            int cont = 0;

            //Foreach file in directory
            string[] fileEntries = Directory.GetFiles("Ficheiros de Texto/Requisicoes");
            foreach (string fileName in fileEntries)
            {
                StreamReader sa = new StreamReader(fileName);
                //Read the first line of text
                line = sa.ReadLine();
                int  a          = 0;
                char delimiters = ';';
                while (line != null)
                {
                    string[] parts = line.Split(delimiters);
                    if (parts.Length > 1)
                    {
                        if (parts[1] == textBox1.Text)
                        {
                            if (parts[6] == " ")
                            {
                                cont++;
                            }
                        }
                    }
                    line = sa.ReadLine();
                    a++;
                }
                sa.Close();
            }
            if (cont >= 1)
            {
                MessageBox.Show("Tem " + cont.ToString() + " equipamentos por entregar! Dirija-se ao CPR o mais brevemente possivel", "Alerta",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }