예제 #1
0
        public static DeviceDocument CreateDocument(InputDocumentHead head, string headtable, string bodytable, string connection, List <int> devicelist, int parent)
        {
            DeviceDocument parentDocument;
            DeviceDocument result = new DeviceDocument();

            result.Head             = head;
            result.headTable        = headtable;
            result.bodyTable        = bodytable;
            result.connectionString = connection;
            result.deviceList       = devicelist;
            result.SetBodySettings();
            try
            {
                parentDocument = DeviceDocument.LoadDocument(parent, headtable, bodytable, connection, devicelist);
            }
            catch (Exception exception)
            {
                //return null;
                throw new Exception("Ошибка загрузки связанного документа.", exception);
            }
            result.DocumentBody.Load(parentDocument.DocumentBody.CreateDataReader(), LoadOption.OverwriteChanges);
            if (!result.SaveDocument())
            {
                return(null);
            }
            return(result);
        }
예제 #2
0
        public static DeviceDocument CreateDocument(InputDocumentHead head, string headtable, string bodytable, string connection, List <int> devicelist)
        {
            var result = new DeviceDocument();

            result.Head             = head;
            result.headTable        = headtable;
            result.bodyTable        = bodytable;
            result.connectionString = connection;
            result.deviceList       = devicelist;

            result.SetBodySettings();

            for (int i = 1; i <= 24; ++i)
            {
                DataRow row = result.DocumentBody.NewRow();
                row["DataHour"] = i;
                foreach (var device in devicelist)
                {
                    row[device.ToString()] = true;
                }
                result.DocumentBody.Rows.Add(row);
            }
            result.SaveDocument();
            return(result);
        }
예제 #3
0
        public static DeviceDocument LoadDocument(int docnum, string headtable, string bodytable, string connection, List <int> devicelist)
        {
            var result = new DeviceDocument();

            result.headTable        = headtable;
            result.bodyTable        = bodytable;
            result.deviceList       = devicelist;
            result.connectionString = connection;
            var    sql     = new SqlConnection(connection);
            string sqlhead = @"SELECT dh.DocumentID, dh.FactoryID, dh.DocTypeID, dh.DocumentDate " +
                             "FROM " + headtable + @" dh WHERE  DocTypeID in (2, 4) AND dh.DocumentID = " + docnum.ToString();
            SqlCommand cmd = new SqlCommand(sqlhead, sql);

            try
            {
                sql.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                if (!reader.Read())
                {
                    throw new Exception("Не удалось найти документ  с заданным номером, или номер документа не соотвествет типу документа.");
                    //return null;
                    //Не удалось найти документ  с заданным номером, или номер документа не соотвествет типу документа.
                }
                ;
                result.Head.Factory      = reader.GetInt32(1);
                result.Head.DocType      = reader.GetInt32(2);
                result.Head.DocumentDate = reader.GetDateTime(3);
                sql.Close();
            }
            catch (Exception exception)
            {
                throw exception;
            }
            var sqlbody = @"SELECT DocumentID, DataHour, ProductID, DataValue1 FROM " +
                          bodytable + " WHERE DocumentID = " + docnum.ToString();
            SqlDataAdapter adapter = new SqlDataAdapter(sqlbody, sql);
            var            temp    = new DataTable();

            try
            {
                adapter.Fill(temp);
            }
            catch (Exception exception)
            {
                //return null;
                throw new Exception("Не удалось считать данные документа.", exception);
            }
            DataColumn key1 = temp.Columns["DataHour"];
            DataColumn key2 = temp.Columns["ProductID"];

            temp.PrimaryKey = new DataColumn[] { key1, key2 };

            result.SetBodySettings();
            for (int i = 1; i <= 24; ++i)
            {
                DataRow row = result.DocumentBody.NewRow();
                row["DataHour"] = i;
                foreach (var device in devicelist)
                {
                    if (temp.Rows.Contains(new object[] { i, device }))
                    {
                        DataRow info = temp.Rows.Find(new object[] { i, device });
                        row[device.ToString()] = (double)info["DataValue1"] != 0.0;
                    }
                    else
                    {
                        row[device.ToString()] = 0;
                    }
                }
                result.DocumentBody.Rows.Add(row);
            }
            return(result);
        }