Esempio n. 1
0
        /// <summary>
        /// XLS导入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnImportEqu_Click(object sender, RoutedEventArgs e)
        {
            SecurityClass[] securityclasses = CO_IA.Client.Utility.GetSecurityClasses();
            if (securityclasses == null || securityclasses.Length == 0)
            {
                MessageBox.Show("请先在基础数据设置中增加保障类别");
            }
            else
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter = "Excel文件(*.xls)|*.xls";
                //dialog.Filter = "(*.xlsx)|*.xlsx|(*.xls)|*.xls";
                //dialog.DefaultExt = "xlsx";

                dialog.CheckFileExists = true;
                if (dialog.ShowDialog() == true)
                {
                    DataTable[] tables = ExcelImportHelper.LoadDataFromExcel(dialog.FileName);
                    if (tables != null && tables.Length > 0)
                    {
                        //单位信息
                        Organization orginfo  = null;
                        DataTable    orgtable = tables.FirstOrDefault(r => r.TableName == "单位信息");
                        if (orgtable != null && ExcelImportHelper.ValidateORG(orgtable))
                        {
                            orginfo = this.LoadORGFromTable(orgtable);
                        }
                        if (orginfo != null)
                        {
                            #region 验证单位名称

                            OrgQueryCondition condition = new OrgQueryCondition();
                            condition.Name = orginfo.Name;
                            Organization[] orgs    = this.GetORGSource(condition);
                            Organization   sameorg = orgs.FirstOrDefault(r => r.Name == orginfo.Name);
                            #endregion

                            if (sameorg != null)
                            {
                                MessageBoxResult result = MessageBox.Show(string.Format("'{0}'已经存在,是否将Excel中的设备导入到'{0}'中?", orginfo.Name), "提示", MessageBoxButton.YesNo);
                                if (result == MessageBoxResult.Yes)
                                {
                                    ImportEquipment(tables, sameorg);
                                }
                                else
                                {
                                    MessageBox.Show("请修改单位名称");
                                }
                            }
                            else
                            {
                                ImportEquipment(tables, orginfo);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public static void Import(Action <ActivityOrganization, List <ActivityEquipment> > p_importEquips)
        {
            ImportEquipmentDelegate = p_importEquips;
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter     = "Excel文件(*.xls)|*.xls";
            dialog.DefaultExt = "xls";

            dialog.CheckFileExists = true;
            if (dialog.ShowDialog() == true)
            {
                DataTable[] tables = ExcelImportHelper.LoadDataFromExcel(dialog.FileName);
                if (tables != null && tables.Length > 0)
                {
                    //单位信息
                    ActivityOrganization activityorg = null;
                    DataTable            orgtable    = tables.FirstOrDefault(r => r.TableName == "单位信息");
                    if (orgtable != null && ExcelImportHelper.ValidateORG(orgtable))
                    {
                        activityorg = LoadActivityORGFromTable(orgtable, SystemLoginService.CurrentActivity.Guid);
                    }
                    if (activityorg != null)
                    {
                        #region 验证单位名称
                        OrgQueryCondition condition = new OrgQueryCondition();
                        condition.ActivityGuid = SystemLoginService.CurrentActivity.Guid;
                        condition.Name         = activityorg.Name;
                        ActivityOrganization[] orgs    = DataOperator.GetActivityOrgSources(condition);
                        ActivityOrganization   sameorg = orgs.FirstOrDefault(r => r.Name == activityorg.Name);
                        #endregion

                        if (sameorg != null)
                        {
                            MessageBoxResult result = MessageBox.Show(string.Format("单位'{0}'已经存在,是否将Excel中的设备导入到现有的单位中?", activityorg.Name), "提示", MessageBoxButton.YesNo);
                            if (result == MessageBoxResult.Yes)
                            {
                                ImportActivityEquipment(tables, sameorg);
                            }
                            else
                            {
                                MessageBox.Show("请修改单位名称");
                            }
                        }
                        else
                        {
                            ImportActivityEquipment(tables, activityorg);
                        }
                    }
                }
            }
        }