Exemplo n.º 1
0
        public DataOperationResult CreateNewCliente(Cliente newCliente) // devo scrivere una riga nel file clienti
        {
            DataOperationResult result = new DataOperationResult();

            try
            {
                System.IO.StreamWriter sw_clienti = System.IO.File.AppendText(clientiFileName);
                string new_cliente = newCliente.Username + ";" +
                                     newCliente.FirstName + ";" +
                                     newCliente.LastName + ";" +
                                     newCliente.CF;
                sw_clienti.WriteLine(new_cliente);
                sw_clienti.Close();
                System.IO.StreamWriter sw_cc  = System.IO.File.AppendText(CCFileName); // creo il conto corrente solo se ho un cliente
                ContoCorrente          new_cc = newCliente.mioConto;
                string s_new_cc = new_cc.GetNumeroConto() + ";" + new_cc.GetSaldo() + ";" + newCliente.Username;
                sw_cc.WriteLine(s_new_cc);
                sw_cc.Close();
                result.isOK = true;
            }
            catch (Exception excp)
            {
                result.isOK    = false;
                result.Message = excp.Message;
            }

            return(result);
        }
Exemplo n.º 2
0
        public DataOperationResult AggiornaFileMovimenti(Movimento mov)
        {
            DataOperationResult result = new DataOperationResult();

            try
            {
                System.IO.StreamWriter sw_clienti = System.IO.File.AppendText(MovimentiFileName); // aggiorno file movimenti (devo aggiornare anche il file cc con saldo)
                string new_cliente = mov.NumConto + ";" +
                                     mov.Tipo + ";" +
                                     mov.Importo + ";" +
                                     mov.Data + ";" +
                                     mov.Beneficiario;
                sw_clienti.WriteLine(new_cliente);
                sw_clienti.Close();

                /* manca finire di aggiorare il saldo nel file conto corrente
                 * string line_to_read;
                 * string line_to_write = null;
                 * char[] chararray = new char[1]; // se scrivessi char[] ca starei dichiarando un puntatore vuoto
                 * chararray[0] = ';';
                 * using (System.IO.StreamReader fileCC = new System.IO.StreamReader(CCFileName))
                 * {
                 *  while (!String.IsNullOrEmpty(line_to_read = fileCC.ReadLine())) // quella tra paresntesi si chiama guardia ed e' un espressione booleana
                 *  {
                 *      String[] resultArray = line_to_read.Split(chararray);
                 *      string current_conto = resultArray[0];
                 *      if (current_conto== mov.NumConto)
                 *    //RSOLVERE      line_to_write= mov.NumConto() + ";" + new_cc.GetSaldo() + ";" + newCliente.Username;
                 *  }
                 *
                 *  string line = null;
                 *  using (System.IO.StreamReader reader = new System.IO.StreamReader(CCFileName))
                 *  using (System.IO.StreamWriter writer = new System.IO.StreamWriter(tempCCFileName))
                 *  {
                 *      while ((line = reader.ReadLine()) != null)
                 *      {
                 *          if (line == line_to_write)
                 *          {
                 *              writer.WriteLine(line_to_write);
                 *          }
                 *          else
                 *          {
                 *              writer.WriteLine(line);
                 *          }
                 *          line_number++;
                 *      }
                 *  }
                 *
                 *
                 *  int line_to_edit = 2;
                 * string sourceFile = "source.txt";
                 * string destinationFile = "target.txt";
                 * string tempFile = "target2.txt";
                 *
                 * // Read the appropriate line from the file.
                 * string lineToWrite = null;
                 * using (StreamReader reader = new StreamReader(sourceFile))
                 * {
                 *  for (int i = 1; i <= line_to_edit; ++i)
                 *      lineToWrite = reader.ReadLine();
                 * }
                 *
                 * if (lineToWrite == null)
                 *  throw new InvalidDataException("Line does not exist in " + sourceFile);
                 *
                 * // Read from the target file and write to a new file.
                 * int line_number = 1;
                 * string line = null;
                 * using (StreamReader reader = new StreamReader(destinationFile))
                 * using (StreamWriter writer = new StreamWriter(tempFile))
                 * {
                 *  while ((line = reader.ReadLine()) != null)
                 *  {
                 *      if (line_number == line_to_edit)
                 *      {
                 *          writer.WriteLine(lineToWrite);
                 *      }
                 *      else
                 *      {
                 *          writer.WriteLine(line);
                 *      }
                 *      line_number++;
                 *  }
                 * }
                 *
                 * // TODO: Delete the old file and replace it with the new file here.
                 * //System.IO.StreamWriter sw_cc = System.IO.File.AppendText(CCFileName); // creo il conto corrente solo se ho un cliente
                 * //ContoCorrente new_cc = mov.mioConto;
                 * //string s_new_cc = new_cc.GetNumeroConto() + ";" + new_cc.GetSaldo() + ";" + newCliente.Username;
                 * //sw_cc.WriteLine(s_new_cc);
                 * //sw_cc.Close();
                 */
                result.isOK = true;
            }
            catch (Exception excp)
            {
                result.isOK    = false;
                result.Message = excp.Message;
            }

            return(result);
        }