private void toolStripButton22_Click(object sender, EventArgs e) { if (workStageStaffBindingSource.Count == 0) { return; } dbDataSet.WorkStageStaffRow employee = (workStageStaffBindingSource.Current as DataRowView).Row as dbDataSet.WorkStageStaffRow; OpenEditEmployeeForm(employee.EmployeeId); }
private void toolStripButton21_Click(object sender, EventArgs e) { if (workStageStaffBindingSource.Count == 0) { return; } DialogResult res = MessageBox.Show("Вы уверены?\nОтменить данное действие будет невозможно!", "Подтвердите удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res != DialogResult.Yes) { return; } int pos = workStageStaffBindingSource.Position; dbDataSet.WorkStageStaffRow data = (workStageStaffBindingSource.Current as DataRowView).Row as dbDataSet.WorkStageStaffRow; workStageStaffTableAdapter.Delete(data.StageId, data.EmployeeId); workStageStaffTableAdapter.Fill(dbDataSet.WorkStageStaff); workStageStaffBindingSource.Position = pos; }
private void EditEmployeeForm_Load(object sender, EventArgs e) { if (Id > 0) { Employee = workStageStaffTableAdapter.GetDataByKey(StageId, Id).FirstOrDefault(); if (Employee == null) { MessageBox.Show("Запись не найдена!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Abort; return; } Data.selectedEmployee = staffTableAdapter.GetDataById(Employee.EmployeeId).FirstOrDefault(); fullNameInput.Text = Employee.EmployeeName; labelPosition.Text = Employee.IsEmployeePositionNull() ? "-" : Employee.EmployeePosition; daysInput.Value = Employee.LaborExpenditures; rateInput.Value = Employee.Rate; } else { Data.selectedEmployee = null; } }
private void PrintSheduleOfWork() { saveFileDialog.FileName = "План-график работ"; DialogResult res = saveFileDialog.ShowDialog(); if (res == DialogResult.OK) { dbDataSet.OrdersRow order = (ordersBindingSource.Current as DataRowView).Row as dbDataSet.OrdersRow; dbDataSet.OrganizationInfoRow org = (organizationInfoBindingSource.Current as DataRowView).Row as dbDataSet.OrganizationInfoRow; dbDataSet.ClientsRow client = clientsTableAdapter.GetDataById(order.ClientId).FirstOrDefault(); DataRowView[] stagesDataList = new DataRowView[worksStagesBindingSource.List.Count]; worksStagesBindingSource.List.CopyTo(stagesDataList, 0); List <dbDataSet.WorksStagesRow> stages = new List <dbDataSet.WorksStagesRow>(); foreach (DataRowView i in stagesDataList) { stages.Add(i.Row as dbDataSet.WorksStagesRow); } int stagesCount = stages.Aggregate(0, (acc, i) => i.Number.Contains(".") ? acc : acc + 1); Dictionary <string, decimal> stagesCosts = new Dictionary <string, decimal>(); for (int i = 1; i <= stagesCount; ++i) { stagesCosts.Add(i.ToString(), 0); } dbDataSet.WorksStagesCostsDataTable worksStagesCostsDataTable = worksStagesCostsTableAdapter.GetData(order.Id); decimal stagesTotalCost = 0; foreach (dbDataSet.WorksStagesCostsRow item in worksStagesCostsDataTable.Rows) { string stageN = item.Number.Split('.').First(); stagesCosts[stageN] += item.TotalSum; stagesTotalCost += item.TotalSum; } string path = saveFileDialog.FileName; try { File.WriteAllBytes(path, Resources.SheduleOfWork); } catch { MessageBox.Show("Не выполнено!\nВыбранный файл занят другим процессом!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Word.Application app = new Word.Application(); Word.Document doc = app.Documents.Open(path); Word.Bookmarks bs = doc.Bookmarks; Dictionary <string, string> values = new Dictionary <string, string> { { "DocN", order.Id.ToString() }, { "Day", order.AdmissionDate.Day.ToString() }, { "Month", order.AdmissionDate.Month.ToString() }, { "Year", order.AdmissionDate.Year.ToString() }, { "ProgName", order.Name }, { "OrgName", org.Name }, { "OrgDelegate", GetShortName(org.Delegate) }, { "ClientName", client.Name }, { "ClientDelegate", client.IsDelegateNull() ? "": GetShortName(client.Delegate) }, }; foreach (KeyValuePair <string, string> pair in values) { try { bs[pair.Key].Range.Text = pair.Value; } catch { } } Word.Table tbl = doc.Tables[2]; Word.Row tplRow = tbl.Rows[2]; List <Word.Range> rls = new List <Word.Range>(); int pos = worksStagesBindingSource.Position; worksStagesBindingSource.MoveFirst(); workStageStaffBindingSource.MoveFirst(); for (int i = 0; i < worksStagesBindingSource.Count; ++i) { dbDataSet.WorksStagesRow stage = (worksStagesBindingSource.Current as DataRowView).Row as dbDataSet.WorksStagesRow; Word.Row row = tbl.Rows.Add(tplRow); row.Cells[1].Range.Text = stage.Number; row.Cells[2].Range.Text = stage.Name; row.Cells[4].Range.Text = stage.StartDate.ToShortDateString(); row.Cells[5].Range.Text = stage.FinishDate.ToShortDateString(); Word.Row rowEmp = null; decimal totalCost = 0; workStageStaffBindingSource.MoveFirst(); foreach (DataRowView empRow in workStageStaffBindingSource.List) { dbDataSet.WorkStageStaffRow emp = empRow.Row as dbDataSet.WorkStageStaffRow; if (emp.IsEmployeeNameNull()) { continue; } string posPrefix = emp.IsEmployeePositionNull() ? "" : $"{emp.EmployeePosition} "; decimal cost = emp.LaborExpenditures * 8 * emp.Rate; totalCost += cost; rowEmp = tbl.Rows.Add(tplRow); rowEmp.Cells[3].Range.Text = posPrefix + GetShortName(emp.EmployeeName); rowEmp.Cells[6].Range.Text = emp.LaborExpenditures.ToString(); rowEmp.Cells[7].Range.Text = emp.Rate.ToString(); rowEmp.Cells[8].Range.Text = cost.ToString(); } row.Cells[9].Range.Text = totalCost.ToString(); if (rowEmp != null) { rls.Add(doc.Range(row.Cells[9].Range.Start, rowEmp.Cells[9].Range.End)); } worksStagesBindingSource.MoveNext(); } tbl.Columns.AutoFit(); worksStagesBindingSource.Position = pos; doc.Range(tplRow.Cells[1].Range.Start, tplRow.Cells[5].Range.End).Cells.Merge(); doc.Range(tplRow.Cells[2].Range.Start, tplRow.Cells[5].Range.End).Cells.Merge(); tplRow.Cells[1].Range.Text = "ИТОГО"; tplRow.Range.Font.Bold = 1; tplRow.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight; tplRow.Cells[2].Range.Text = stagesTotalCost.ToString(); foreach (Word.Range r in rls) { r.Cells.Merge(); } doc.Save(); app.Visible = true; } }