private void btnCreate_Click(object sender, EventArgs e) { docHead.DocType = TENDER; //Заявка docHead.DocumentDate = dtpDateDoc.Value; if (chkParentDocument.Checked) { docHead.DocumentParent = int.Parse(txtParentDocNum.Text); } docHead.RPInfo = (int)cmbRP.SelectedValue; if (docHead.DocumentNumber == 0) { MessageBox.Show("Возникла ошибка при создании документа.\nНеверный номер документа.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { IForecastDocument document = ForecastDocumentFactory.CreateDocument(docHead, Data); if (document == null) { throw new Exception(); } Doc = document as ForecastDocument; string message = "Документ № " + document.Head.DocumentNumber.ToString() + " успешно создан.\nПерейти к редактированию?"; if (MessageBox.Show(message, "Информация", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { this.DialogResult = DialogResult.Yes; } } catch (Exception exception) { ErrorMsgBox.Show("Ошибка", "Возникла ошибка при создании документа.\n" + exception.Message, exception.ToString()); } this.Dispose(); }
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(); }
private void btnEditPlan_Click(object sender, EventArgs e) { if (gridPlanDocuments.SelectedRows.Count > 0) { try { IInputDocument doc = InputDocFactory.LoadDocument((int)gridPlanDocuments.SelectedRows[0].Cells["DocumentID"].Value, GlobalValues.Instance); FormInputDoc edit = new FormInputDoc(doc, GlobalValues.Instance); edit.Show(); edit.Activate(); } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка редактирования документа\r\n" + exc.Message, exc.ToString()); return; } } }
private void btnEdit_Click(object sender, EventArgs e) { if (gridForecastDocuments.SelectedRows.Count > 0) { try { int docid = (int)gridForecastDocuments.SelectedRows[0].Cells["DocumentID"].Value; ForecastDocument document = ForecastDocumentFactory.LoadDocument(docid, GlobalValues.Instance); FormTender edit = new FormTender(document, GlobalValues.Instance); edit.Show(); } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка редактирования документа\r\n" + exc.Message, exc.ToString()); return; } } }
private void btnCreatePlan_Click(object sender, EventArgs e) { try { CreateInputDoc create = new CreateInputDoc(GlobalValues.Instance); create.ShowDialog(); if (create.DialogResult == DialogResult.Yes) { FormInputDoc edit = new FormInputDoc(create.Document, GlobalValues.Instance); edit.Show(); edit.Activate(); } } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка создания документа\r\n" + exc.Message, exc.ToString()); return; } }
private void MainFrame_Load(object sender, EventArgs e) { if (!GlobalValues.Instance.InitUser(ConfigurationManager.AppSettings["ConnectionString"])) { ErrorMsgBox.Show("Ошибка", "Ошибка инициализации пользователя.\n" + GlobalValues.Instance.exception.Message, GlobalValues.Instance.exception.ToString()); this.Close(); } if (!GlobalValues.Instance.InitData()) { ErrorMsgBox.Show("Ошибка", "Ошибка инициализации настроек.\n" + GlobalValues.Instance.exception.Message, GlobalValues.Instance.exception.ToString()); this.Close(); } //GlobalData.Instance.InitData(); if (GlobalValues.Instance.RoleTable.Rows.Count == 1) { cmbRole.Visible = false; } else { cmbRole.DataSource = GlobalValues.Instance.RoleTable; cmbRole.DisplayMember = "RoleName"; cmbRole.ValueMember = "RoleID"; cmbRole.SelectedValue = GlobalValues.Instance.ActiveRole; } if (GlobalValues.Instance.ActiveRole.Contains("energy")) { cmbFactory.DataSource = null; cmbFactory.DataSource = new BindingSource(GlobalValues.Instance.FactoryList, null); cmbFactory.DisplayMember = "Value"; cmbFactory.ValueMember = "Key"; cmbFactory.SelectedIndex = 0; cmbFactory.Enabled = cmbFactory.Items.Count != 1; } dtpEnd.Value = DateTime.Now.AddDays(3); dtpStart.Value = DateTime.Now.Subtract(new TimeSpan(3, 0, 0, 0)); ChangeRole(); contextDocType.Closing += new ToolStripDropDownClosingEventHandler(contextDocType_Closing); contextForecastType.Closing += new ToolStripDropDownClosingEventHandler(contextDocType_Closing); btnSearch_Click(null, null); }
private void toolCreateTender_Click(object sender, EventArgs e) { if (gridForecastDocuments.SelectedRows.Count > 0) { try { int documentNumber = (int)gridForecastDocuments.SelectedRows[0].Cells["DocumentID"].Value; CreateTender tender = new CreateTender(GlobalValues.Instance, documentNumber); tender.Show(); } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка создания заявки\r\n" + exc.Message, exc.ToString()); return; } } else { MessageBox.Show("Документа не выбран."); } }
private void btnDeleteTender_Click(object sender, EventArgs e) { if (gridForecastDocuments.SelectedRows.Count > 0) { try { int docid = (int)gridForecastDocuments.SelectedRows[0].Cells["DocumentID"].Value; ForecastDocument document = ForecastDocumentFactory.LoadDocument(docid, GlobalValues.Instance); if (MessageBox.Show("Вы хотите удалить документ № " + docid.ToString(), "Предупреждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (document.DeleteDocument()) { MessageBox.Show("Документ № " + docid.ToString() + " удалён."); } } } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка удаления документа\r\n" + exc.Message, exc.ToString()); return; } } }
public static void Show(string caption, string message, string info) { ErrorMsgBox box = new ErrorMsgBox(caption, message, info); box.ShowDialog(); }
private void btnSearch_Click(object sender, EventArgs e) { string role = GlobalValues.Instance.ActiveRole; string doctypes = string.Empty; if (tabControl.TabPages.Contains(tabForecast)) // отображение прогнозов и заявок { doctypes = string.Empty; foreach (ToolStripMenuItem item in contextForecastType.Items) { if (item.Checked) { doctypes += (doctypes == string.Empty ? "" : ",") + item.Tag.ToString(); } } try { var data = DocumentSelector.SelectForecastDocuments(GlobalValues.Instance, dtpStart.Value, dtpEnd.Value, doctypes); gridForecastDocuments.DataSource = data; gridForecastDocuments.Columns["DocumentID"].HeaderText = "№ Документа"; gridForecastDocuments.Columns["DocumentDate"].HeaderText = "Дата"; gridForecastDocuments.Columns["RPName"].HeaderText = "РП"; gridForecastDocuments.Columns["FactoryName"].HeaderText = "Фабрика"; gridForecastDocuments.Columns["ParentDocument"].HeaderText = "Связанный документ"; gridForecastDocuments.Columns["DocTypeName"].HeaderText = "Тип документа"; gridForecastDocuments.Columns["DocTypeID"].Visible = false; gridForecastDocuments.Columns["RPID"].Visible = false; gridForecastDocuments.Columns["FactoryID"].Visible = false; } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка запроса заявок(прогнозов)\r\n" + exc.Message, exc.ToString()); } } if (tabControl.TabPages.Contains(tabPlan)) // отображение плнов произвостваи графиков работы оборудования { doctypes = string.Empty; foreach (ToolStripMenuItem item in contextDocType.Items) { if (item.Checked) { doctypes += (doctypes == string.Empty ? "" : ",") + item.Tag.ToString(); } } try { var data = DocumentSelector.SelectInputDocuments(GlobalValues.Instance, dtpStart.Value, dtpEnd.Value, doctypes); gridPlanDocuments.DataSource = data; gridPlanDocuments.Columns["DocumentID"].HeaderText = "№ Документа"; gridPlanDocuments.Columns["DocumentDate"].HeaderText = "Дата"; gridPlanDocuments.Columns["FactoryName"].HeaderText = "Фабрика"; gridPlanDocuments.Columns["DocTypeName"].HeaderText = "Тип документа"; gridPlanDocuments.Columns["DocTypeID"].Visible = false; gridPlanDocuments.Columns["FactoryID"].Visible = false; } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка запроса планов производства(графиков работы оборудования)\r\n" + exc.Message, exc.ToString()); } } if (tabControl.TabPages.Contains(tabViewForecast)) // просмотр заявок(прогнозов) { doctypes = string.Empty; foreach (ToolStripMenuItem item in contextForecastType.Items) { if (item.Checked) { doctypes += (doctypes == string.Empty ? "" : ",") + item.Tag.ToString(); } } try { var data = DocumentSelector.SelectAllForecastDocuments(GlobalValues.Instance, dtpStart.Value, dtpEnd.Value, doctypes); gridForecastView.DataSource = data; gridForecastView.Columns["DocumentID"].HeaderText = "№ Документа"; gridForecastView.Columns["DocumentDate"].HeaderText = "Дата"; gridForecastView.Columns["RPName"].HeaderText = "РП"; gridForecastView.Columns["FactoryName"].HeaderText = "Фабрика"; gridForecastView.Columns["ParentDocument"].HeaderText = "Связанный документ"; gridForecastView.Columns["DocTypeName"].HeaderText = "Тип документа"; gridForecastView.Columns["DocTypeID"].Visible = false; gridForecastView.Columns["RPID"].Visible = false; gridForecastView.Columns["FactoryID"].Visible = false; } catch (Exception exc) { ErrorMsgBox.Show("Ошибка", "Ошибка запроса заявок(прогнозов)\r\n" + exc.Message, exc.ToString()); } } //if (tabControl.TabPages.Contains(tabLog)) // просмотр журнала событий //{ // try // { // var data = new DataTable(); // var query = "SELECT * FROM dbo.DocsHistory WHERE adate >= '" + dtpStart.Value.ToString("yyyyMMdd") + "' AND adate <= '" + dtpEnd.Value.ToString("yyyyMMdd") + "'"; // var sql = new SqlConnection(GlobalValues.Instance.ConnectionString); // var adapter = new SqlDataAdapter(query, sql); // adapter.Fill(data); // gridLog.DataSource = data; // gridLog.Columns["cmd"].HeaderText = "Команда"; // gridLog.Columns["actiontable"].HeaderText = "Тип документа"; // gridLog.Columns["adate"].HeaderText = "Дата"; // gridLog.Columns["docid"].HeaderText = "№ Документа"; // gridLog.Columns["username"].HeaderText = "Пользователь"; // } // catch (Exception exc) // { // ErrorMsgBox.Show("Ошибка", "Ошибка запроса \"Журнала событий\"\r\n" + exc.Message, exc.ToString()); // } //} }