示例#1
0
        private void BtnAddBriefcase_Click(object sender, EventArgs e)
        {
            int idProject = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Id").ToString());

            ViewForms.SelectBriefcaseWindow selectItem = new ViewForms.SelectBriefcaseWindow();
            selectItem.Owner = this;
            if (selectItem.ShowDialog() == DialogResult.OK)
            {
                List <int> id = selectItem.SelectedBriefcaseID;
                // Добавляем портфели к проекту.
                foreach (int oneID in id)
                {
                    List <Model.AddFittingModel> models = new List <AddFittingModel>();
                    DataTable dt = new SqlMethods().LoadProjects(String.Format("select IDFitting, FittingCount from BriefcaseAccessories where IDBriefcase={0}", oneID));
                    foreach (DataRow row in dt.Rows)
                    {
                        models.Add(new AddFittingModel()
                        {
                            IdProject    = idProject,
                            IdFitting    = int.Parse(row["IDFitting"].ToString()),
                            FittingCount = double.Parse(row["FittingCount"].ToString())
                        });
                    }

                    foreach (Model.AddFittingModel model in models)
                    {
                        AddFittingToProject(model.IdProject, model.IdFitting, model.FittingCount);
                    }
                }

                LoadFittings(idProject);

                // Обновляем строку с проектом.
                DataTable dt1 = new SqlMethods().LoadProjects(String.Format("exec ShowTheOneProjects {0}", idProject));
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "FittingSum", dt1.Rows[0]["FittingSum"]);
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TransportSum", dt1.Rows[0]["TransportSum"]);
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LaborIntencity", dt1.Rows[0]["LaborIntencity"]);
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "UnexpectedExpenses", dt1.Rows[0]["UnexpectedExpenses"]);
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TotalSum", dt1.Rows[0]["TotalSum"]);
                gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TotalSumWithPercent2", dt1.Rows[0]["TotalSumWithPercent2"]);
            }
        }
示例#2
0
        /// <summary>
        /// Добавление проекта.
        /// </summary>
        private void AddProject()
        {
            ProjectCard projectCard = new ProjectCard();

            projectCard.Owner = this;
            projectCard.ShowDialog();

            if (projectCard.DialogResult == DialogResult.OK)
            {
                LoadProjects();

                // Выделяем строку с новым фиттингом.
                int idNewProject = projectCard.IdAddedProject;
                for (int i = 0; i < gridView1.DataRowCount; i++)
                {
                    object b = gridView1.GetRowCellValue(i, "Id");
                    if (b != null && b.Equals(idNewProject))
                    {
                        gridView1.FocusedRowHandle = i;
                        continue;
                    }
                }

                if (MessageBox.Show("Хотите добавить портфель к проекту?",
                                    "Добавление портфеля",
                                    MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                {
                    ViewForms.SelectBriefcaseWindow selectItem = new ViewForms.SelectBriefcaseWindow();
                    selectItem.Owner = this;
                    if (selectItem.ShowDialog() == DialogResult.OK)
                    {
                        List <int> id = selectItem.SelectedBriefcaseID;
                        // Добавляем портфели к проекту.
                        foreach (int oneID in id)
                        {
                            List <Model.AddFittingModel> models = new List <AddFittingModel>();
                            DataTable dt = new SqlMethods().LoadProjects(String.Format("select IDFitting, FittingCount from BriefcaseAccessories where IDBriefcase={0}", oneID));
                            foreach (DataRow row in dt.Rows)
                            {
                                models.Add(new AddFittingModel()
                                {
                                    IdProject    = idNewProject,
                                    IdFitting    = int.Parse(row["IDFitting"].ToString()),
                                    FittingCount = double.Parse(row["FittingCount"].ToString())
                                });
                            }

                            foreach (Model.AddFittingModel model in models)
                            {
                                AddFittingToProject(model.IdProject, model.IdFitting, model.FittingCount);
                            }
                        }

                        LoadFittings(idNewProject);

                        // Обновляем строку с проектом.
                        DataTable dt1 = new SqlMethods().LoadProjects(String.Format("exec ShowTheOneProjects {0}", idNewProject));
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "FittingSum", dt1.Rows[0]["FittingSum"]);
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TransportSum", dt1.Rows[0]["TransportSum"]);
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "LaborIntencity", dt1.Rows[0]["LaborIntencity"]);
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "UnexpectedExpenses", dt1.Rows[0]["UnexpectedExpenses"]);
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TotalSum", dt1.Rows[0]["TotalSum"]);
                        gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "TotalSumWithPercent2", dt1.Rows[0]["TotalSumWithPercent2"]);
                    }
                }
            }
        }