Exemple #1
0
        private bool ImportExcel()
        {
            //bool result;
            System.Data.DataTable dt;
            var openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Excel (*.XLS)|*.xls";

            if (!(bool)(openFileDialog.ShowDialog()))
            {
                return(false);
            }
            else
            {
                string excelName = openFileDialog.FileName;
                dt = _excelHelper.LoadExcel(excelName);
            }

            if (dt == null)
            {
                return(false);
            }
            else
            {
                var tradeNo = openFileDialog.SafeFileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0];
                LvTradeInfo.Add(new T_Trade_Sta_Ext()
                {
                    Trade_No = tradeNo, Sort = LvTradeInfo.Count()
                });
                dt.Rows.RemoveAt(0);
                dt.Columns.RemoveAt(9);
                ld.Add(dt);
                return(true);
            }
        }
        //初始化
        public override void Loaded()
        {
            //如果上页面有传过来参数
            if ((int)ModifyOrAdd == 1)
            {
                //题目名称
                QuestionName = Question_Collection.Question;

                //题目难度
                Difficulty = Question_Collection.Level.ToString();
                try
                {
                    //通过传过来的题目的KEY查询出所有符合的交易信息
                    List <T_Trade_Sta> tradeinfo =
                        ExamHandle.TryGetData <T_Trade_Sta>(
                            @"SELECT F_KEY,F_QUESTION_KEY,F_MENU_NO,F_TRADE_NO,F_PROPORTION,F_SORT FROM T_TRADE_STA WHERE F_QUESTION_KEY = ?",
                            Question_Collection.Key);
                    foreach (var ele in tradeinfo)
                    {
                        List <T_Fld_Sta> listFldSta = ExamHandle.TryGetData <T_Fld_Sta>(
                            @"SELECT
                                    F_KEY,
                                    F_TRADESTA_KEY,
                                    F_LOCATION,
                                    F_CHANNEL,
                                    F_IOFLAG,
                                    F_OBJCODE,
                                    F_FLDCODE,
                                    F_FLDDES,
                                    F_FLDVALUE,
                                    F_ISCREATE,
                                    F_PROPORTION,
                                    F_SORT
                                FROM
                                    T_FLD_STA WHERE F_TRADESTA_KEY=?",
                            ele.Key);
                        string keyinfos = string.Empty;
                        foreach (var item in listFldSta)
                        {
                            keyinfos += item.F_KEY + "|*|"
                                        + item.F_TRADESTA_KEY + "|*|"
                                        + item.F_LOCATION + "|*|"
                                        + item.F_CHANNEL + "|*|"
                                        + item.F_IOFLAG + "|*|"
                                        + item.F_OBJCODE + "|*|"
                                        + item.F_FLDCODE + "|*|"
                                        + item.F_FLDDES + "|*|"
                                        + item.F_FLDVALUE + "|*|"
                                        + item.F_ISCREATE + "|*|"
                                        + item.F_PROPORTION + "|*|"
                                        + item.F_SORT + "#*#";
                        }


                        LvTradeInfo.Add(new T_Trade_Sta_Ext
                        {
                            Key          = ele.Key,
                            Question_Key = ele.Question_Key,
                            Menu_No      = ele.Menu_No,
                            Trade_No     = ele.Trade_No,
                            Proportion   = ele.Proportion,
                            KeyInfo      = keyinfos,
                            Sort         = ele.Sort
                        });
                    }



                    //var temp = new List<T_Trade_Sta>(tradeinfo);

                    ////将查询出来的交易信息转一次格式,变成需要的的类型T_Trade_Sta_Ext

                    //foreach (var item in listPtAnswer)
                    //{
                    //    keyinfos += item.F_KEY + "|*|"
                    //    + item.F_TRADESTA_KEY + "|*|"
                    //    + item.F_LOCATION + "|*|"
                    //    + item.F_CHANNEL + "|*|"
                    //    + item.F_IOFLAG + "|*|"
                    //    + item.F_OBJCODE + "|*|"
                    //    + item.F_FLDCODE + "|*|"
                    //    + item.F_FLDDES + "|*|"
                    //    + item.F_FLDVALUE + "|*|"
                    //    + item.F_ISCREATE + "|*|"
                    //    + item.F_PROPORTION + "|*|"
                    //    + item.F_SORT + "#*#";
                    //}
                    //List<T_Trade_Sta_Ext> ListLvTradeInfo = temp.Select(c => new T_Trade_Sta_Ext
                    //{
                    //    Key = c.Key,
                    //    Question_Key = c.Question_Key,
                    //    Menu_No = c.Menu_No,
                    //    Trade_No = c.Trade_No,
                    //    Proportion = c.Proportion,
                    //    KeyInfo = "",
                    //    Sort = c.Sort
                    //}).ToList();

                    ////将转后的交易信息负给前台listview的数据源
                    //LvTradeInfo = new ObservableCollection<T_Trade_Sta_Ext>(ListLvTradeInfo);

                    ////通过传过来的交易的KEY查询出所有符合的答案信息
                    //for (int i = 0; i < LvTradeInfo.Count(); i++)
                    //{
                    //    List<T_Trade_Value_Sta> answerinfo =
                    //        ExamHandle.TryGetData<T_Trade_Value_Sta>(
                    //            @"SELECT F_KEY,F_TRADE_STA_KEY,F_VALUE_TYPE,F_DOMAIN,F_DOMAIN_VALUE,F_IS_WRITE,F_PROPORTION ,F_SORT FROM T_TRADE_VALUE_STA WHERE F_TRADE_STA_KEY = ?",
                    //            LvTradeInfo[i].Key);
                    //    var tempanswerinfo = new List<T_Trade_Value_Sta>(answerinfo);
                    //    string keyinfos = string.Empty;

                    //    //将答案信息拼成交易展示需要的一个字段:KeyInfo
                    //    foreach (T_Trade_Value_Sta x in tempanswerinfo)
                    //    {
                    //        string f = string.Empty;
                    //        if (x.Value_Type == 0 || x.Value_Type == 1)
                    //            f = "Fd";
                    //        keyinfos += f + x.Domain + "=" + x.Domain_Value + "(" + x.Proportion + "%)" +
                    //                    (x.Is_Write.ToString() != "0" ? "(接收数据)" : "不接收数据");
                    //        if (tempanswerinfo.IndexOf(x) != tempanswerinfo.Count() - 1)
                    //        {
                    //            keyinfos += " | ";
                    //        }
                    //    }

                    //    //将该拼好的KeyInfo负值给绑定源
                    //    LvTradeInfo[i].KeyInfo = keyinfos;
                    //}
                }
                catch (Exception)
                {
                }
            }
            else
            {
                Difficulty = "1";
            }
        }
        //新增
        private void AddAnswer()
        {
            Messenger.Default.Send(
                new WindowMessage
            {
                WindowName      = "TradeFieldPage",
                Operation       = WindowOperation.ShowDialog,
                ProcessCallback = (obj) =>
                {
                    if (obj == null)
                    {
                        return;
                    }

                    var data = obj as T_Trade_Sta_Ext;
                    if (data == null)
                    {
                        return;
                    }
                    data.Sort = LvTradeInfo.Count;
                    //下层页面传过来的值
                    LvTradeInfo.Add(data);

                    //listPtAnswer = data[0] as List<T_Fld_Sta>;
                    //string TradeStaKey = data[1] as string;
                    //string MenuNo = data[2] as string;
                    //string TradeWeight = data[3] as string;
                    //string keyinfos = string.Empty;
                    //foreach (var item in listPtAnswer)
                    //{
                    //    keyinfos += item.F_KEY + "|*|"
                    //    + item.F_TRADESTA_KEY + "|*|"
                    //    + item.F_LOCATION + "|*|"
                    //    + item.F_CHANNEL + "|*|"
                    //    + item.F_IOFLAG + "|*|"
                    //    + item.F_OBJCODE + "|*|"
                    //    + item.F_FLDCODE + "|*|"
                    //    + item.F_FLDDES + "|*|"
                    //    + item.F_FLDVALUE + "|*|"
                    //    + item.F_ISCREATE + "|*|"
                    //    + item.F_PROPORTION + "|*|"
                    //    + item.F_SORT + "#*#";
                    //}


                    ////遍历从下层页面传过来的第一个参数listPtAnswer,1,将其按条加到la集合中;2,将信息分割拼成一个 trade 用来显示的字符串keyinfos
                    //la.AddRange(listPtAnswer);

                    ////给tradeinfo 负值
                    //var tradeinfo = new T_Trade_Sta_Ext()
                    //{
                    //    Key = TradeStaKey,
                    //    Menu_No = MenuNo,
                    //    Trade_No = "",
                    //    Proportion = Convert.ToSingle(TradeWeight),
                    //    KeyInfo = keyinfos,
                    //    Sort = LvTradeInfo.Count()
                    //};

                    ////将tradeinfo按条加到数据源中
                    //LvTradeInfo.Add(tradeinfo);
                }
            });
        }