Exemplo n.º 1
0
        /// <summary>
        /// Редактировать выбранный проект.
        /// </summary>
        private void EditProject()
        {
            object idProject          = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Id");
            object nameProject        = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Name");
            object descriptionProject = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Description");

            object fitSum       = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "FittingSum");
            object transportSum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TransportSum");
            object laborSum     = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LaborIntencity");
            object unexcpectSum = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "UnexpectedExpenses");
            object totalSum     = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TotalSum");

            object numOfGoods  = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NumberOfGoods");
            object distance    = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Distanсe");
            object hours       = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Hours");
            object peopleCount = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PeopleCount");



            ProjectCard projectCard = new ProjectCard(int.Parse(idProject.ToString()), nameProject.ToString(), descriptionProject.ToString(),
                                                      fitSum, transportSum, laborSum, unexcpectSum, totalSum,
                                                      numOfGoods, distance, hours, peopleCount);

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

            if (projectCard.DialogResult == DialogResult.OK)
            {
                //int oldIndex = gridView1.FocusedRowHandle; // Индекс до обновления.
                LoadProjects();
                //gridView1.FocusedRowHandle = oldIndex;

                for (int i = 0; i < gridView1.DataRowCount; i++)
                {
                    object b = gridView1.GetRowCellValue(i, "Id");
                    if (b != null && b.Equals(idProject))
                    {
                        gridView1.FocusedRowHandle = i;
                        continue;
                    }
                }
            }
        }
Exemplo n.º 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"]);
                    }
                }
            }
        }