示例#1
0
 public void ReadAll()
 {
     if (Rows == null)
     {
         Rows = workSheet.RangeUsed().RowsUsed();
     }
 }
示例#2
0
        private string GenerationData(string v, int indexRow, int indexColumn, IXLRangeRows rows)
        {
            var result = rows.ElementAt(indexRow).Cell(indexColumn).Value.ToString();

            if (String.IsNullOrWhiteSpace(result) && rows.ElementAt(indexRow).Cell(indexColumn).IsMerged())
            {
                return(v);
            }

            return(rows.ElementAt(indexRow).Cell(indexColumn).Value.ToString());
        }
示例#3
0
        private Dictionary <int, int> GenerationDayDictionary(IXLRangeRows rows, int index)
        {
            var j = 2;
            Dictionary <int, int> dictionary = new Dictionary <int, int>();

            while (true)
            {
                if (rows.ElementAt(index).Cell(j).MergedRange().ColumnCount() > 1)
                {
                    var newElement = rows.ElementAt(index + 1);
                    while (!String.IsNullOrWhiteSpace(newElement.Cell(j).Value.ToString()))
                    {
                        var tempSymbol = newElement.Cell(j).Address.ColumnNumber;
                        var tempValue  = Int32.Parse(newElement.Cell(j).Value.ToString());

                        dictionary[tempSymbol] = tempValue;
                        j++;
                    }
                    break;
                }
                j++;
            }
            return(dictionary);
        }
示例#4
0
        private List <ParserDateModel> GenerationMarksInCurrentActivity(int currentIndexActivity, Dictionary <int, int> dayDictionary, IXLRangeRows rows)
        {
            List <ParserDateModel> result = new List <ParserDateModel>();

            for (var i = 0; i < dayDictionary.Count();)
            {
                var objectDay = rows.ElementAt(currentIndexActivity).Cell(dayDictionary.ElementAt(i).Key);
                if (objectDay.MergedRange() != null)
                {
                    result.Add(
                        new ParserDateModel()
                    {
                        Text    = objectDay.Value.ToString(),
                        day     = dayDictionary.ElementAt(i).Value,
                        lastDay = dayDictionary.ElementAt(i).Value + objectDay.MergedRange().ColumnCount() - 1
                    });
                    i = i + objectDay.MergedRange().ColumnCount();
                    continue;
                }

                if (!String.IsNullOrWhiteSpace(objectDay.Value.ToString()))
                {
                    result.Add(new ParserDateModel()
                    {
                        IsExist = true,
                        day     = dayDictionary.ElementAt(i).Value
                    });
                }
                i++;
            }

            return(result);
        }
        private void ImportStudentsByFile(string filepath)
        {
            int           rowCount         = 0;
            List <string> attributes       = Database.ExecuteGetColumnNames();
            List <string> importAttributes = new List <string>();

            attributes.Remove("ID");
            Excel excel;

            try
            {
                excel = new Excel(filepath);
            }
            catch (IOException e)
            {
                MessageBox.Show(e.Message.ToString());
                return;
            }
            IXLRangeRows rows = excel.GetContentRows();

            foreach (IXLRangeRow r in rows)
            {
                rowCount++;
                importAttributes     = excel.GetAttributesFromRow(r.WorksheetRow(), attributes);
                importAttributes[24] = (excel.GetMiscAttributes(r.WorksheetRow(), attributes));
                if (IsValidInput(importAttributes))
                {
                    DataTable exactDuplicates = Database.CheckForExactDuplicateas(importAttributes[0], importAttributes[1], importAttributes[2], importAttributes[11]);
                    DataTable duplicates      = Database.CheckForDuplicates(importAttributes[0], importAttributes[1], importAttributes[2], importAttributes[11]);
                    if (importAttributes[18] == String.Empty)
                    {
                        importAttributes[18] = null;
                    }
                    //If In Camps UI and no value or in student ui
                    if (CampsListBorder.Visibility == Visibility.Hidden || CampsListComboBox.SelectedValue == null)
                    {
                        if (exactDuplicates.Rows.Count == 0)
                        {
                            if (duplicates.Rows.Count > 0)
                            {
                                ChildWindow childWindow = new ChildWindow(importAttributes, duplicates, camps, CampsListComboBox, false);
                                childWindow.ShowInTaskbar = false;
                                childWindow.Owner         = Application.Current.MainWindow;
                                childWindow.ShowDialog();
                            }
                            else
                            {
                                Database.ExecuteStudentImport(importAttributes[0], importAttributes[1], importAttributes[3], importAttributes[16], importAttributes[11], importAttributes[12], importAttributes[13],
                                                              importAttributes[14], importAttributes[4], importAttributes[5], importAttributes[6], importAttributes[7], importAttributes[9], importAttributes[8], importAttributes[10],
                                                              importAttributes[2], importAttributes[15], importAttributes[22], importAttributes[23], importAttributes[17], Convert.ToBoolean(importAttributes[18]),
                                                              importAttributes[19], importAttributes[20], importAttributes[24], importAttributes[21]);
                            }
                        }
                    }
                    //If in camps and something is selected
                    else
                    {
                        int campID;
                        if (exactDuplicates.Rows.Count == 0)
                        {
                            if (duplicates.Rows.Count <= 0)
                            {
                                Database.ExecuteStudentImport(importAttributes[0], importAttributes[1], importAttributes[3], importAttributes[16], importAttributes[11], importAttributes[12], importAttributes[13],
                                                              importAttributes[14], importAttributes[4], importAttributes[5], importAttributes[6], importAttributes[7], importAttributes[9], importAttributes[8], importAttributes[10],
                                                              importAttributes[2], importAttributes[15], importAttributes[22], importAttributes[23], importAttributes[17], Convert.ToBoolean(importAttributes[18]),
                                                              importAttributes[19], importAttributes[20], importAttributes[24], importAttributes[21]);
                                foreach (DataRow c in camps.Rows)
                                {
                                    string rowCurrentCamp = $"{c[2].ToString()} {Convert.ToDateTime(c[1].ToString()).Date}".Substring(0, c[2].ToString().Length + c[1].ToString().Length - 11);
                                    if (rowCurrentCamp == CampsListComboBox.SelectedValue.ToString())
                                    {
                                        campID = Convert.ToInt32(c[0].ToString());
                                        Database.ExecuteAddAttendance(campID, importAttributes[0], importAttributes[1], importAttributes[11], importAttributes[2]);
                                    }
                                }
                            }
                            //Handels Duplicate Students when insertting into a camp by using the child window
                            else
                            {
                                ChildWindow childWindow = new ChildWindow(importAttributes, duplicates, camps, CampsListComboBox);
                                childWindow.ShowInTaskbar = false;
                                childWindow.Owner         = Application.Current.MainWindow;
                                childWindow.ShowDialog();
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show($"Invalid input on row {rowCount}.");
                }
            }
            MessageBox.Show("Insert by file Complete");
        }