Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        public bool DeleteDocument()
        {
            var connection = new SqlConnection(connectionString);

            var            sql1 = string.Format("DELETE FROM {0} WHERE DocumentID = {1}", bodyTable, Head.DocumentNumber);
            var            sql2 = string.Format("DELETE FROM {0} WHERE DocumentID = {1}", headTable, Head.DocumentNumber);
            SqlTransaction tn   = null;;

            try
            {
                connection.Open();
                tn = connection.BeginTransaction();
                var cmd = new SqlCommand(sql2, connection, tn);
                cmd.ExecuteNonQuery();
                cmd.CommandText = sql1;
                cmd.ExecuteNonQuery();
                tn.Commit();
            }
            catch (Exception exc)
            {
                error = exc;
                tn.Rollback();
                return(false);
            }
            Head = new InputDocumentHead();
            DocumentBody.Clear();
            return(true);
        }
Esempio n. 4
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. 5
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);
        }
Esempio n. 6
0
 protected InputDocumentBase()
 {
     Head     = new InputDocumentHead();
     ReadOnly = true;
 }