Пример #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            BrokenRulesDisplay.ResetBrokenRules();
            Alert alert = new Alert(BrokenRulesDisplay);
            bool canSave = true;

            #region Error Checking

            // Check if a stack is selected
            if (lstSwitches.SelectedIndex < 0)
            {
                alert.AddError("Select Stack Error", "Both a device and a VLAN must be selected before saving the record.");
                canSave = false;
            }

            // Check if the selected VoIP VLAN is used as a Native or Tagged on any interfaces
            if (canSave && lstVLANs.SelectedIndex != 0)
            {
                string query = @"SELECT COUNT(*)
                             FROM InterfaceVLANs
                             WHERE VLANID = " + lstVLANs.SelectedValue;
                int matches = int.Parse(Risque.Utility.SqlHelper.GetSingleSqlValue(query, sdsSwitches.ConnectionString));

                if (matches != 0)
                {
                    alert.AddError("In Use Error", "This VLAN is used elsewhere. A VoIP VLAN cannot be used as a tagged or native VLAN.");
                    canSave = false;
                }
            }

            #endregion Error Checking

            if (canSave)
            {
                // Get the Stack's properties.
                DeviceManagementGroup dmg = DeviceManagementGroup.GetByIdentification(int.Parse(lstSwitches.SelectedValue));

                // Assign the VoIP VLAN to the stack.
                dmg.VoIPVLANID = lstVLANs.SelectedIndex != 0 ? (int?) int.Parse(lstVLANs.SelectedValue) : null;

                // Update the VLAN to be a VoIP Vlan
                if (lstVLANs.SelectedIndex != 0)
                {
                    Vlan v = Vlan.GetByIdentification(int.Parse(lstVLANs.SelectedValue));
                    v.IsVoIP = true;
                    v.Save();
                }

                // Save settings & display success mesage.
                dmg.Save();
                alert.AddSuccess("Success", "Successfully associated device " + lstSwitches.SelectedItem + " with VLAN " + lstVLANs.SelectedItem + ".");
            }

            alert.ShowBrokenRules();
        }
Пример #2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            var alert = new Alert(BulkUploadBrokenRulesDisplay);
            bool valid = true;

            // get file
            Stream csvFile = uplPICs.PostedFile.InputStream;
            var csvName = uplPICs.PostedFile.FileName;

            //
            if (csvName == string.Empty)
            {
                valid = false;
                alert.AddError("No file", "Please select a file and click Upload CSV File.");
            }

            // check size
            if (valid && uplPICs.PostedFile.ContentLength >= 35840)
            {
                valid = false;
                alert.AddError("Too large", "File size is too large. Files must be smaller than 35 KB.");
            }

            // check extension
            if (valid)
            {
                string[] fileExt = csvName.Split('.');
                string ext = fileExt[fileExt.Length - 1];

                if (ext.ToLower() != "csv")
                {
                    valid = false;
                    alert.AddError("Not CSV", "File uploaded must have an extension of \".csv\".");
                }
            }
            // Create StreamReader
            StreamReader sr = new StreamReader(csvFile);
            try
            {
                if (valid)
                {
                    int i = 0;
                    string line;
                    // Keep track of PICS to deduplicate
                    List<string> validPiCs = new List<string>();

                    // ENTER readline loop
                    while ((line = sr.ReadLine()) != null)
                    {
                        // check line
                        if (line.Equals(string.Empty) || i == 0)
                        {
                            i++;
                            continue;
                        }

                        String strpattern = "[0-9a-z,A-Z\t\v\r\n]";
                        if (!Regex.IsMatch(line, strpattern))
                        {
                            valid = false;
                            alert.AddError("Line invalid", "Line " + (i + 1) + " is invalid.");
                            continue;
                        }
                        //--Split the Line into an Array of Strings using Commas
                        string[] values = line.Split(Convert.ToChar(","));

                        //--Validate Line Numbers
                        String strlinepattern = "^[0-9]+$";
                        if (!Regex.IsMatch(values[0], strlinepattern))
                        {
                            valid = false;
                            alert.AddError("Invalid line number", "Line number at line " + i + " is invalid.");
                        }
                        //Run validation to ensure the line items are in the correct format
                        if (!CheckLine_csv(values, alert, validPiCs))
                        {
                            valid = false;
                        }
                        i++;
                    }
                    if (!validPiCs.Any())
                    {
                        valid = false;
                        alert.AddWarning("No Data", "There were no records in the bulk upload file to be processed.");
                    }

                    if (valid)
                    {
                        i = 0;
                        // Passed checkCSVLine Method -- So add to Line Items
                        csvFile.Seek(0, SeekOrigin.Begin); // Start at the beginning
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Equals(string.Empty) || i == 0)
                            {
                                i++;
                                continue;
                            }
                            //--Fix Excel Weirdness and smart single quotes and apostrophe--//
                            line = Regex.Replace(line, "[\u2018\u2019\u201A]", "'");
                            //--Smart double quotes
                            line = Regex.Replace(line, "[\u201C\u201D\u201E]", "\"");
                            //--Ellipsis
                            line = Regex.Replace(line, "[\u2026\uFFFD]", "...");
                            //--Split line into array using comma
                            string[] values = line.Split(Convert.ToChar(","));
                            //--Add to line items!
                            AddLine_csv(values);
                            i++;
                        }
                    } // END of Readline Loop
                }
            }
            catch
            {
                valid = false;
                alert.AddError("Critical error", "The file submitted includes a critical error and cannot be validated.");
            }
            finally
            {
                sr.Close(); //Close the stream reader
            }
            if (valid)
            {
                alert.AddSuccess("Success", "The items from the uploaded file have been added to this ticket successfully.");
            }
            //Bind The GridViews and Datatables
            BindAmdLineItems();
            BindRepairLineItems();
            alert.ShowBrokenRules();
            //Close the intial Stream
            csvFile.Close();
        }