Example #1
0
 public void Export_SPUN(System.DateTime FromDate, System.DateTime ToDate, string path, string prefix, int reeType, int processType, bool writePeriod, string sql, string note)
 {
     string str;
     System.IO.StreamWriter writer = null;
     try
     {
         System.Text.Encoding encoding = System.Text.Encoding.GetEncoding(0x362);
         string str2 = string.Concat((string[]) new string[] { path, @"\", prefix, ((string) DALSql.ExecuteScalar("select isnull(sn.Setting_GetValue('GLOBAL','Код района из 1С'),'')", null)), "_", System.DateTime.Now.ToString("yyMMdd_HHmmss"), ".txt" });
         System.IO.File.Delete(str2);
         writer = new System.IO.StreamWriter(str2, false, encoding);
         writer.WriteLine("#TYPEORG\tRKC");
         writer.WriteLine("#KODORG\t\t" + ((string) ((string) DALSql.ExecuteScalar("select isnull(sn.Setting_GetValue('SID','Код организации'),'')", null))));
         writer.WriteLine("#NAMEORG\t" + ((string) ((string) DALSql.ExecuteScalar("select isnull(sn.Setting_GetValue('SID','Наименование организации'),'')", null))));
         writer.WriteLine("#TYPEREE\t" + ((int) reeType).ToString());
         writer.WriteLine("#PROCESS\t" + ((int) processType).ToString());
         writer.Write("#RECORDS\t");
         writer.Flush();
         long num = writer.BaseStream.get_Position();
         writer.WriteLine("         ");
         if (writePeriod)
         {
             System.DateTime time = FromDate.AddDays((double) (-FromDate.get_Day() + 1));
             writer.WriteLine("#PERIODB\t" + time.ToString(@"dd\/MM\/yyyy"));
             writer.WriteLine("#PERIODE\t" + time.AddMonths(1).AddDays((double) -1.0).ToString(@"dd\/MM\/yyyy"));
         }
         writer.WriteLine(string.Concat((string[]) new string[] { "#NOTE\t\t", note, " (", System.DateTime.Now.ToString("dd.MM.yyyy HH:mm"), ")" }));
         int num2 = 0;
         System.Data.SqlClient.SqlParameter[] parameters = new System.Data.SqlClient.SqlParameter[2];
         parameters[0] = new System.Data.SqlClient.SqlParameter("@d_beg", System.Data.SqlDbType.DateTime);
         parameters[0].set_Value(FromDate);
         parameters[1] = new System.Data.SqlClient.SqlParameter("@d_end", System.Data.SqlDbType.DateTime);
         parameters[1].set_Value(ToDate.AddDays((double) 1.0).AddSeconds((double) -1.0));
         writer.WriteLine("#NOTE\t\tДата начала выборки: " + System.Convert.ToDateTime(parameters[0].get_Value()).ToString("dd.MM.yyyy HH:mm"));
         writer.WriteLine("#NOTE\t\tДата окончания выборки: " + System.Convert.ToDateTime(parameters[1].get_Value()).ToString("dd.MM.yyyy HH:mm"));
         foreach (System.Data.DataRow row in DALSql.ExecuteDataTable(sql, parameters).Rows)
         {
             writer.WriteLine(row.get_Item(0).ToString());
             num2 = (int) (num2 + 1);
         }
         writer.Flush();
         writer.BaseStream.Seek(num, System.IO.SeekOrigin.Begin);
         writer.Write(((int) num2).ToString("########0"));
         str = "Файл сформирован" + System.Environment.get_NewLine() + str2;
     }
     catch (System.Exception exception)
     {
         throw new System.ApplicationException("Произошла ошибка выгрузки", exception);
     }
     finally
     {
         if (writer != null)
         {
             writer.Close();
         }
     }
     throw new System.ApplicationException(str);
 }
Example #2
0
 public static int GetDiffInMonth(System.DateTime from, System.DateTime to)
 {
     return (int) ((((to.get_Year() - from.get_Year()) * 12) + (to.get_Month() - from.get_Month())) + ((from.get_Day() > to.get_Day()) ? -1 : 0));
 }