Example #1
0
        private void devoluçõesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form devolucoes = new Devolucoes();

            devolucoes.Closed += (s, args) => this.Close();
            devolucoes.Show();
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string   lineSelected  = "";
            DateTime date          = DateTime.Now;
            string   data          = date.ToString("dd-MM-yy");
            string   idReq         = "";
            int      value         = 0;
            string   idEquipamento = "";

            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();
                    lineSelected  = selected;
                    date          = Convert.ToDateTime(dataGridView1.SelectedRows[0].Cells[2].Value);
                    idReq         = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    idEquipamento = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
                }
            }

            string       fileName = "Ficheiros de Texto/Requisicoes/R_" + DateTime.Parse(lineSelected).ToString("ddMMyy");
            String       line;
            StreamReader sr = new StreamReader(fileName);

            //Read the first line of text
            line = sr.ReadLine();
            int    a            = 0;
            char   delimiters   = ';';
            string linhaSaved   = "";
            int    linhaAlterar = -1;
            string hora         = String.Format("{0:t}", DateTime.Now).ToString();

            string[] parts     = line.Split(delimiters);
            bool     devolvido = false;

            while (line != null)
            {
                parts = line.Split(delimiters);
                if (value == 0)
                {
                    value++;
                }
                if (idReq == parts[0])
                {
                    linhaAlterar = a;
                    linhaSaved   = parts[0] + ";" + parts[1] + ";" + parts[2] + ";" + parts[3] + ";" + parts[4] + ";" + parts[5] + ";" + data + ";" + hora;
                    devolvido    = true;
                }
                line = sr.ReadLine();
                a++;
            }
            sr.Close();
            if (devolvido == true)
            {
                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("Equipamento Devolvido!");



                //AUMENTA STOCK----------------------------------------------------------
                fileName = "Ficheiros de Texto/equipamentos.txt";
                StreamReader reader = new StreamReader(fileName);
                //Read the first line of text
                line         = reader.ReadLine();
                a            = 0;
                delimiters   = ';';
                linhaSaved   = "";
                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[] lines2 = File.ReadAllLines(fileName);
                lines2[linhaAlterar] = linhaSaved;
                File.WriteAllLines(fileName, lines2);
                var liness = File.ReadAllLines(fileName).Where(arg => !string.IsNullOrWhiteSpace(arg));
                File.WriteAllLines(fileName, liness);
            }
            this.Hide();
            Form devolucoes = new Devolucoes();

            devolucoes.Closed += (s, args) => this.Close();
            devolucoes.Show();
        }