示例#1
0
        private void buttonSaveOrgInfo_Click(object sender, EventArgs e)
        {
            string[] requiredValues =
            {
                nameOrgTextBox.Text,
                addressOrgTextBox.Text,
                phonesOrgTextBox.Text,
                innOrgTextBox.Text,
                kppOrgTextBox.Text,
                ogrnOrgTextBox.Text,
                bankAccountOrgTextBox.Text,
                bankOrgNameTextBox.Text,
                rcbicOrgTextBox.Text,
                corrAccOrgTextBox.Text,
                delegateOrgTextBox.Text,
            };
            bool exitEmptyField = requiredValues.Any(s => String.IsNullOrEmpty(s.Trim()));

            if (exitEmptyField)
            {
                MessageBox.Show("Не выполнено!\nВсе поля со звездочкой обязательны к заполнению!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            organizationInfoBindingSource.EndEdit();
            tableAdapterManager.UpdateAll(dbDataSet);
            dbDataSet.OrganizationInfoRow organization = (organizationInfoBindingSource.Current as DataRowView).Row as dbDataSet.OrganizationInfoRow;
            organizationInfoTableAdapter.Update(organization);
        }
示例#2
0
        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;
            }
        }
示例#3
0
        private void PrintSertificateAccept()
        {
            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.SertificateAccept);
                }
                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>
                {
                    { "DocN1", order.Id.ToString() },
                    { "DocN2", order.Id.ToString() },
                    { "AdmissionDay1", order.AdmissionDate.Day.ToString() },
                    { "AdmissionMonth1", order.AdmissionDate.Month.ToString() },
                    { "AdmissionYear1", order.AdmissionDate.Year.ToString() },
                    { "AdmissionDay2", order.AdmissionDate.Day.ToString() },
                    { "AdmissionMonth2", order.AdmissionDate.Month.ToString() },
                    { "AdmissionYear2", order.AdmissionDate.Year.ToString() },
                    { "DeliveryDay1", order.DeliveryDate.Day.ToString() },
                    { "DeliveryMonth1", order.DeliveryDate.Month.ToString() },
                    { "DeliveryYear1", order.DeliveryDate.Year.ToString() },


                    { "ProgName", order.Name },
                    { "ProgName2", order.Name },

                    { "OrgName1", org.Name },
                    { "OrgName2", org.Name },
                    { "OrgDelegate", GetShortName(org.Delegate) },

                    { "ClientName1", client.Name },
                    { "ClientName2", client.Name },
                    { "ClientDelegate", client.IsDelegateNull() ? "": GetShortName(client.Delegate) },

                    { "TotalCost", stagesTotalCost.ToString() },
                    { "TotalCost1", stagesTotalCost.ToString() },
                };

                //if (!client.IsPassportNull())
                //{
                //    values.Add("Fiz", "");
                //}


                foreach (KeyValuePair <string, string> pair in values)
                {
                    try
                    {
                        bs[pair.Key].Range.Text = pair.Value;
                    }
                    catch { }
                }


                Word.Table tbl = doc.Tables[3];
                for (int i = 1; i < stagesCount; ++i)
                {
                    tbl.Rows.Add(tbl.Rows[2]);
                }

                int row = 2;

                foreach (KeyValuePair <string, decimal> i in stagesCosts)
                {
                    tbl.Rows[row].Cells[1].Range.Text = i.Key;
                    tbl.Rows[row].Cells[2].Range.Text = stages.Find(x => x.Number == i.Key).Name;
                    tbl.Rows[row].Cells[3].Range.Text = i.Value.ToString();

                    ++row;
                }


                doc.Save();
                app.Visible = true;
            }
        }
示例#4
0
        private void PrintContract()
        {
            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.Contract);
                }
                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>
                {
                    { "Number", order.Id.ToString() },
                    { "DateDay", order.AdmissionDate.Day.ToString() },
                    { "DateMonth", order.AdmissionDate.Month.ToString() },
                    { "DateYear", order.AdmissionDate.Year.ToString() },

                    { "ProgName1", order.Name },
                    { "ProgName2", order.Name },
                    { "ProgName3", order.Name },

                    { "OrgName", org.Name },
                    { "OrgName1", org.Name },
                    { "OrgName2", org.Name },
                    { "OrgOGRN", org.OGRN },
                    { "OrgINN", org.INN },
                    { "OrgKPP", org.KPP },
                    { "OrgAddress", org.Address },
                    { "OrgBank", $"{org.BankName}, {org.BankAccount}" },
                    { "OrgDelegate", org.Delegate },
                    { "OrgDelegate1", GetShortName(org.Delegate) },

                    { "ClientAddress", client.Address },
                    { "ClientBank", $"{client.BankName}, {client.BankAccount}" },
                    { "ClientDelegate", client.IsDelegateNull() ? "" : client.Delegate },
                    { "ClientDelegate1", client.IsDelegateNull() ? "": GetShortName(client.Delegate) },
                    { "ClientINN", client.INN },
                    { "ClientKPP", client.KPP },
                    { "ClientName", client.Name },
                    { "ClientName1", client.Name },
                    { "ClientName2", client.Name },
                    { "ClientOGRN", client.IsOGRNNull() ? "" : client.OGRN },

                    { "StagesCount", stagesCount.ToString() },
                    { "StagesCount1", stagesCount.ToString() },

                    { "StagesTotalCost", stagesTotalCost.ToString() },
                };

                if (!client.IsPassportNull())
                {
                    values.Add("Fiz", "");
                }


                foreach (KeyValuePair <string, string> pair in values)
                {
                    try
                    {
                        bs[pair.Key].Range.Text = pair.Value;
                    }
                    catch { }
                }

                List <string> stagesCostsText       = new List <string>();
                List <string> stagesCostsSecondText = new List <string>();

                foreach (KeyValuePair <string, decimal> i in stagesCosts)
                {
                    stagesCostsText.Add($"стоимость {i.Key}-го этапа работ по Разработке Системы в размере {i.Value} рублей;");
                    stagesCostsSecondText.Add($"Аванс 50% от стоимости работ по Разработке Системы по этапу №{i.Key} выплачивается в течении 5 (пяти) рабочих дней после начала работ по этому этапу в соответствии со сроками начала работ, указанными в Приложении № 2 в размере {i.Value / 2} рублей;");
                    stagesCostsSecondText.Add($"В течение 5 (пяти) рабочих дней после подписания обеими Сторонами Акта сдачи-приемки {i.Key}-го этапа работ по Разработке Системы (Приложение № 3) Заказчик выплачивает Исполнителю сумму в размере {i.Value / 2} рублей;");
                }

                try
                {
                    bs["CostsStages"].Range.Text  = String.Join("\n", stagesCostsText);
                    bs["CostsStages2"].Range.Text = String.Join("\n", stagesCostsSecondText);
                }
                catch { }

                doc.Save();
                app.Visible = true;
            }
        }