Пример #1
0
        private void btnImportGlobalPositions_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog opf = new OpenFileDialog();

            if (opf.ShowDialog().Value == true)
            {
                Excel.Worksheet xlsheet;
                Excel.Workbook  xlwkbook;

                xlwkbook = (Excel.Workbook)System.Runtime.InteropServices.Marshal.BindToMoniker(opf.FileName);
                xlsheet  = (Excel.Worksheet)xlwkbook.ActiveSheet;

                Excel.Range oRng;

                for (int i = 2; i < 48; i++)
                {
                    HR_GlobalPositions pos = new HR_GlobalPositions();
                    //name
                    string gstr;
                    oRng = (Excel.Range)xlsheet.Cells[i, 1];
                    try
                    {
                        gstr = oRng.get_Value(Missing.Value).ToString();
                    }
                    catch (System.NullReferenceException)
                    {
                        continue;
                    }
                    if (gstr == "")
                    {
                        continue;
                    }
                    pos.Name = gstr;


                    oRng = (Excel.Range)xlsheet.Cells[i, 6];
                    try
                    {
                        gstr = oRng.get_Value(Missing.Value).ToString();
                    }
                    catch (System.NullReferenceException)
                    {
                        continue;
                    }
                    if (gstr == "")
                    {
                        continue;
                    }
                    pos.id_positionType = int.Parse(gstr);
                    pos.IsActive        = true;
                    pos.ActiveFrom      = DateTime.Now;

                    using (var logic = new NomenclaturesLogic())
                    {
                        logic.HR_GlobalPositions.Add(pos);
                        logic.Save();
                    }
                }
            }
        }
Пример #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            using (var logic = new NomenclaturesLogic())
            {
                if (this.id_globalPosition == 0)
                {
                    this.globalPosition            = new HR_GlobalPositions();
                    this.globalPosition.IsActive   = true;
                    this.globalPosition.ActiveFrom = DateTime.Now;
                }
                else
                {
                    this.globalPosition = logic.HR_GlobalPositions.GetById(this.id_globalPosition);
                }

                using (var comboBoxLogic = new ComboBoxLogic())
                {
                    this.cmbPositionTypes.ItemsSource = comboBoxLogic.ReadPositionTypes(this.globalPosition.id_globalPosition);
                }
                this.DataContext = this.globalPosition;
            }
        }