Exemplo n.º 1
0
        private void StartUpInitializer()
        {
            this.SchoolClasses         = new string[] { "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII" };
            this.Section               = new string[] { "A", "B", "C", "D", "E" };
            this.ClsIndex              = -1;
            this.SectionIndex          = -1;
            this.UnSelectedColumnIndex = -1;
            this.SelectedColumnIndex   = -1;
            this.SYear            = DateTime.Today.Year;
            this.EYear            = DateTime.Today.Year;
            this.Slist            = new List <Student>();
            PreFilteredList       = new List <Student>();
            this.FilteredList     = new List <Student>();
            this.ProgressbarValue = "0/0";

            ExcelColumnPositionService exService = new ExcelColumnPositionService();

            this.UnSelectedColumns = new ObservableCollection <string>(exService.GetColListForExport());
            this.SelectedColumns   = new ObservableCollection <string>();
            this.db             = new ExcelExportDb();
            this._flagCanExport = true;
            this.FilterCategory = "none";

            HsArtsSubs      = new string[] { "ARABIC", "ECONOMICS", "EDUCATION", "GEOGRAPHY", "PHILOSOPHY", "HISTORY", "POL. SC", "SOCIOLOGY" };
            HsSciSubs       = new string[] { "PHYSICS", "CHEMISTRY", "MATHEMATICS", "BIOLOGY" };
            HsActiveSubs    = new string[] { };
            HsSubIndex      = -1;
            StreamList      = new string[] { "ARTS", "SCIENCE" };
            StreamListIndex = -1;

            SubHsVisibility = System.Windows.Visibility.Hidden;

            this.MoveRightCommand     = new RelayCommand(this.MoveRight, this.CanMoveRight);
            this.MoveRightAllCommand  = new RelayCommand(this.MoveRightAll, this.CanMoveRightAll);
            this.MoveLeftCommand      = new RelayCommand(this.MoveLeft, this.CanMoveLeft);
            this.MoveLeftAllCommand   = new RelayCommand(this.MoveLeftAll, this.CanMoveLeftAll);
            this.BuildGridViewCommand = new RelayCommand(this.BuildGridView, this.CanBuildGridView);
            this.ExportCommand        = new RelayCommand(this.Export, this.CanExport);
        }
Exemplo n.º 2
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            ExcelExportDb db = new ExcelExportDb();

            slist = db.GetStudentListByClass(SchoolClass[this.SchoolClassIndex], SchoolSection[SchoolSectionIndex], StartYear, EndYear);
            if (slist.Count > 0)
            {
                int sListStdIndex = 0;
                try
                {
                    Excel.Application xlApp = new Excel.Application();
                    var oWB = xlApp.Workbooks.Add();
                    Excel._Worksheet workSheet = (Excel.Worksheet)xlApp.ActiveSheet;
                    workSheet.Rows.WrapText = true;

                    //add column titile
                    workSheet.Cells[2, 1] = "U-DISE Code : " + GlobalVar.Udise;
                    workSheet.Cells[2, 3] = "School Name : " + GlobalVar.SchoolName;
                    workSheet.Cells[2, 5] = "Class : " + SchoolClass[SchoolClassIndex];
                    workSheet.Cells[2, 6] = "Section : " + SchoolSection[SchoolSectionIndex];
                    workSheet.Cells[2, 7] = "Academic Year : 2017-2018";

                    workSheet.Cells[3, 1] = "SL";
                    workSheet.Cells[3, 2] = "Variable";
                    workSheet.Cells[3, 4] = "Student 1";
                    workSheet.Cells[3, 5] = "Student 2";
                    workSheet.Cells[3, 6] = "Student 3";
                    workSheet.Cells[3, 7] = "Student 4";

                    workSheet.Range[workSheet.Cells[2, 1], workSheet.Cells[2, 2]].Merge();
                    workSheet.Range[workSheet.Cells[2, 3], workSheet.Cells[2, 4]].Merge();

                    int totalStudent = slist.Count;
                    this.ProgressbarValue = "0" + "%";

                    var OtrLoops       = Math.Ceiling(Convert.ToDecimal(totalStudent / 4));
                    int OuterLoopNos   = (int)OtrLoops;
                    int StdInLastOuter = totalStudent - (OuterLoopNos * 4);

                    // made spliting array
                    List <Student>[] StdListArray = new List <Student> [OuterLoopNos];

                    if (StdInLastOuter == 0)
                    {
                        for (int i = 0; i < OuterLoopNos; i++)
                        {
                            int            startIndex = i * 4;
                            int            endIndex   = startIndex + 4;
                            List <Student> tempList   = new List <Student>();
                            for (int k = startIndex; k < endIndex; k++)
                            {
                                tempList.Add(slist[k]);
                            }
                            StdListArray[i] = tempList;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < OuterLoopNos - 1; i++)
                        {
                            int            startIndex = i * 4;
                            int            endIndex   = startIndex + 4;
                            List <Student> tempList   = new List <Student>();
                            for (int k = startIndex; k < endIndex; k++)
                            {
                                tempList.Add(slist[k]);
                            }
                            StdListArray[i] = tempList;
                        }

                        // last array add
                        List <Student> tempList2 = new List <Student>();

                        int sIndex = (OuterLoopNos) * 4;
                        for (int j = sIndex; j < slist.Count; j++)
                        {
                            tempList2.Add(slist[j]);
                        }
                        StdListArray[OuterLoopNos - 1] = tempList2;
                    }

                    int startRow = 4;
                    for (int oi = 0; oi < OuterLoopNos; oi++)
                    {
                        startRow = WriteInCell(startRow, StdListArray[oi], workSheet);
                        double percen = (oi * 4 * 100) / totalStudent;
                        ProgressbarValue = percen.ToString() + "%";
                    }

                    workSheet.Rows.AutoFit();

                    oWB.SaveAs(OutputFile, AccessMode: Excel.XlSaveAsAccessMode.xlShared);

                    //cleanup
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    oWB.Close();
                    Marshal.ReleaseComObject(oWB);

                    //quit and release
                    xlApp.Quit();
                    Marshal.ReleaseComObject(xlApp);
                    OutputFile = string.Empty;
                }
                catch (Exception exl)
                {
                    System.Windows.MessageBox.Show("Problem in generating excel file. : " + sListStdIndex.ToString() + " " + exl.Message);
                }
            }
            else
            {
                System.Windows.MessageBox.Show("Sorry! there is no record.");
            }
        }