Exemple #1
0
        private void myTreeView_Selected(object sender, RoutedEventArgs e)
        {
            var item = e.OriginalSource as TreeViewItem;

            if (item == null)
            {
                return;
            }
            var source = item.DataContext;

            if (source is MyTable)
            {
                return;
            }
            else if (source is BaseViewModel)
            {
                BaseViewModel bv = source as BaseViewModel;
                //还有节点则返回
                if (bv.Children != null && bv.Children.Count > 0)
                {
                    return;
                }
                else
                {
                    string partType  = GetPartTypeString(bv);
                    string tableName = GetTableName(bv);
                    string sql       = string.Format("select * from {0} where PartType = '{1}'", tableName, partType);
                    Page   page      = null;
                    string msg;
                    #region 开始查询显示

                    switch (tableName)
                    {
                    case "Capacitor":
                        LstCapacitor.Clear();
                        page = new CapacitorPage();
                        dataService.CreateSqlQuery <Capacitor>(sql, out msg).ToList().ForEach(x => LstCapacitor.Add(x));

                        break;

                    case "IC":
                        LstIC.Clear();
                        page = new ICPage();
                        dataService.CreateSqlQuery <IC>(sql, out msg).ToList().ForEach(x => LstIC.Add(x));

                        break;

                    case "Inductor":
                        LstInductor.Clear();
                        page = new InductorPage();
                        dataService.CreateSqlQuery <Inductor>(sql, out msg).ToList().ForEach(x => LstInductor.Add(x));

                        break;

                    case "Misc":
                        LstMisc.Clear();
                        page = new MiscPage();
                        dataService.CreateSqlQuery <Misc>(sql, out msg).ToList().ForEach(x => LstMisc.Add(x));

                        break;

                    case "Module":
                        LstModule.Clear();
                        page = new ModulePage();
                        dataService.CreateSqlQuery <Module>(sql, out msg).ToList().ForEach(x => LstModule.Add(x));

                        break;

                    case "Oscillator":
                        LstOscillator.Clear();
                        page = new OscillatorPage();
                        dataService.CreateSqlQuery <Oscillator>(sql, out msg).ToList().ForEach(x => LstOscillator.Add(x));

                        break;

                    case "Resistor":
                        LstResistor.Clear();
                        page = new ResistorPage();
                        dataService.CreateSqlQuery <Resistor>(sql, out msg).ToList().ForEach(x => LstResistor.Add(x));

                        break;

                    case "Sensors":
                        LstSensors.Clear();
                        page = new SensorsPage();
                        dataService.CreateSqlQuery <Sensors>(sql, out msg).ToList().ForEach(x => LstSensors.Add(x));

                        break;
                    }
                    #endregion
                    page.DataContext   = this;
                    this.frame.Content = page;
                }
            }
        }
Exemple #2
0
        private void FileSelectBtn_Click(object sender, RoutedEventArgs e)
        {
            if (this.tableCombox.SelectedIndex == -1)
            {
                MessageBox.Show("请选择一张表来导入");
                return;
            }
            System.Windows.Forms.OpenFileDialog op = new System.Windows.Forms.OpenFileDialog();
            op.Multiselect = false;
            op.Title       = "请选择从Acess导入的EXCEL文件";
            string msg = "";

            if (op.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            this.tb_Path.Text = op.FileName;
            Page page  = null;
            int  count = 0;

            try
            {
                switch (this.tableCombox.SelectedIndex)
                {
                case 0:    //Capacitor
                    excelHelper.GetDatasFromAccess_Capacitor(op.FileName).ForEach(x => LstCapacitor.Add(x));
                    count = LstCapacitor.Count;
                    page  = new CapacitorPage();
                    break;

                case 1:    //IC
                    excelHelper.GetDatasFromAccess_IC(op.FileName).ForEach(x => LstIC.Add(x));
                    count = LstIC.Count;
                    page  = new ICPage();
                    break;

                case 2:     //Inductor
                    excelHelper.GetDatasFromAccess_Inductor(op.FileName).ForEach(x => LstInductor.Add(x));
                    count = LstInductor.Count;
                    page  = new InductorPage();
                    break;

                case 3:     // Misc
                    excelHelper.GetDatasFromAccess_Misc(op.FileName).ForEach(x => LstMisc.Add(x));
                    count = LstMisc.Count;
                    page  = new MiscPage();
                    break;

                case 4:     //Module
                    excelHelper.GetDatasFromAccess_Module(op.FileName).ForEach(x => LstModule.Add(x));
                    count = LstModule.Count;
                    page  = new ModulePage();
                    break;

                case 5:     //Oscillator
                    excelHelper.GetDatasFromAccess_Oscillator(op.FileName).ForEach(x => LstOscillator.Add(x));
                    count = LstOscillator.Count;
                    page  = new OscillatorPage();
                    break;

                case 6:     //Resistor
                    excelHelper.GetDatasFromAccess_Resistor(op.FileName).ForEach(x => LstResistor.Add(x));
                    count = LstResistor.Count;
                    page  = new ResistorPage();
                    break;

                case 7:     //Sensors
                    excelHelper.GetDatasFromAccess_Sensors(op.FileName).ForEach(x => LstSensors.Add(x));
                    count = LstSensors.Count;
                    page  = new SensorsPage();
                    break;
                }
                page.DataContext    = this;
                this.frame.Content  = page;
                this.lb_Msg.Content = string.Format("本次从excel读取到{0}条记录", count);
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }