Beispiel #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);
        }
Beispiel #2
0
        public static PlanDocument LoadDocument(int docnum, string headtable, string bodytable, string connection)
        {
            var result = new PlanDocument();

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

            var    sql     = new SqlConnection(connection);
            string sqlhead = @"SELECT DocumentID, FactoryID, DocTypeID, DocumentDate FROM " +
                             headtable + " WHERE  DocTypeID in (1, 3) AND DocumentHead.DocumentID = " + docnum.ToString();
            var cmd = new SqlCommand(sqlhead, sql);

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

                if (!reader.Read())
                {
                    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)
            {
                string msg = @"Ошибка загрузки документа. Не удалось найти документ
                            с заданным номером, или номер документа не соотвествет
                            типу документа.\n" + exception.Message;
                throw new Exception(msg, exception);
            }

            var sqlbody = @"SELECT DocumentID, DataHour, ProductID, DataValue1, DataValue2 FROM " +
                          bodytable + " WHERE DocumentID = " + docnum.ToString();
            SqlDataAdapter adapter = new SqlDataAdapter(sqlbody, sql);

            try
            {
                adapter.Fill(result.DocumentBody);
            }
            catch (Exception exception)
            {
                throw new Exception("Не удалось загрузить документ.\n" + exception.Message, exception);
                //return null; // Не удалось загрузить документ
            }
            result.SetBodySettings();

            return(result);
        }
Beispiel #3
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);
        }