Example #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            InputDocumentHead head = new InputDocumentHead();

            head.DocType      = (int)cmbDocType.SelectedValue;
            head.DocumentDate = dtpDate.Value;
            head.Factory      = (int)cmbFactory.SelectedValue;

            try
            {
                if (chkParent.Checked)
                {
                    switch (head.DocType)
                    {
                    case 1:
                    case 3:
                        Document = InputDocFactory.CreateDocument(head, Data, int.Parse(txtParent.Text));
                        break;

                    case 2:
                    case 4:
                        Document = InputDocFactory.CreateDocument(head, Data, int.Parse(txtParent.Text));
                        break;
                    }
                }
                else
                {
                    switch (head.DocType)
                    {
                    case 1:
                    case 3:
                        Document = InputDocFactory.CreateDocument(head, Data);
                        break;

                    case 2:
                    case 4:
                        Document = InputDocFactory.CreateDocument(head, Data);
                        break;
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorMsgBox.Show("Ошибка", "Ошибка создания документа.\n" + exception.Message, exception.ToString());
                return;
            }
            if (Document != null)
            {
                string message = "Документ № " + head.DocumentNumber.ToString() + " успешно создан.\nПерейти к редактированию?";
                if (MessageBox.Show(message, "Информация", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                {
                    this.DialogResult = DialogResult.Yes;
                }
            }
            else
            {
                ErrorMsgBox.Show("Ошибка", "Ошибка создания документа.", "Документ с таким номером уже существует.");
            }
            this.Close();
        }
Example #2
0
        public static IInputDocument CreateDocument(InputDocumentHead head, IGlobalValues data, int parent)
        {
            switch (head.DocType)
            {
            case 1:
            case 3:
                return(PlanDocument.CreateDocument(head, data.ActiveSchema + ".DocumentHead", data.ActiveSchema + ".DocumentBody", data.ConnectionString, parent));

            case 2:
            case 4:
                return(DeviceDocument.CreateDocument(head, data.ActiveSchema + ".DocumentHead", data.ActiveSchema + ".DocumentBody", data.ConnectionString, new List <int>(data.ProductGroups[DEVICES].Keys), parent));

            default:
                throw new Exception("Неверный тип документа.");
            }
        }
Example #3
0
        private bool KBK(DateTime date)
        {
            InputDocumentHead head = new InputDocumentHead();

            head.DocType      = PLAN;
            head.DocumentDate = date;
            head.Factory      = 4; //идентификатор КБК
            PlanDocument doc = null;

            var connection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

            //var rplist = new int[6] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
            var cmd = new SqlCommand();

            cmd = new SqlCommand(string.Format("Select dbo.FindPlan({0}, '{1}')", 4, date.ToString("yyyyMMdd")), connection);
            connection.Open();
            //проверка наличия плана производства
            int num = (int)cmd.ExecuteScalar();

            if (num > 0)
            {
                doc = PlanDocument.LoadDocument(num, GlobalValues.Instance.ActiveSchema + ".DocumentHead", GlobalValues.Instance.ActiveSchema + ".DocumentBody", GlobalValues.Instance.ConnectionString);
                doc.DeleteDocument();
                doc = null;
            }
            doc = PlanDocument.CreateDocument(head, GlobalValues.Instance.ActiveSchema + ".DocumentHead", GlobalValues.Instance.ActiveSchema + ".DocumentBody", GlobalValues.Instance.ConnectionString);
            doc.BeginEdit();
            doc.DocumentBody.Clear();

            //var lastdate = date.Subtract(new TimeSpan(4, 0, 0, 0));
            cmd.Connection = connection;
            for (int j = 1; j <= 8; ++j)
            {
                cmd.CommandText = "SELECT     fdb.DataHour as h, fdb.DataValue FROM dbo.vRP rp INNER JOIN " +
                                  " dbo.vForecastDocumentHead fdh ON rp.RPID = fdh.RPID INNER JOIN " +
                                  " dbo.vForecastDocumentBody fdb ON fdh.DocumentID = fdb.DocumentID" +
                                  " WHERE (fdh.DocumentDate = '" + date.ToString("yyyyMMdd") + "') " +
                                  " AND (fdh.DocTypeID = 2) AND " +
                                  " (rp.RPID = " + j.ToString() + ")";
                var adapter = new SqlDataAdapter(cmd);
                var data    = new DataTable();
                adapter.Fill(data);
                data.Columns["h"].DataType = typeof(int);
                DataColumn key = data.Columns["h"];
                data.PrimaryKey = new DataColumn[] { key };

                if (data.Rows.Count != 24)
                {
                    doc.EndEdit();
                    connection.Close();
                    ErrorMessage = string.Format("отсутствует одна из заявок на {0}", date.ToString("dd.MM.yyyy"));
                    doc.DeleteDocument();
                    return(false);
                }

                for (int i = 1; i <= 24; ++i)
                {
                    DataRow row = data.Rows.Find(i);
                    DataRow add = doc.DocumentBody.NewRow();
                    add["DocumentID"] = doc.Head.DocumentNumber;
                    add["ProductID"]  = j;
                    add["DataHour"]   = i;
                    add["DataValue1"] = row["DataValue"];
                    doc.DocumentBody.Rows.Add(add);
                }
            }
            doc.UpdateDocument();
            doc.EndEdit();

            connection.Close();

            cmd = new SqlCommand(string.Format("Select dbo.FindPlan({0}, '{1}')", 4, date.ToString("yyyyMMdd")), connection);
            connection.Open();
            bool result = true;

            //проверка наличия плана производства
            if ((int)cmd.ExecuteScalar() > 0)
            {
                //загруска плана производства в таблицу TempPlan
                SqlCommand plan = new SqlCommand(string.Format("exec dbo.LoadPlan {0},'{1}'", 4, date.ToString("yyyyMMdd")), connection);
                plan.ExecuteNonQuery();
                connection.Close();
                //запуск скрипта дедуктора
                Process prc    = null;
                string  output = string.Empty;

                try
                {
                    // Устанавливаем параметры запуска процесса
                    prc = new Process();
                    prc.StartInfo.FileName  = ConfigurationManager.AppSettings["DeductorString"];
                    prc.StartInfo.Arguments = Scripts[4] + " /run";

                    // Старт
                    prc.Start();

                    // Ждем пока процесс не завершится
                    prc.WaitForExit();
                    if (prc.ExitCode == -1)
                    {
                        result       = false;
                        ErrorMessage = "Ошибка серваера прогнозирования.";
                    }
                }
                finally
                {
                    if (prc != null)
                    {
                        prc.Close();
                    }
                }
            }
            else
            {
                ErrorMessage = string.Format("отсутствует план производства на {0}", date);
                result       = false;
            }
            return(result);
        }
Example #4
0
        private bool OtherFactory(DateTime date)
        {
            InputDocumentHead head = new InputDocumentHead();

            head.DocType      = PLAN;
            head.DocumentDate = date;
            head.Factory      = 3; // остальные потребители
            PlanDocument doc = null;

            var connection = new SqlConnection(GlobalValues.Instance.ConnectionString);

            var rplist = new int[6] {
                0, 4, 5, 6, 7, 8
            };
            var cmd = new SqlCommand();

            cmd = new SqlCommand(string.Format("Select dbo.FindPlan({0}, '{1}')", 3, date.ToString("yyyyMMdd")), connection);
            connection.Open();
            bool result = true;
            //проверка наличия плана производства
            int num = (int)cmd.ExecuteScalar();

            if (num > 0)
            {
                doc = PlanDocument.LoadDocument(num, GlobalValues.Instance.ActiveSchema + ".DocumentHead", GlobalValues.Instance.ActiveSchema + ".DocumentBody", GlobalValues.Instance.ConnectionString);
                doc.DeleteDocument();
                doc = null;
            }

            doc = PlanDocument.CreateDocument(head, GlobalValues.Instance.ActiveSchema + ".DocumentHead", GlobalValues.Instance.ActiveSchema + ".DocumentBody", GlobalValues.Instance.ConnectionString);
            doc.BeginEdit();
            doc.DocumentBody.Clear();

            var lastdate = date.Subtract(new TimeSpan(4, 0, 0, 0));

            cmd.Connection = connection;
            for (int j = 1; j <= 5; ++j)
            {
                cmd.CommandText = "Select DATEPART(hour, e.DataDate) as h, e.DataValue FROM dbo.Energy e WHERE e.RPID = " + rplist[j].ToString() +
                                  " AND ((CONVERT(char(8), e.DataDate, 112) = '" + lastdate.ToString("yyyyMMdd") + "' AND DATEPART(hour, e.DataDate) <> 0) OR " +
                                  "(CONVERT(char(8), e.DataDate, 112) = '" + lastdate.AddDays(1).ToString("yyyyMMdd") + "' AND DATEPART(hour, e.DataDate) = 0))";
                var adapter = new SqlDataAdapter(cmd);
                var data    = new DataTable();
                adapter.Fill(data);
                data.Columns["h"].DataType = typeof(int);
                DataColumn key = data.Columns["h"];
                data.PrimaryKey = new DataColumn[] { key };

                for (int i = 1; i <= 24; ++i)
                {
                    DataRow row = data.Rows.Find(i % 24);
                    DataRow add = doc.DocumentBody.NewRow();
                    add["DocumentID"] = doc.Head.DocumentNumber;
                    add["ProductID"]  = j;
                    add["DataHour"]   = i;
                    add["DataValue1"] = row["DataValue"];
                    doc.DocumentBody.Rows.Add(add);
                }
            }
            doc.UpdateDocument();
            doc.EndEdit();

            connection.Close();

            cmd = new SqlCommand(string.Format("Select dbo.FindPlan({0}, '{1}')", 3, date.ToString("yyyyMMdd")), connection);
            connection.Open();
            //проверка наличия плана производства
            if ((int)cmd.ExecuteScalar() > 0)
            {
                //загруска плана производства в таблицу TempPlan
                SqlCommand plan = new SqlCommand(string.Format("exec dbo.LoadPlan {0},'{1}'", 3, date.ToString("yyyyMMdd")), connection);
                plan.ExecuteNonQuery();
                //запуск скрипта дедуктора
                Process prc    = null;
                string  output = string.Empty;

                try
                {
                    // Устанавливаем параметры запуска процесса
                    prc = new Process();
                    prc.StartInfo.FileName  = ConfigurationManager.AppSettings["DeductorString"];
                    prc.StartInfo.Arguments = Scripts[3] + " /run";

                    // Старт
                    prc.Start();

                    // Ждем пока процесс не завершится
                    prc.WaitForExit();
                    if (prc.ExitCode == -1)
                    {
                        result       = false;
                        ErrorMessage = "Ошибка серваера прогнозирования.";
                    }
                }
                finally
                {
                    if (prc != null)
                    {
                        prc.Close();
                    }
                }
            }
            else
            {
                ErrorMessage = string.Format("отсутствует план производства на {0}", date.ToString("dd.MM.yyyy"));
                result       = false;
            }
            return(result);
        }