コード例 #1
0
 private void FillEntity(int id)
 {
     using (kipEntities context = new kipEntities())
     {
         role             = context.MVPSRoleSet.Where(b => b.Id == id).SingleOrDefault();
         MVPSRoleBox.Text = role.name;
     }
     AddButton.Text = "Сохранить";
 }
コード例 #2
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     using (kipEntities context = new kipEntities())
     {
         try
         {
             if (MVPSRoleBox.Text == "Введите название роли МВПС")
             {
                 throw new Exception("Введите коректное название роли МВПС");
             }
             if (role != null)
             {
                 int      key       = role.Id;
                 MVPSRole freshRole = context.MVPSRoleSet.Where(b => b.Id == key).SingleOrDefault();
                 string   str       = MVPSRoleBox.Text;
                 if ((freshRole.name != str) && (str != ""))
                 {
                     freshRole.name = str;
                     context.SaveChanges();
                 }
             }
             else
             {
                 string str = MVPSRoleBox.Text;
                 if (str != "")
                 {
                     MVPSRole freshRole = new MVPSRole
                     {
                         name = str
                     };
                     context.MVPSRoleSet.Add(freshRole);
                     context.SaveChanges();
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             Close();
         }
     }
 }
コード例 #3
0
        public static void FillGrid(ListBox list, DataGridView view)
        {
            var str = "";

            if (list.SelectedItem != null)
            {
                str = list.SelectedItem.ToString();
            }
            gridView = view;
            listBox  = list;

            switch (str)
            {
            case "Оборудование":
                Equipment.FillGrid(view);
                break;

            case "Типы оборудования":
                EquipmentType.FillGrid(view);
                break;

            case "Производители":
                Manufacturer.FillGrid(view);
                break;

            case "Типы систем":
                SystemType.FillGrid(view);
                break;

            case "Роли МВПС":
                MVPSRole.FillGrid(view);
                break;

            case "Типы МВПС":
                MVPSType.FillGrid(view);
                break;

            case "МВПС":
                MVPS.FillGrid(view);
                break;

            case "Правила компелктования":
                EquipmentRule.FillGrid(view);
                break;

            case "Замены оборудования":
                ReplacingLog.FillGrid(view);
                break;

            case "Работники":
                Worker.FillGrid(view);
                break;

            case "Должности":
                Position.FillGrid(view);
                break;

            case "График ТО и ТР":
                Shedule.FillGrid(view);
                break;

            case "Журнал проверки/ремонта":
                ServiceLog.FillGrid(view);
                break;

            default:
                break;
            }
        }
コード例 #4
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            Guid guid = mVPS == null? Guid.Empty : mVPS.Id;

            using (kipEntities context = new kipEntities())
            {
                try
                {
                    CheckFields();
                    if (mVPS != null)
                    {
                        int           typeId = typeIds[TypeBox.SelectedIndex];
                        int           roleId = roleIds[RoleBox.SelectedIndex];
                        int           ruleId = currentRules[RuleBox.SelectedIndex].Id;
                        MVPSType      type   = context.MVPSTypeSet.Where(b => b.Id == typeId).SingleOrDefault();
                        MVPSRole      role   = context.MVPSRoleSet.Where(b => b.Id == roleId).SingleOrDefault();
                        EquipmentRule rule   = context.EquipmentRuleSet.Where(b => b.Id == ruleId).SingleOrDefault();
                        MVPS          mVPS   = context.MVPSSet.Where(b => b.Id == guid).SingleOrDefault();
                        if (mVPS.MVPSRole.Id != role.Id)
                        {
                            mVPS.MVPSRole = role;
                        }
                        if (mVPS.MVPSType.Id != type.Id)
                        {
                            mVPS.MVPSType = type;
                        }
                        if (mVPS.number != NumberBox.Text)
                        {
                            mVPS.number = NumberBox.Text;
                        }
                        if (mVPS.series != SeriesBox.Text)
                        {
                            mVPS.series = SeriesBox.Text;
                        }
                        if (mVPS.EquipmentRule.Id != rule.Id)
                        {
                            mVPS.EquipmentRule = rule;
                        }
                        context.SaveChanges();
                    }
                    else
                    {
                        int           typeId = typeIds[TypeBox.SelectedIndex];
                        int           roleId = roleIds[RoleBox.SelectedIndex];
                        int           ruleId = currentRules[RuleBox.SelectedIndex].Id;
                        MVPSType      type   = context.MVPSTypeSet.Where(b => b.Id == typeId).SingleOrDefault();
                        MVPSRole      role   = context.MVPSRoleSet.Where(b => b.Id == roleId).SingleOrDefault();
                        EquipmentRule rule   = context.EquipmentRuleSet.Where(b => b.Id == ruleId).SingleOrDefault();

                        mVPS = new MVPS
                        {
                            Id            = Guid.Parse(IdBox.Text),
                            number        = NumberBox.Text,
                            series        = SeriesBox.Text,
                            MVPSType      = type,
                            MVPSRole      = role,
                            EquipmentRule = rule
                        };

                        context.MVPSSet.Add(mVPS);
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    roleIds.Clear();
                    typeIds.Clear();
                    currentRules.Clear();
                    Close();
                }
            }
        }