示例#1
0
        ////////////export all report
        private void exportreport(classinfo cl1, View_class_exp vst1)
        {
            String dirsave = null;
            List <View_class_student> lstwei = new List <View_class_student>();

            // List<View_class_student> lstall = null;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string localFilePath = saveFileDialog1.FileName.ToString();
                dirsave = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
            }



            List <studreport> lstrep = null;
            var questionQuery2       = from o in pp.context.studreport
                                       where o.classid == cl1.classid && o.expid == vst1.expid
                                       select o;

            if (questionQuery2.Count() > 0)
            {
                lstrep = questionQuery2.ToList <studreport>();

                foreach (studreport qew in lstrep)
                {
                    string attaDirectory = dirsave + @"\" + qew.stid + EXtools.getstuname(pp, qew.stid);
                    String repname       = qew.fname;
                    if (repname[repname.Length - 1] == 'x' || repname[repname.Length - 1] == 'X')
                    {
                        attaDirectory = attaDirectory + @".docx";
                    }
                    else
                    {
                        attaDirectory = attaDirectory + @".doc";
                    }

                    Byte[]       Files = qew.rep;
                    BinaryWriter bw    = new BinaryWriter(File.Open(attaDirectory, FileMode.OpenOrCreate));
                    bw.Write(Files);
                    bw.Close();
                    ///导出附件
                    ///
                    if (qew.aname != null && qew.atta != null)
                    {
                        string attaDirectory2 = dirsave + @"\" + qew.stid + EXtools.getstuname(pp, qew.stid);
                        attaDirectory2 = attaDirectory2 + @".rar";
                        Byte[]       Files2 = qew.atta;
                        BinaryWriter bw2    = new BinaryWriter(File.Open(attaDirectory2, FileMode.OpenOrCreate));
                        bw2.Write(Files2);
                        bw2.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("没有报告可以导出");
            }
        }