Esempio n. 1
0
        public static PlanDocument CreateDocument(InputDocumentHead head, string headtable, string bodytable, string connection)
        {
            var result = new PlanDocument();

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

            result.DocumentBody.Columns.Add("DocumentID");
            result.DocumentBody.Columns["DocumentID"].DataType = Type.GetType("System.Int32");
            result.DocumentBody.Columns.Add("DataHour");
            result.DocumentBody.Columns["DataHour"].DataType = Type.GetType("System.Int32");
            result.DocumentBody.Columns.Add("ProductID");
            result.DocumentBody.Columns["ProductID"].DataType = Type.GetType("System.Int32");
            result.DocumentBody.Columns.Add("DataValue1");
            result.DocumentBody.Columns["DataValue1"].DataType = Type.GetType("System.Double");
            result.DocumentBody.Columns.Add("DataValue2");
            result.DocumentBody.Columns["DataValue2"].DataType = Type.GetType("System.Double");
            result.SetBodySettings();
            for (int i = 1; i <= 24; ++i)
            {
                DataRow row = result.DocumentBody.NewRow();
                row["DocumentID"] = result.Head.DocumentNumber;
                row["DataHour"]   = i;
                row["ProductID"]  = 0;
                row["DataValue1"] = 0;
                row["DataValue2"] = 0;
                result.DocumentBody.Rows.Add(row);
            }

            return(result.SaveDocument() ? result : null);
        }
Esempio n. 2
0
        public static PlanDocument CreateDocument(InputDocumentHead head, string headtable, string bodytable, string connection, int parent)
        {
            PlanDocument parentDocument;
            PlanDocument result;

            try
            {
                parentDocument = PlanDocument.LoadDocument(parent, headtable, bodytable, connection);
            }
            catch (Exception exception)
            {
                throw new Exception("Ошибка загрузки связанного документа.\n" + exception.Message, exception);
                //return null;
                // Ошибка загрузки связанного документа;
            }

            result                  = new PlanDocument();
            result.Head             = head;
            result.headTable        = headtable;
            result.bodyTable        = bodytable;
            result.connectionString = connection;

            result.DocumentBody.Columns.Add("DocumentID");
            result.DocumentBody.Columns["DocumentID"].DataType = Type.GetType("System.Int32");
            result.DocumentBody.Columns.Add("DataHour");
            result.DocumentBody.Columns["DataHour"].DataType = Type.GetType("System.Int32");
            result.DocumentBody.Columns.Add("ProductID");
            result.DocumentBody.Columns["ProductID"].DataType = Type.GetType("System.Int32");
            result.DocumentBody.Columns.Add("DataValue1");
            result.DocumentBody.Columns["DataValue1"].DataType = Type.GetType("System.Double");
            result.DocumentBody.Columns.Add("DataValue2");
            result.DocumentBody.Columns["DataValue2"].DataType = Type.GetType("System.Double");
            result.SetBodySettings();

            foreach (DataRow source in parentDocument.DocumentBody.Rows)
            {
                DataRow destenation = result.DocumentBody.NewRow();
                destenation["DocumentID"] = head.DocumentNumber;
                destenation["DataHour"]   = source["DataHour"];
                destenation["ProductID"]  = source["ProductID"];
                destenation["DataValue1"] = source["DataValue1"];
                destenation["DataValue2"] = source["DataValue2"];
                result.DocumentBody.Rows.Add(destenation);
            }
            if (!result.SaveDocument())
            {
                return(null);
            }
            return(result);
        }