Example #1
0
        private bool CreerFichier(List <CsLclient> Liste, string nomposte)
        {
            try
            {
                // Set the path and filename variable "path", filename being MyTest.csv in this example.
                // Change SomeGuy for your username.
                string date = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString("0000");
                string file = @"IMPAYES" + DateTime.Now.Year.ToString("0000") + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00") + ".csv";
                //string path = SessionObject.CheminImpression.Replace('[', '\\') + file;
                string path = @"C:\Impression\Interface\" + file;

                if (!string.IsNullOrEmpty(nomposte))
                {
                    path = @"\\" + nomposte + "\\Impression\\Interface\\" + file;
                }

                // Set the variable "delimiter" to ", ".
                string delimiter = ";";

                // This text is added only once to the file.
                if (System.IO.File.Exists(path))
                {
                    return(false);
                }

                if (!System.IO.File.Exists(path))
                {
                    // Create a file to write to.
                    string text;
                    Guid   cle = Guid.NewGuid();

                    text = "1;2211010000;" + date + ";BILL;1;0;0;0;0;0;0;0;0;0" + Environment.NewLine;
                    System.IO.File.WriteAllText(path, text, System.Text.Encoding.UTF8);

                    decimal total = 0;

                    for (int i = 0; i < Liste.Count; i++)
                    {
                        total += Liste[i].SOLDEFACTURE.Value;

                        text = "2;" + Liste[i].NDOC + delimiter + Liste[i].CLIENT + Liste[i].ORDRE + delimiter + " " + delimiter + Liste[i].NOM + delimiter + Liste[i].TELEPHONE + delimiter + Liste[i].sDATEFAC + delimiter + Liste[i].sDATEEXIG + delimiter + Liste[i].SOLDEFACTURE + delimiter + "XOF;" + Liste[i].ADRESSE + delimiter + Liste[i].sDATEDEBUT + delimiter + Liste[i].sDATEFIN + delimiter + Liste[i].REFEM + Environment.NewLine;
                        System.IO.File.AppendAllText(path, text, System.Text.Encoding.UTF8);
                    }

                    text = "3;2211010000;" + date + delimiter + Liste.Count + delimiter + total + ";0;0;0;0;0;0;0;0;0" + Environment.NewLine;
                    System.IO.File.AppendAllText(path, text, System.Text.Encoding.UTF8);

                    text = "0;0;0;0;0;0;0;0;0;0;0;0;0;0";
                    System.IO.File.AppendAllText(path, text, System.Text.Encoding.UTF8);
                }


                return(true);


                // Open the file to read from.
                //string readText = File.ReadAllText(path);
                //Console.WriteLine(readText);
            }
            catch (Exception ex)
            {
                ErrorManager.LogException(this, ex);
                return(false);
            }
        }