Exemple #1
0
        private List <DocumentBatchInfo> GetBatchesInfo()
        {
            List <DocumentBatchInfo> list = new List <DocumentBatchInfo>();

            using (SqlConnection connection = new SqlConnection(Metadata.ConnectionString))
            {
                connection.Open();

                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandType    = CommandType.Text;
                    command.CommandText    = SelectPeriods_Script();
                    command.CommandTimeout = 60; // seconds

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DocumentBatchInfo item = new DocumentBatchInfo()
                            {
                                Period1 = new DateTime(
                                    reader.GetInt32(0),
                                    reader.GetInt32(1),
                                    reader.GetInt32(2),
                                    0, 0, 0),
                                TotalCount = reader.GetInt32(3)
                            };
                            item.Period2 = item.Period1.AddDays(1);
                            list.Add(item);
                        }
                        reader.Close();
                    }
                }
            }

            return(list);
        }
Exemple #2
0
        private void ExportBatch(DocumentBatchInfo batch, DataMapper mapper, MemoryStream stream, Utf8JsonWriter writer)
        {
            TablePart table = Document.TableParts.Where(t => t.Name == "Реализация").FirstOrDefault();

            if (table == null)
            {
                Console.WriteLine("Табличная часть \"Реализация\" не найдена.");
                return;
            }

            // InfoBase.ReferenceTypeCodes.TryGetValue()

            using (SqlConnection connection = new SqlConnection(GetMARSConnectionString()))
            {
                connection.Open();

                using (SqlCommand command1 = connection.CreateCommand())
                {
                    command1.CommandType = CommandType.Text;
                    //command1.CommandText = SelectDocuments_Script();
                    command1.CommandTimeout = 60; // seconds
                    mapper.ConfigureSelectCommand(command1);

                    //command1.Parameters.AddWithValue("Period1", batch.Period1);
                    //command1.Parameters.AddWithValue("Period2", batch.Period2);

                    using (SqlCommand command2 = connection.CreateCommand())
                    {
                        command2.CommandType    = CommandType.Text;
                        command2.CommandText    = SelectDocumentTablePart_Script(table);
                        command2.CommandTimeout = 600; // seconds

                        command2.Parameters.Add("Ref", SqlDbType.Binary, 16);

                        using (SqlDataReader reader1 = command1.ExecuteReader())
                        {
                            while (reader1.Read())
                            {
                                mapper.MapDataToJson(reader1, writer);
                                writer.Flush();

                                ReadOnlySpan <byte> span = new ReadOnlySpan <byte>(stream.GetBuffer(), 0, (int)writer.BytesCommitted);

                                writer.Reset();
                                stream.Position = 0;

                                Console.WriteLine(Encoding.UTF8.GetString(span));

                                //command2.Parameters["Ref"].Value = reader1["Ref"];

                                ////Console.WriteLine("Document = " + (new Guid(doc)).ToString());

                                //using (SqlDataReader reader2 = command2.ExecuteReader())
                                //{
                                //    while (reader2.Read())
                                //    {
                                //        for (int f = 0; f < reader2.FieldCount; f++)
                                //        {
                                //            Console.WriteLine(reader2.GetName(f) + " = " + reader2.GetValue(f).ToString());
                                //        }
                                //    }
                                //    reader2.Close();
                                //}
                            }
                            reader1.Close();
                        }
                    }
                }
            }
        }