Advertisement
lilos404

Untitled

Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.70 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4. using System.Drawing;
  5. using System.Globalization;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using DevExpress.Spreadsheet;
  9. using DevExpress.Web.Office;
  10. using DevExpress.XtraSpreadsheet;
  11.  
  12.  
  13. namespace DevExpress.Web.Demos
  14. {
  15.  
  16.     public class CellValueValidationHelpers
  17.     {
  18.  
  19.         static Worksheet MPD_Page, Section_Page, ATA_Page, Revision_Page, Carte_Page, MRBR_Page, ACCESS_Page ,ZONE_Page ;
  20.         public static void OnCellValueChanged(object sender, SpreadsheetCellEventArgs e)
  21.         {
  22.             SpreadsheetDocumentInfo documentInfo = sender as SpreadsheetDocumentInfo;
  23.             revisionValidationCell(e.Cell);
  24.             sectionValidationCell(e.Cell);
  25.  
  26.         }
  27.         //   public static void PrepareWorksheet(Worksheet MPD_Page_in, Worksheet Revision_Page_in, Worksheet Section_Page_in, Worksheet ATA_Page_in, Worksheet Carte_Page_in)
  28.         public static async Task PrepareWorksheet(DevExpress.Web.Mvc.MVCxSpreadsheet wb)
  29.  
  30.         {
  31.  
  32.             MPD_Page = wb.Document.Worksheets[0];
  33.             Section_Page = wb.Document.Worksheets[2];
  34.             Revision_Page = wb.Document.Worksheets[1];
  35.             ATA_Page = wb.Document.Worksheets[3];
  36.             Carte_Page = wb.Document.Worksheets[4];
  37.             MRBR_Page = wb.Document.Worksheets[5];
  38.             ACCESS_Page  = wb.Document.Worksheets[6];
  39.             ZONE_Page = wb.Document.Worksheets[7];
  40.  
  41.             var tr = revisionValidation();
  42.             var sr = sectionValidation();
  43.             var tv = taskValidation();
  44.             var mr = mrbrValidation();
  45.             accessValidation();
  46.              preparationValidation();
  47.             zoneValidation();
  48.           //  await tr;
  49.           //  await sr;
  50.           //  await tv;
  51.           //  await mr;
  52.  
  53.         }
  54.  
  55.         private static void zoneValidation()
  56.         {
  57.             var cells = MPD_Page.Columns[6].ExistingCells.ToArray();
  58.             string indice = "";
  59.             var zonesListes = ZONE_Page.Columns[0].ExistingCells.ToArray();
  60.             string[] zonesValue = new string[zonesListes.Length];
  61.             string[] zones;
  62.             for (int i = 0; i < zonesListes.Length; i++)
  63.             {
  64.                 zonesValue[i] = zonesListes[i].Value.ToString();
  65.  
  66.             }
  67.             for (int i = 1; i < cells.Length; i++)
  68.             {
  69.  
  70.                 indice = "G" + (i + 1).ToString();
  71.                 if (cells[i].Value.ToString() == "")
  72.                 {
  73.                     continue;
  74.                 }
  75.                 zones = cells[i].Value.ToString().Split('\n');
  76.                 foreach (var zone in zones)
  77.                 {
  78.                     if (Array.IndexOf(zonesValue, zone) == -1)
  79.                     {
  80.                         MPD_Page.Cells[indice].FillColor = Color.Red;
  81.                         break;
  82.                     }
  83.  
  84.                 }
  85.                
  86.  
  87.             }
  88.         }
  89.  
  90.         private static void preparationValidation()
  91.         {
  92.             var cells = MPD_Page.Columns[5].ExistingCells.ToArray();
  93.             string indice = "";
  94.             for (int i = 1; i < cells.Length; i++)
  95.             {
  96.  
  97.                 indice = "F" + (i + 1).ToString();
  98.                 if (cells[i].Value.ToString() == "")
  99.                 {
  100.                     continue;
  101.                 }
  102.  
  103.                 if (cells[i].Value.ToString().IndexOf("\n")>0)
  104.                 {
  105.                     MPD_Page.Cells[indice].FillColor = Color.Red;
  106.                 }
  107.  
  108.             }
  109.  
  110.  
  111.  
  112.         }
  113.  
  114.         static void accessValidation()
  115.         {
  116.             var accessListe = ACCESS_Page.Columns[0].ExistingCells.ToArray();
  117.             var cells = MPD_Page.Columns[4].ExistingCells.ToArray();
  118.             var zonesListes = MPD_Page.Columns[6].ExistingCells.ToArray();
  119.             string[] accessValue = new string[accessListe.Length];
  120.  
  121.             for (int i = 0; i < accessListe.Length; i++)
  122.             {
  123.                 accessValue[i] = accessListe[i].Value.ToString();
  124.          
  125.             }
  126.  
  127.  
  128.             string indice = "";
  129.  
  130.             for (int i = 1; i < cells.Length; i++)
  131.             {
  132.                 indice = "E" + (i + 1).ToString();
  133.                 bool notFound = false;
  134.                 string[] ligneAccess , zones ;
  135.                 string[] access;
  136.                 string[] cellAccessValues , cellAccessValuesReversed;
  137.  
  138.                 if (cells[i].Value.ToString() == "")
  139.                 {
  140.                     continue;
  141.                 }
  142.  
  143.                 zones = zonesListes[i].Value.ToString().Split('\n');
  144.                 ligneAccess = cells[i].Value.ToString().Split('\n');
  145.  
  146.                 if (zones.Length < ligneAccess.Length)
  147.                 {
  148.                     MPD_Page.Cells[indice].FillColor = Color.Red;
  149.                     continue;
  150.  
  151.                 }
  152.                 cellAccessValues = cells[i].Value.ToString().Replace('\n', ';').Split(';');
  153.                 cellAccessValuesReversed = cells[i].Value.ToString().Replace('\n', ';').Split(';');
  154.                 Array.Reverse(cellAccessValuesReversed);
  155.                
  156.  
  157.                 foreach (var itemligne in ligneAccess)
  158.                 {
  159.                    
  160.                     if (itemligne != "") {
  161.                     access = itemligne.Split(';');
  162.                     foreach (var itemaccess in access)
  163.                     {
  164.                        
  165.                        if (Array.IndexOf(accessValue, itemaccess)== -1 || (Array.IndexOf(cellAccessValues, itemaccess) != (cellAccessValues.Length - Array.IndexOf(cellAccessValuesReversed, itemaccess)) - 1))
  166.                         {
  167.                             notFound = true;
  168.                             MPD_Page.Cells[indice].FillColor = Color.Red;
  169.                             break;
  170.                         }
  171.                     }
  172.                     if (notFound)
  173.                     {
  174.                         break;
  175.                     }
  176.                 }
  177.  
  178.  
  179.  
  180.                 }
  181.  
  182.  
  183.  
  184.             }
  185.         }
  186.  
  187.         static async Task revisionValidation()
  188.         {
  189.             Column cc = MPD_Page.Columns[0];
  190.             var cells = cc.ExistingCells.ToArray();
  191.             string indice = "";
  192.  
  193.             for (int i = 2; i < cells.Length; i++)
  194.             {
  195.                 indice = "A" + (i + 1).ToString();
  196.  
  197.                 if (cells[i].Value.ToString() == "" || cells[i].Value.ToString() == "R" || cells[i].Value.ToString() == "N" || cells[i].Value.ToString() == "D")
  198.                 {
  199.  
  200.                 }
  201.                 else
  202.                 {
  203.                     MPD_Page.Cells[indice].FillColor = Color.Red;
  204.  
  205.                 }
  206.             }
  207.         }
  208.         static async Task sectionValidation()
  209.         {
  210.             ArrayList arrSample = new ArrayList();
  211.  
  212.  
  213.             Column cc = Section_Page.Columns[0];
  214.             Column cc2 = ATA_Page.Columns[0];
  215.  
  216.  
  217.             var cells = cc.ExistingCells.ToArray();
  218.             var cells2 = cc2.ExistingCells.ToArray();
  219.  
  220.             Regex regex = new Regex(@"^[0-9]?[0-9]-[0-9][0-9]$");
  221.             string[] token;
  222.             string indice = "";
  223.             // var ar = MPD_Page.Columns[0].ExistingCells.ToArray() ;
  224.             int colN = MPD_Page.Columns[0].ExistingCells.ToArray().Length;
  225.             for (int i = 2; i < colN; i++)
  226.             {
  227.                 indice = "B" + i.ToString();
  228.  
  229.  
  230.  
  231.                 if (regex.IsMatch(MPD_Page.Cells[indice].Value.ToString()))
  232.                 {
  233.                     token = MPD_Page.Cells[indice].Value.ToString().Split('-');
  234.                     if (!cells.Any(x => x.DisplayText == token[0]) || !cells2.Any(x => x.DisplayText == token[1]))
  235.                     {
  236.  
  237.                         MPD_Page.Cells[indice].FillColor = Color.Red;
  238.                     }
  239.  
  240.                 }
  241.                 else
  242.                 {
  243.                     MPD_Page.Cells[indice].FillColor = Color.Red;
  244.                 }
  245.  
  246.             }
  247.         }
  248.         static async Task taskValidation()
  249.         {
  250.             Column cc = MPD_Page.Columns[2];
  251.             var regexStrings = Carte_Page.Columns[0].ExistingCells.ToArray();
  252.  
  253.             var cells = cc.ExistingCells.ToArray();
  254.  
  255.  
  256.             string[] cellsValue = new string[cells.Length];
  257.             string[] cellsValueReversed = new string[cells.Length];
  258.             for (int i = 0; i < cells.Length; i++)
  259.             {
  260.                 cellsValue[i] = cells[i].Value.ToString();
  261.                 cellsValueReversed[i] = cells[i].Value.ToString();
  262.             }
  263.  
  264.             Array.Reverse(cellsValueReversed);
  265.  
  266.  
  267.             string indice = "";
  268.  
  269.             Regex[] regexS = new Regex[regexStrings.Length];
  270.             int regexS_length = 0;
  271.             for (int i = 1; i < regexStrings.Length; i++)
  272.             {
  273.  
  274.                 if (regexStrings[i].Value.ToString() != "")
  275.                     regexS[regexS_length++] = new Regex(regexStrings[i].Value.ToString());
  276.             }
  277.  
  278.  
  279.             //  Regex regex = new Regex(@"^[0-9]{6}-[0-9]{2}-[0-9]{1}$");
  280.             for (int i = 1; i < cells.Length; i++)
  281.             {
  282.                 indice = "C" + (i + 1).ToString();
  283.  
  284.                 if (Array.IndexOf(cellsValue, cellsValue[i]) != (cells.Length - Array.IndexOf(cellsValueReversed, cellsValue[i])) - 1)
  285.                 {
  286.                     MPD_Page.Cells[indice].FillColor = Color.Red;
  287.                     continue;
  288.                 }
  289.  
  290.  
  291.                 MPD_Page.Cells[indice].FillColor = Color.Red;
  292.                 for (int j = 0; j < regexS_length; j++)
  293.                 {
  294.                     if (regexS[j].IsMatch(cells[i].Value.ToString()))
  295.                     {
  296.                         MPD_Page.Cells[indice].FillColor = Color.White;
  297.                         break;
  298.                     }
  299.                 }
  300.  
  301.  
  302.  
  303.  
  304.  
  305.             }
  306.  
  307.  
  308.         }
  309.         static async Task mrbrValidation()
  310.         {
  311.             Column cc = MPD_Page.Columns[3];
  312.             var regexStrings = MRBR_Page.Columns[5].ExistingCells.ToArray();
  313.  
  314.             var cells = MPD_Page.Columns[3].ExistingCells.ToArray();
  315.  
  316.             Regex[] regexS = new Regex[regexStrings.Length - 1];
  317.             int regexS_length = 0;
  318.             for (int i = 1; i < regexStrings.Length; i++)
  319.             {
  320.  
  321.                 if (regexStrings[i].Value.ToString() != "")
  322.                     regexS[regexS_length++] = new Regex(regexStrings[i].Value.ToString());
  323.             }
  324.  
  325.             string indice = "";
  326.  
  327.  
  328.             for (int i = 1; i < cells.Length; i++)
  329.             {
  330.                 indice = "D" + (i + 1).ToString();
  331.  
  332.                 /*
  333.                 if (Array.IndexOf(cellsValue, cellsValue[i]) != (cells.Length - Array.IndexOf(cellsValueReversed, cellsValue[i])) - 1)
  334.                 {
  335.                     MPD_Page.Cells[indice].FillColor = Color.Red;
  336.                     continue;
  337.                 } */
  338.  
  339.                 string[] elemnts;
  340.                 MPD_Page.Cells[indice].FillColor = Color.Red;
  341.  
  342.                 for (int j = 0; j < regexS_length; j++)
  343.                 {
  344.                     elemnts = cells[i].Value.ToString().Split('\n');
  345.                     foreach (var item in elemnts)
  346.                     {
  347.                         if (regexS[j].IsMatch(item))
  348.                         {
  349.                             MPD_Page.Cells[indice].FillColor = Color.White;
  350.                             break;
  351.                         }
  352.                     }
  353.  
  354.  
  355.  
  356.  
  357.                 }
  358.  
  359.  
  360.  
  361.  
  362.  
  363.             }
  364.         }
  365.  
  366.         static async Task revisionValidationCell(Cell cell)
  367.         {
  368.             if (cell.ColumnIndex != 0)
  369.                 return;
  370.  
  371.             if (cell.Value.ToString() == "" || cell.Value.ToString() == "R" || cell.Value.ToString() == "N" || cell.Value.ToString() == "D")
  372.                 cell.FillColor = Color.White;
  373.             else cell.FillColor = Color.Red;
  374.         }
  375.         static async Task sectionValidationCell(Cell cell)
  376.         {
  377.             if (cell.ColumnIndex != 1)
  378.                 return;
  379.             Column cc = Section_Page.Columns[0];
  380.             Column cc2 = ATA_Page.Columns[0];
  381.  
  382.  
  383.             var cells = cc.ExistingCells.ToArray();
  384.             var cells2 = cc2.ExistingCells.ToArray();
  385.             Regex regex = new Regex(@"^[0-9]?[0-9]-[0-9][0-9]$");
  386.  
  387.             string[] token;
  388.             if (regex.IsMatch(cell.Value.ToString()))
  389.             {
  390.                 token = cell.Value.ToString().Split('-');
  391.                 if (!cells.Any(x => x.DisplayText == token[0]) || !cells2.Any(x => x.DisplayText == token[1]))
  392.                     cell.FillColor = Color.Red;
  393.                 else cell.FillColor = Color.White;
  394.             }
  395.             else
  396.                 cell.FillColor = Color.Red;
  397.         }
  398.     }
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement