Exemple #1
0
        /// <summary>
        /// 导入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.lb_Msg.Foreground = new SolidColorBrush(Colors.Green);
            object result = "";

            try
            {
                switch (this.tableCombox.SelectedIndex)
                {
                case 0:    //Capacitor
                    if (LstCapacitor.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Capacitor>(LstCapacitor.ToList());
                    this.LstCapacitor.Clear();
                    break;

                case 1:    //IC
                    if (LstIC.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <IC>(LstIC.ToList());
                    this.lstIC.Clear();
                    break;

                case 2:     //Inductor
                    if (LstInductor.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Inductor>(LstInductor.ToList());
                    this.LstInductor.Clear();
                    break;

                case 3:     // Misc
                    if (LstMisc.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Misc>(LstMisc.ToList());
                    this.LstMisc.Clear();
                    break;

                case 4:     //Module
                    if (LstModule.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Module>(LstModule.ToList());
                    this.LstModule.Clear();
                    break;

                case 5:     //Oscillator
                    if (LstOscillator.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Oscillator>(LstOscillator.ToList());
                    this.LstOscillator.Clear();
                    break;

                case 6:     //Resistor
                    if (LstResistor.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Resistor>(LstResistor.ToList());
                    this.LstResistor.Clear();
                    break;

                case 7:     //Sensors
                    if (LstSensors.Count == 0)
                    {
                        MessageBox.Show("没有要导入的数据");
                        return;
                    }
                    result = sqlHelper.Add <Sensors>(LstSensors.ToList());
                    this.LstSensors.Clear();
                    break;
                }
                this.lb_Msg.Content = string.Format("成功导入{0}条记录", result);
                MessageBox.Show(string.Format("成功导入{0}条记录", result));
            }
            catch (Exception ee)
            {
                this.lb_Msg.Foreground = new SolidColorBrush(Colors.Red);
                this.lb_Msg.Content    = "导入失败!";
                MessageBox.Show(ee.Message);
            }
        }
Exemple #2
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 #3
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);
            }
        }