コード例 #1
0
ファイル: SwitchVoIPVLAN.cs プロジェクト: drewjst/Risque
        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
ファイル: TicketDetail.aspx.cs プロジェクト: drewjst/Risque
        /// <summary>
        ///     Edit Line Item Checked Changed event method.
        ///     This Event allows the user to change the current settings and billing plans
        ///     <param name="isAdmin">User has Ticket Admin Permissions</param>
        ///     <paramref name="isSubmitter">User is the original Submitter</paramref>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void chkItemEdit_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkItemEdit = (CheckBox)sender;
            var ticket = getTicket();
            var isAdmin = AuthorizationProvider.HasPermission("TicketAdmin");
            var isSubmitter = ticket.CreatedBy == RisqueContext.CurrentUser.Identification;

            /*Grab All Controls within the gridview row repeater*/
            var row = chkItemEdit.NamingContainer as GridViewRow;
            var line = getLineItem(ticket, row);

            var pnlItemTaggedVlans = row.FindControl("pnlItemTaggedVLANs") as Panel;
            var pnlItemOldServices = row.FindControl("pnlItemOldServices") as Panel;
            var pnlItemServices = row.FindControl("pnlItemServices") as Panel;
            var pnlItemBilling = row.FindControl("pnlItemBilling") as Panel;
            var pnlItemAccount = row.FindControl("pnlItemAccount") as Panel;
            var pnlNewVoIPVlan = (Panel)row.FindControl("pnlNewVoIPVlan");

            var lblItemNewSpeed = row.FindControl("lblItemNewSpeed") as Label;
            var lblItemNewVLANLabel = row.FindControl("lblItemNewVLANLabel") as Label;
            var lblItemNewVLAN = row.FindControl("lblItemNewVLAN") as Label;
            var lblItemTaggedVLANs = row.FindControl("lblItemTaggedVLANs") as Label;
            var lblItemOldServices = row.FindControl("lblItemOldServices") as Label;
            var lblItemServices = row.FindControl("lblItemServices") as Label;
            var lblNewVoIPVlan = (Label)row.FindControl("lblNewVoIPVlan");

            var litAccountNumbers = row.FindControl("litAccountNumbers") as Literal;

            var ddlItemNewSpeed = row.FindControl("ddlItemNewSpeed") as GroupDropDownList;
            var ddlItemNewVLAN = row.FindControl("ddlItemNewVLAN") as DropDownList;
            var ddlItemBilling = row.FindControl("ddlItemBilling") as DropDownList;
            var ddlAccountType = row.FindControl("ddlAccountType") as DropDownList;

            var lstItemTaggedVLANs = row.FindControl("lstItemTaggedVLANs") as ListBox;
            var lstItemServices = row.FindControl("lstItemServices") as ListBox;

            var txtAcct1 = row.FindControl("txtAcct1") as TextBox;
            var txtAcct2 = row.FindControl("txtAcct2") as TextBox;
            var txtAcct3 = row.FindControl("txtAcct3") as TextBox;

            if (((isSubmitter && ticket.StatusID == 1) || (isAdmin && ticket.StatusID <= 4)) && line.ActionID < 4)
            {
                // Submitted and Status 1 / OR / admin and status before pending billing and NOT a repair.
                if (chkItemEdit.Checked)
                {
                    pnlItemTaggedVlans.Visible = true;
                    pnlItemServices.Visible = true;
                    pnlItemAccount.Visible = true;

                    ddlItemNewSpeed.Visible = true;
                    ddlItemNewVLAN.Visible = true;
                    lstItemServices.Visible = true;
                    lstItemTaggedVLANs.Visible = true;

                    lblItemNewSpeed.Visible = false;
                    lblItemNewVLAN.Visible = false;
                    lblItemServices.Visible = false;
                    lblItemTaggedVLANs.Visible = false;

                    litAccountNumbers.Visible = false;

                    // Load dropdown data
                    List<VlanList.SimpleVLAN> vlans = new List<VlanList.SimpleVLAN>();

                    // new speed and vlan
                    Interface pic = Interface.GetByIdentification(line.InterfaceID);

                    ddlItemNewSpeed.Items.Clear();
                    ddlItemNewSpeed.Items.Insert(0, "");

                    // set speed option groups based on pic ID and speed type "is standard"
                    ddlItemNewSpeed.AddItemGroup("Standard");
                    foreach (var speed in InterfaceSpeedList.GetValidSpeedsByInterface(pic, true))
                    {
                        ddlItemNewSpeed.Items.Add(new ListItem(speed.Name, speed.Identification.ToString()));
                    }
                    ddlItemNewSpeed.AddItemGroup("Non-Standard");

                    foreach (var speed in InterfaceSpeedList.GetValidSpeedsByInterface(pic, false))
                    {
                        ddlItemNewSpeed.Items.Add(new ListItem(speed.Name, speed.Identification.ToString()));
                    }

                    ddlItemNewSpeed.SelectedValue = line.SpeedID.ToString();

                    // new vlan
                    vlans = VlanList.GetAllowedByLocation(pic.Device.Room.LocationID);

                    ddlItemNewVLAN.DataSource = vlans;
                    ddlItemNewVLAN.DataTextField = "FriendlyName";
                    ddlItemNewVLAN.DataValueField = "Identification";
                    ddlItemNewVLAN.DataBind();
                    ddlItemNewVLAN.Items.Insert(0, "");

                    foreach (var vlan in line.LineItemVLANs)
                    {
                        var li = new ListItem(null, vlan.VLANName);
                        if (vlan.IsNative && !vlan.IsOld)
                        {
                            if (ddlItemNewVLAN.Items.FindByText(li.Text) != null)
                            {
                                ddlItemNewVLAN.SelectedValue = vlan.Vlanid.ToString();
                                break;
                            }
                        }
                    }

                    // Tagged VLAN(s)
                    lstItemTaggedVLANs.DataSource = vlans;
                    lstItemTaggedVLANs.DataTextField = "FriendlyName";
                    lstItemTaggedVLANs.DataValueField = "Identification";
                    lstItemTaggedVLANs.DataBind();
                    // Set tagged VLAN(s)
                    var tagged = new List<string>();
                    foreach (var vlan in line.LineItemVLANs)
                    {
                        if (!vlan.IsNative && !vlan.IsOld)
                            tagged.Add(vlan.Vlanid.ToString());
                    }

                    foreach (ListItem vlan in lstItemTaggedVLANs.Items)
                    {
                        vlan.Selected = tagged.Contains(vlan.Value);
                    }

                    // Services
                    lstItemServices.DataSource = ServiceList.FetchAll();
                    lstItemServices.DataTextField = "Name";
                    lstItemServices.DataValueField = "Identification";
                    lstItemServices.DataBind();

                    var services = new List<string>();
                    foreach (var service in line.LineItemServices)
                    {
                        if (!service.IsOld)
                            services.Add(service.ServiceID.ToString());
                    }

                    foreach (ListItem service in lstItemServices.Items)
                        service.Selected = services.Contains(service.Value);

                    if (isAdmin)
                    {
                        // billing plan
                        pnlItemBilling.Visible = true;
                        ddlItemBilling.DataSource = BillingPlanList.GetAll();
                        ddlItemBilling.DataTextField = "Name";
                        ddlItemBilling.DataValueField = "Identification";
                        ddlItemBilling.DataBind();
                        ddlItemBilling.Items.Insert(0, "");

                        if (line.BillingPlanID != null)
                            ddlItemBilling.SelectedValue = line.BillingPlanID.ToString();
                    }

                    // account types from database table
                    ddlAccountType.DataSource = AccountTypeList.FetchAll();
                    ddlAccountType.DataTextField = "Name";
                    ddlAccountType.DataValueField = "Identification";
                    ddlAccountType.DataBind();
                    ddlAccountType.SelectedValue = line.AccountTypeID.ToString();

                    switch (ddlAccountType.SelectedItem.Text)
                    {
                        case "Business Partner Number":
                            // show bpn fields
                            txtAcct1.Visible = true;
                            txtAcct2.Visible = false;
                            txtAcct3.Visible = false;
                            txtAcct1.Attributes.Add("Placeholder", "BPN");
                            txtAcct1.MaxLength = 10;
                            txtAcct1.Text = line.AccountNumber1; // Set account number text.
                            break;

                        case "Cost Center":
                            txtAcct1.Visible = true;
                            txtAcct2.Visible = true;
                            txtAcct3.Visible = true;
                            txtAcct1.Attributes.Add("Placeholder", "Fund");
                            txtAcct2.Attributes.Add("Placeholder", "Cost Center");
                            txtAcct3.Attributes.Add("Placeholder", "SIO");
                            txtAcct1.MaxLength = 8;
                            txtAcct1.Text = line.AccountNumber1;
                            txtAcct2.Text = line.AccountNumber2;
                            txtAcct3.Text = line.AccountNumber3;
                            break;

                        case "Real Order":
                            txtAcct1.Visible = true;
                            txtAcct2.Visible = true;
                            txtAcct3.Visible = true;
                            txtAcct1.Attributes.Add("Placeholder", "Fund");
                            txtAcct2.Attributes.Add("Placeholder", "Real Order");
                            txtAcct3.Attributes.Add("Placeholder", "Fund Center");
                            txtAcct1.MaxLength = 8;
                            txtAcct1.Text = line.AccountNumber1;
                            txtAcct2.Text = line.AccountNumber2;
                            txtAcct3.Text = line.AccountNumber3;
                            break;

                        case "WBS Element":
                            txtAcct1.Visible = true;
                            txtAcct2.Visible = true;
                            txtAcct3.Visible = false;
                            txtAcct1.Attributes.Add("Placeholder", "WBS");
                            txtAcct2.Attributes.Add("Placeholder", "SIO");
                            txtAcct1.MaxLength = 10;
                            txtAcct1.Text = line.AccountNumber1;
                            txtAcct2.Text = line.AccountNumber2;
                            break;
                    }
                }
                else
                {
                    if (lblItemTaggedVLANs.Text == @"None")
                    {
                        pnlItemTaggedVlans.Visible = false;
                        lblItemNewVLANLabel.Text = @"New&nbsp;VLAN:";
                    }
                    else
                        lblItemNewVLANLabel.Text = @"New&nbsp;Native&nbsp;VLAN:";

                    if ((lblItemServices.Text == "None" && lblItemOldServices.Text == "None") ||
                        (lblItemServices.Text == "None" && !pnlItemOldServices.Visible))
                        pnlItemServices.Visible = false;

                    pnlItemBilling.Visible = false;
                    pnlItemAccount.Visible = false;
                    ddlItemNewSpeed.Visible = false;
                    ddlItemNewVLAN.Visible = false;
                    lstItemServices.Visible = false;
                    lstItemTaggedVLANs.Visible = false;
                    lblItemNewSpeed.Visible = true;
                    lblItemNewVLAN.Visible = true;
                    lblItemServices.Visible = true;
                    lblItemTaggedVLANs.Visible = true;
                    litAccountNumbers.Visible = true;

                    // SAVE ACCOUNT NUMBERS HERE because they're textboxes, and nobody likes a postback after a textbox.
                    // Seriously, I'd rather drink skol vodka than postback after a textbox.
                    var error = false;
                    var alert = new Alert(BrokenRulesDisplay);
                    if (ddlAccountType.SelectedValue == "1")
                    {
                        // cost center
                        long validator;
                        if (txtAcct1.Text.Trim().Length != 8 || !long.TryParse(txtAcct1.Text.Trim(), out validator) ||
                            !LineItem.VerifyNumber("FUND", txtAcct1.Text.Trim()))
                        {
                            error = true;
                            alert.AddError("Bad Fund", "Fund must be a valid 8-digit number.");
                        }
                        if (txtAcct2.Text.Trim().Length != 10 || !long.TryParse(txtAcct2.Text.Trim(), out validator) ||
                            !LineItem.VerifyNumber("COST", txtAcct2.Text.Trim()))
                        {
                            error = true;
                            alert.AddError("Bad Cost Center", "Cost Center must be a valid 10-digit number.");
                        }
                        if ((txtAcct3.Text.Trim().Length != 0 && txtAcct3.Text.Trim().Length != 10) ||
                            (txtAcct3.Text.Trim().Length != 0 && !long.TryParse(txtAcct3.Text.Trim(), out validator)))
                        {
                            error = true;
                            alert.AddError("Bad SIO", "SIO must be a 10-digit number.");
                        }
                    }
                    else if (ddlAccountType.SelectedValue == "2")
                    {
                        // real order
                        long validator;
                        if (txtAcct1.Text.Trim().Length != 8 || !long.TryParse(txtAcct1.Text.Trim(), out validator) ||
                            !LineItem.VerifyNumber("FUND", txtAcct1.Text.Trim()))
                        {
                            error = true;
                            alert.AddError("Bad Fund", "Fund must be a valid 8-digit number.");
                        }
                        if (txtAcct2.Text.Trim().Length != 10 || !long.TryParse(txtAcct2.Text.Trim(), out validator) ||
                            !LineItem.VerifyNumber("ORDER", txtAcct2.Text.Trim()))
                        {
                            error = true;
                            alert.AddError("Bad Real Order", "Real Order must be a valid 10-digit number.");
                        }
                    }
                    else if (ddlAccountType.SelectedValue == "3")
                    {
                        // wbs element
                        long validator;
                        var match = Regex.Match(txtAcct1.Text, @"\bC[.][0-9][0-9][.][0-9][0-9][0-9][0-9][0-9]\b");
                        if (txtAcct1.Text.Trim().Length != 10 || !match.Success ||
                            !LineItem.VerifyNumber("WBS", txtAcct1.Text.Trim().Replace(".", string.Empty)))
                        {
                            error = true;
                            alert.AddError("Bad WBS", "WBS must be a valid 7-digit number.");
                        }
                        if ((txtAcct2.Text.Trim().Length != 0 && txtAcct2.Text.Trim().Length != 10) ||
                            (txtAcct2.Text.Trim().Length != 0 && !long.TryParse(txtAcct2.Text.Trim(), out validator)))
                        {
                            error = true;
                            alert.AddError("Bad SIO", "SIO must be a 10-digit number.");
                        }
                    }
                    else if (ddlAccountType.SelectedValue == "4")
                    {
                        // business partner number
                        long validator;
                        if (txtAcct1.Text.Trim().Length != 7 || !txtAcct1.Text.Trim().StartsWith("3") ||
                            !long.TryParse(txtAcct1.Text.Trim(), out validator))
                        {
                            error = true;
                            alert.AddError("Bad BPN",
                                "Business Partner Number must be a 7-digit number starting with '3'.");
                        }
                    }

                    if (!error) // Save the account numbers now.
                    {
                        // check if any changes were made. if not, we shouldn't bother saving as that would also overwrite the billing plan (maybe someone decided that needed to be changed)
                        if (line.AccountTypeID == int.Parse(ddlAccountType.SelectedValue) && (line.AccountNumber1 == txtAcct1.Text.Trim() ||
                             (line.AccountNumber1 == null && txtAcct1.Text.Trim() == string.Empty)) &&
                            (line.AccountNumber2 == txtAcct2.Text.Trim() ||
                             (line.AccountNumber2 == null && txtAcct2.Text.Trim() == string.Empty)) &&
                            (line.AccountNumber3 == txtAcct3.Text.Trim() ||
                             (line.AccountNumber3 == null && txtAcct3.Text.Trim() == string.Empty)))
                            return;

                        line.AccountTypeID = int.Parse(ddlAccountType.SelectedValue);

                        line.AccountNumber1 = txtAcct1.Text.Trim();

                        line.AccountNumber2 = txtAcct2.Text.Trim() != string.Empty ? txtAcct2.Text.Trim() : null;

                        line.AccountNumber3 = txtAcct3.Text.Trim() != string.Empty ? txtAcct3.Text.Trim() : null;

                        // Set Billing Plan
                        LineItem.SetBilling(line);
                        // Save
                        ticket.Save();
                        // Update Labels
                        updateLiteral_Account(line, litAccountNumbers);
                    }
                    else
                    {
                        alert.AddWarning("Not saved",
                            "Account Number changes for the line " + line.Picid +
                            " were not saved due to errors. Other settings were saved successfully. Please try again using valid information.");
                        scrollTop();
                        alert.ShowBrokenRules();
                    }
                }
            }
        }
コード例 #3
0
ファイル: CreateTicket.aspx.cs プロジェクト: drewjst/Risque
        //--Save and Submit all Line Items to be created for Tickets
        protected void btnSave_Click(object sender, EventArgs e)
        {
            // Validate that all required data is present for the current line items state
            List<int> createdTickets = new List<int>();
            Alert alert = new Alert(BrokenRulesDisplay);
            bool needsPriorityConfirmed = false;
            bool canSave = true;

            if (txtContactName.Text.Trim() == string.Empty)
            {
                rfvName.IsValid = false;
                txtContactName.Focus();
                canSave = false;
            }

            if (txtContactPhone.Text.Trim() == string.Empty)
            {
                rfvPhone.IsValid = false;
                txtContactPhone.Focus();
                canSave = false;
            }

            if (txtContactEmail.Text.Trim() == string.Empty)
            {
                rfvEmail.IsValid = false;
                txtContactEmail.Focus();
                canSave = false;
            }

            Match emailMatch = Regex.Match(txtContactEmail.Text.Trim(), @"\b[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\b");

            if (txtContactEmail.Text.Trim() != "" && !emailMatch.Success)
            {
                canSave = false;
                alert.AddError("Bad email", "Contact Email must be a valid email address.");
            }

            if (AmdLineItems.Rows.Count == 0 && RepairLineItems.Rows.Count == 0)
            {
                canSave = false;
                alert.AddError("No items", "A ticket must have at least one line item before being submitted.");
            }
            // save priority and comments to datatable then check if required fields are present
            PreservePriorityAndComments();
            //
            foreach (RepeaterItem item in rptBuildings.Items)
            {
                HiddenField rowLocationId = (HiddenField)item.FindControl("rowLocationID");
                RadioButton rdoPriorityRush = (RadioButton)item.FindControl("rdoPriorityRush");
                RadioButton rdoPriorityScheduled = (RadioButton)item.FindControl("rdoPriorityScheduled");

                if (rdoPriorityRush.Checked)
                {   // Rush Priority
                    needsPriorityConfirmed = true;

                    TextBox txtRushRationale = (TextBox)item.FindControl("txtRushRationale");
                    string validateLength = txtRushRationale.Text.Trim();
                    validateLength = validateLength.Replace("\r\n", " ");

                    Match match = Regex.Match(validateLength, @"^((\b[a-zA-Z.]{1,40}\b).*){3,}$");

                    if (!match.Success)
                    {
                        canSave = false;
                        alert.AddError("Needs rush rationale", "Rush Priority Rationale for building " + Location.GetByIdentification(int.Parse(rowLocationId.Value)).ShortName + " must contain at least 3 words.");
                    }
                }
                else if (rdoPriorityScheduled.Checked)
                {    // Scheduled Priority
                    needsPriorityConfirmed = true;
                    TextBox txtScheduledDate = (TextBox)item.FindControl("txtScheduledDate");
                    TextBox txtScheduledTime = (TextBox)item.FindControl("txtScheduledTime");
                    DateTime scheduled;

                    if (txtScheduledDate.Text == "" || txtScheduledTime.Text == "")
                    {
                        canSave = false;
                        alert.AddError("Needs date", "Scheduled Date and Time for building " + Location.GetByIdentification(int.Parse(rowLocationId.Value)).ShortName + " must be a valid date and time.");
                    }
                    else if (DateTime.TryParse(txtScheduledDate.Text.Trim() + " " + txtScheduledTime.Text.Trim(), out scheduled))
                    {
                        if (DateTime.Now.AddDays(Ticket.GetNumberBusinessDaysFromDate(DateTime.Now, 3)) > scheduled)
                        {
                            canSave = false;
                            alert.AddError("Needs date", "Scheduled Date and Time for building " + Location.GetByIdentification(int.Parse(rowLocationId.Value)).ShortName + " must be at least 3 business days from now.");
                        }
                    }
                }
            }
            if (needsPriorityConfirmed)
            {
                if (!chkPriorityConfirm.Checked)
                {
                    canSave = false;
                    alert.AddError("Needs priority confirmed", "You must acknowledge the 3-day business rule before submitting this ticket.");
                }
            }

            if (canSave)
            {
                foreach (RepeaterItem building in rptBuildings.Items)
                {
                    HiddenField rowLocationId = (HiddenField)building.FindControl("rowLocationID");
                    DataRow[] lineItemRow = AmdBuildings.Select("LocationID = " + rowLocationId.Value);

                    // Create Ticket and set values in the database, is populated from <amdLineItems>
                    foreach (DataRow row in lineItemRow)
                    {
                        // Create a new ticket for each building
                        Ticket ticket = Ticket.NewTicket();

                        // Populate Contact Data and Status
                        PopulateTicketGeneralData(ticket);

                        // Set ticket priority <amdLineItem>
                        if (row["PriorityID"] != DBNull.Value)
                            ticket.PriorityID = (int)row["PriorityID"];
                        else
                            ticket.PriorityID = 1;

                        // Rush rationale as comment, also set due date <amdLineItem>
                        if (ticket.PriorityID == 2)
                        {
                            Comment rush = ticket.Comments.AddNew();
                            rush.ClientName = RisqueContext.CurrentUser.FullName;
                            rush.IsInternal = false;
                            rush.Text = "Rationale for Rush priority: " + row["RushRationale"];
                            ticket.DueDate = DateTime.Now.AddDays(Ticket.GetNumberBusinessDaysFromDate(DateTime.Now, 1));
                        }
                        else
                        {
                            ticket.DueDate = DateTime.Now.AddDays(Ticket.GetNumberBusinessDaysFromDate(DateTime.Now, 3));
                        }

                        // Set Schedule Date <amdLineItem>
                        if (ticket.PriorityID == 3)
                            ticket.ScheduledDate = (DateTime?) row["ScheduledDate"];

                        // Comments amdLineItem>
                        if (row["Comment"].ToString() != string.Empty)
                        {
                            Comment comment = ticket.Comments.AddNew();
                            comment.ClientName = RisqueContext.CurrentUser.FullName;
                            comment.IsInternal = false;
                            comment.Text = row["Comment"].ToString();
                        }
                        bool isAccountChangeOnly = true;
                        bool isStandard          = true;
                        bool changeToStandard    = false;
                        bool addEngineerNote     = false;
                        bool addVoiceVlanNote    = false;

                        // Line Items (Activate / Modify / Deactivate)
                        foreach (DataRow drLineItem in AmdLineItems.Select("LocationID = " + rowLocationId.Value))
                        {
                            // Create a New Line Item for the Ticket.
                            LineItem lineItemPic = ticket.LineItems.AddNew();
                            // Check if anything has changed outside of billing. If so -- it is no long an account change only line item.
                            if ((int)drLineItem["ActionID"] == 3 || !(bool)drLineItem["IsOnlyAccountChange"])
                                isAccountChangeOnly = false;

                            // Populate from DataTable.
                            lineItemPic.ActionID = (int) drLineItem["ActionID"];
                            lineItemPic.Picid = drLineItem["PICID"].ToString();
                            lineItemPic.InterfaceID = (int) drLineItem["InterfaceID"];
                            lineItemPic.IsDone = isAccountChangeOnly;

                            // If the LineItem is not a Phone Only Connection -- Do a Normal Data Ticket -- Else add Phone Only Values
                            if ((bool?) drLineItem["IsVoIP"] == false)
                            {
                                // Set new native vlan(s) for the line item.
                                if (drLineItem["NativeVLAN"] != DBNull.Value)
                                    LineItemVLAN.SaveNewNativeVlan(lineItemPic, drLineItem);

                                // Set new tagged VLAN(s) for the the line item.
                                if (drLineItem["InterfaceVLANs"] != DBNull.Value)
                                    LineItemVLAN.SaveNewTaggedVlans(lineItemPic, drLineItem);

                                // If an Activate there are no current tagged vlan(s) to set.
                                if (!lineItemPic.ActionID.Equals(1))
                                {
                                    Interface currentInterface = Interface.GetByIdentification(lineItemPic.InterfaceID);

                                    // Save current native vlan to the ticket line item.
                                    LineItemVLAN.SaveCurrentNativeVlan(currentInterface, lineItemPic);

                                    // Save current tagged vlan to the ticket line item.
                                    LineItemVLAN.SaveCurrentTaggedVlans(currentInterface, lineItemPic);

                                    // Save current voip vlan(if any) to the ticket line item.
                                    LineItemVLAN.SaveCurrentVoipVlan(currentInterface, lineItemPic);
                                }

                                // Set Data Service Assignments
                                if (drLineItem["InterfaceServiceAssignments"] != DBNull.Value)
                                {
                                    string[] serviceNames =
                                        drLineItem["ServiceNames"].ToString()
                                            .Split(new[] {"<br />"}, StringSplitOptions.None);
                                    List<int> serviceIDs = (List<int>) drLineItem["InterfaceServiceAssignments"];

                                    for (var i = 0; i < serviceIDs.Count; i++)
                                    {
                                        LineItemService service = lineItemPic.LineItemServices.AddNew();
                                        service.ServiceID = serviceIDs[i];
                                        service.ServiceName = serviceNames[i];
                                        service.IsOld = false;

                                        // Add Engineer Note
                                        if (service.ServiceName == "Port Channel" ||
                                            service.ServiceName == "BPDU Guard Disable")
                                            addEngineerNote = true;

                                        if (service.ServiceName == "Voice VLAN") // Add voice VLAN Note
                                            addVoiceVlanNote = true;
                                    }
                                }
                                // Set Data Ticket Billing Data,
                                if (drLineItem["AccountTypeID"] != DBNull.Value)
                                    lineItemPic.AccountTypeID = drLineItem["AccountTypeID"] as int?;

                                if (drLineItem["AccountNumber1"] != DBNull.Value)
                                    lineItemPic.AccountNumber1 = drLineItem["AccountNumber1"].ToString();

                                if (drLineItem["AccountNumber2"] != DBNull.Value)
                                    lineItemPic.AccountNumber2 = drLineItem["AccountNumber2"].ToString();

                                if (drLineItem["AccountNumber3"] != DBNull.Value)
                                    lineItemPic.AccountNumber3 = drLineItem["AccountNumber3"].ToString();

                                if (drLineItem["InterfaceSpeedID"] != DBNull.Value)
                                {
                                    lineItemPic.SpeedID = (int) drLineItem["InterfaceSpeedID"];
                                    lineItemPic.SpeedName = drLineItem["SpeedName"].ToString();

                                    // Set Billing Plan if Interface speed exists
                                    LineItem.SetBilling(lineItemPic);
                                }
                            }
                            // Set IsVOIP Data -> 'Phone Only Connection'
                            else
                            {
                                // If the line item was voip and cisco and it is still a phone only connection then its an account change only.
                                if (_containsVoIp && _containsCisco)
                                    isAccountChangeOnly = true;
                                else
                                    isAccountChangeOnly = false;
                                        // Changed to phone only. Won't be an account change only

                                lineItemPic.IsDone = false;

                                // Set Default values for a Phone Only Connection.
                                LineItem.SetPhoneOnlyLineItem(lineItemPic, isAccountChangeOnly);

                                // If PIC is not an activate. Set current VLAN(s) for the line item.
                                if (!lineItemPic.ActionID.Equals(1))
                                {
                                    Interface currentInterface = Interface.GetByIdentification(lineItemPic.InterfaceID);
                                    LineItemVLAN.SaveCurrentNativeVlan(currentInterface, lineItemPic);
                                    LineItemVLAN.SaveCurrentTaggedVlans(currentInterface, lineItemPic);
                                }

                                // Set VoIP Billing Data
                                if (drLineItem["AccountTypeID"] != DBNull.Value)
                                    lineItemPic.AccountTypeID = (int?) drLineItem["AccountTypeID"];

                                if (drLineItem["AccountNumber1"] != DBNull.Value)
                                    lineItemPic.AccountNumber1 = drLineItem["AccountNumber1"].ToString();

                                if (drLineItem["AccountNumber2"] != DBNull.Value)
                                    lineItemPic.AccountNumber2 = drLineItem["AccountNumber2"].ToString();

                                if (drLineItem["AccountNumber3"] != DBNull.Value)
                                    lineItemPic.AccountNumber3 = drLineItem["AccountNumber3"].ToString();

                                // Set current billg plan.
                                LineItem.SetBilling(lineItemPic);

                                // Populate the Switch VOIP Vlan Value if it exists
                                if ((int) drLineItem["ActionID"] == 2 || (int) drLineItem["ActionID"] == 1)
                                    PopSwitchVoIp(lineItemPic);
                            }

                            // If previous BillingPlan was saved -- Check if it has changed from Premium to Standard Account
                            if (drLineItem["prevBillingPlanID"] != DBNull.Value)
                            {
                                // Check if billing plan has changed from Premium to a Standard.  If so update changeToStandard to get sent to billing
                                if ((int) lineItemPic.BillingPlanID != (int) drLineItem["prevBillingPlanID"] && lineItemPic.BillingPlanID == 16)
                                    changeToStandard = true;
                            }
                            //Check Billing Plan 16 = 'DTCSTANDARD'
                            if (lineItemPic.BillingPlanID != 16)
                                isStandard = false;

                            if (drLineItem["isTrunk"] != DBNull.Value)
                            {
                                if ((bool) drLineItem["isTrunk"])
                                {
                                    Comment trunkNote = ticket.Comments.AddNew();
                                    trunkNote.ClientName = "Risque System";
                                    trunkNote.IsInternal = true;
                                    trunkNote.Text = lineItemPic.Picid + ": is <b>Trunk.</b>";
                                }
                            }
                            AddCurrentSettingsToLine(lineItemPic); // Populate current PIC settings
                        } // END AMD LINE ITEM FOREACH LOOP //

                        if (addEngineerNote)
                        {
                            Comment note = ticket.Comments.AddNew();
                            note.ClientName = "Risque System";
                            note.IsInternal = true;
                            note.Text = "Please assign this ticket directly to an engineer.";
                        }

                        if (addVoiceVlanNote)
                        {
                            Comment note = ticket.Comments.AddNew();
                            note.ClientName = "Risque System";
                            note.IsInternal = true;
                            note.Text = "Please verify the voice VLAN for this TR and update links accordingly.";
                        }

                        // Ticket goes to Billing if there it is an account change only.
                        if (isAccountChangeOnly)
                        {
                            //--Update Interface Account Information if the Ticket is an Account Only Change
                            Interface intrface;  // Create Objects
                            LineItem pic = new LineItem();
                            for (var i = 0; i < ticket.LineItems.Count; i++)
                            {

                                pic = ticket.LineItems[i];
                                intrface = Interface.GetByIdentification(pic.InterfaceID);
                                // --- Update Billing Plan & Account Number Interface Data Upon Data Ticket Approval --- //
                                switch (pic.ActionID)
                                {
                                    case 1: // Activate
                                    {
                                        ManageAccounts(pic, intrface);
                                        break;
                                    }
                                    case 2: // Modify
                                    {
                                        ManageAccounts(pic, intrface);
                                        break;
                                    }
                                    case 3: // Deactivate
                                    {
                                        intrface.BillingPlanID = null;
                                        intrface.AccountFund = null;
                                        intrface.AccountCost = null;
                                        intrface.AccountOrder = null;
                                        intrface.AccountWBS = null;
                                        intrface.AccountSIO = null;
                                        intrface.AccountFundCenter = null;
                                        intrface.AccountBusinessPartner = null;
                                        intrface.InterfaceSpeedID = null;
                                        intrface.Save();
                                        break;
                                    }
                                    case 4: // Repair
                                        //No Changes to Billing
                                        break;
                                    default:
                                        continue;
                                }

                            }

                            //If the Billing is Standard ticket goes straight to complete
                            if (changeToStandard)
                            {
                                ticket.StatusID = 5;
                                ticket.EffectiveDate = DateTime.Now;
                            }
                            else if (isStandard)
                            {
                                ticket.StatusID = 6;
                                ticket.EffectiveDate = DateTime.Now;
                            }
                            else
                            {
                                ticket.StatusID = 5;
                                ticket.EffectiveDate = DateTime.Now;
                            }
                        }
                        // Save
                        ticket = ticket.Save();
                        createdTickets.Add(ticket.Identification);
                        // Add to Building Outage Notification List
                        AddToLocationContacts(int.Parse(rowLocationId.Value));
                        //--- Send Email ---//
                        TicketsBusiness.Utility.TicketsMailer.SendMail_CreateTicket(ticket, RisqueContext.CurrentUser);
                    }
                }
                // Iterate through repair line items if they exist
                foreach (DataRow repair in RepairLineItems.Rows)
                {   // Ticket for Repair
                    Ticket ticket = Ticket.NewTicket();

                    // populate contact data and status
                    PopulateTicketGeneralData(ticket);

                    // set as rush priority
                    ticket.PriorityID = 2;

                    // add line item
                    LineItem lineItemPic = ticket.LineItems.AddNew();

                    // populate data from datatable
                    lineItemPic.ActionID    = (int)repair["ActionID"];
                    lineItemPic.Picid       = repair["PICID"].ToString();
                    lineItemPic.InterfaceID = (int)repair["InterfaceID"];
                    lineItemPic.RepairNotes = repair["RepairNotes"].ToString();

                    // Populate Current Settings to PIC
                    AddCurrentSettingsToLine(lineItemPic);

                    // Add Current VLANs
                    LineItemVLAN.SaveCurrentNativeVlan(Interface.GetByIdentification(lineItemPic.InterfaceID), lineItemPic);
                    LineItemVLAN.SaveCurrentTaggedVlans(Interface.GetByIdentification(lineItemPic.InterfaceID), lineItemPic);

                    // Save Repair Notes - To the comments gridview
                    Comment comment    = ticket.Comments.AddNew();
                    comment.ClientName = RisqueContext.CurrentUser.FullName;
                    comment.IsInternal = false;
                    comment.Text       = repair["RepairNotes"].ToString();

                    // Finalize Ticket
                    ticket = ticket.Save();
                    createdTickets.Add(ticket.Identification);

                    //-- add to building outage notification list
                    AddToLocationContacts(Interface.GetByIdentification(lineItemPic.InterfaceID).Device.Room.LocationID);

                    //-- send email
                    TicketsBusiness.Utility.TicketsMailer.SendMail_CreateTicket(ticket, RisqueContext.CurrentUser);
                }
                var ids = string.Empty;
                foreach (int id in createdTickets)
                    ids += id + ",";

                if (createdTickets.Count > 0)
                    ids = ids.Substring(0, ids.Length - 1);

                Response.Redirect("ViewTickets.aspx?created=" + ids, false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }
            else
            {
                ScrollTop();
                alert.ShowBrokenRules();
            }
        }
コード例 #4
0
ファイル: TicketDetail.aspx.cs プロジェクト: drewjst/Risque
        // -- Save Edit Due By Date -- For Ticket Admins ONLY
        protected void btnEditDueBy_Click(object sender, EventArgs e)
        {
            var ticket = getTicket(); // Grab current Ticket Info
            showModal_EditDueBy.Value = "true"; // Show Modal
            var errorChkModal = new Alert(BrokenRulesDisplayEditDueBy);
            BrokenRulesDisplayEditDueBy.ResetBrokenRules(); // Reset Broken Rules
            var isValid = true;

            if (txtEditDueDate.Text.Trim() == string.Empty) //A date must be entered
            {
                errorChkModal.AddError("0", "Please enter a date.");
                isValid = false;
            }
            if (txtEditDueTime.Text.Trim() == string.Empty) //A time must be entered
            {
                errorChkModal.AddError("1", "Please enter a time.");
                isValid = false;
            }

            if ((txtEditDueTime.Text.Trim() != string.Empty || txtEditDueDate.Text.Trim() != string.Empty) &&
                DateTime.Parse(txtEditDueDate.Text + ' ' + txtEditDueTime.Text) < DateTime.Now)
            {
                errorChkModal.AddError("2", "Date and time can not be before " + DateTime.Now + ".");
                isValid = false;
            }
            if (isValid == false)
            {
                //Set Values to default
                var dueDateValues = lblTicketDue.Text.Split(' ');
                txtEditDueDate.Text = dueDateValues[0];
                txtEditDueTime.Text = dueDateValues[1] + ' ' + dueDateValues[2];
                errorChkModal.ShowBrokenRules();
                return;
            }

            if (isValid) // Update new Date/Time
            {
                var newDueDate = DateTime.Parse(txtEditDueDate.Text + ' ' + txtEditDueTime.Text);
                ticket.DueDate = newDueDate;
                if (rdoNewDueDateScheduled_YES.Checked)
                {
                    ticket.ScheduledDate = newDueDate;
                    ticket.PriorityID = 3;
                }
                else
                {
                    ticket.ScheduledDate = null;
                    ticket.PriorityID = 1;
                }

                ticket = ticket.Save();

                lblTicketDue.Text = ticket.ScheduledDate == null
                    ? (ticket.DueDate == null ? "N/A" : ((DateTime)ticket.DueDate).ToString("M/d/yyyy h:mm tt"))
                    : ((DateTime)ticket.ScheduledDate).ToString("M/d/yyyy h:mm tt") + " (s)";
                UpdatePriorityLabel(ticket);
                showModal_EditDueBy.Value = "false";
            }
        }
コード例 #5
0
ファイル: CreateTicket.aspx.cs プロジェクト: drewjst/Risque
        //-- Validate User Input and Values
        private bool VerifyAddLine(TicketsBusiness.Action action)
        {
            // verify data was entered properly
            bool canSave = true;
            Alert alert = new Alert(AddLineBrokenRules);

            if (action.Identification == 1 || action.Identification == 2)
            {
                // activate / modify rules

                // speed is required
                if (ddlSpeed.SelectedIndex == 0)
                {
                    canSave = false;
                    alert.AddError("No Speed", "Speed is a required field.");
                }

                // at least one vlan is required
                if (ddlVLAN.SelectedIndex == 0)
                {
                    canSave = false;
                    alert.AddError("No VLAN", "VLAN is a required field.");
                }

                if (pnlTrunk.Visible)
                {
                    bool dupeVlan = false;
                    foreach (ListItem vlan in lstVLAN.Items)
                    {
                        if (vlan.Selected)
                        {
                            if (ddlVLAN.SelectedIndex > 0 && vlan.Value == ddlVLAN.SelectedValue)
                            {
                                dupeVlan = true;
                                break;
                            }
                        }
                    }
                    if (dupeVlan)
                    {
                        canSave = false;
                        alert.AddError("Duplicate VLAN", "The Native VLAN selected cannot also be selected as a Tagged VLAN. Please ensure all VLAN selections are unique.");
                    }
                }

                // valid account info is required
                if (ddlAccountType.SelectedIndex == 0)
                {
                    canSave = false;
                    alert.AddError("No AccountType", "Account Type is a required field.");
                }
                else
                {
                    if (AcctValidation(alert) == false)
                    {
                        canSave = false;
                    }
                }
            }
            if (!canSave)
                alert.ShowBrokenRules();

            return canSave;
        }
コード例 #6
0
ファイル: CreateTicket.aspx.cs プロジェクト: drewjst/Risque
        // Validate entire line item row within a bulk upload
        private bool CheckLine_csv(string[] values, Alert alert, List<string> validPiCs)
        {
            bool valid = true;
            TicketsBusiness.Action action = null;
            Interface pic = null;
            // check that the line is valid
            /* 0 = Line
             * 1 = Action
             * 2 = PIC
             * 3 = Speed
             * 4 = VLAN
             * 5 = Tagged VLANs
             * 6 = Services
             * 7 = Fund
             * 8 = Cost Center
             * 9 = Real Order
             * 10 = WBS
             * 11 = SIO
             * 12 = BPN
             * 13 = Repair Notes
             * 14 = Phone Only Connection
             */
            // Validate Action
            if (values[1] != string.Empty)
            {
                if (FormatAction_csv(values[1]) == TicketsBusiness.Action.Activate)
                    action = TicketsBusiness.Action.GetByIdentification(1);
                else if (FormatAction_csv(values[1]) == TicketsBusiness.Action.Modify)
                    action = TicketsBusiness.Action.GetByIdentification(2);
                else if (FormatAction_csv(values[1]) == TicketsBusiness.Action.Deactivate)
                    action = TicketsBusiness.Action.GetByIdentification(3);
                else if (FormatAction_csv(values[1]) == TicketsBusiness.Action.Repair)
                    action = TicketsBusiness.Action.GetByIdentification(4);
                else
                {
                    valid = false;
                    alert.AddError("Bad action", "Action value at line  " + values[0] + " is invalid.");
                }
            }
            else
            {
                valid = false;
                alert.AddError("Bad action", "Action value at line " + values[0] + " is required.");
            }
            // Validate PICID
            if (values[2] != string.Empty)
            {
                pic = GetPic(values[2]);
                Ticket existing = pic != null ? LineItem.GetPICInActiveTicket(pic.FriendlyLongName) : null;

                if (pic == null)
                {
                    valid = false;
                    alert.AddError("Bad pic", "PIC ID value at line " + values[0] + " is a PIC that is not in Risque.");
                }
                else if (AmdLineItems.Select("PICID = '" + pic.FriendlyLongName + "'").Length != 0 || RepairLineItems.Select("PICID = '" + pic.FriendlyLongName + "'").Length != 0)
                {
                    //check if PIC is in an existing line already
                    valid = false;
                    alert.AddError("Bad pic", "PIC ID value at line " + values[0] + " is already in a line item below.");
                }
                else if (existing != null)
                {
                    // check if PIC is in an open ticket already
                    valid = false;
                    alert.AddError("Bad pic", "Line " + values[0] + ": There is another open data ticket in the system that is requesting action on this same PIC.  The other ticket number is " + existing.Identification + " and was submitted by " + existing.CreatorName + ".  You may not request action on this PIC until the other ticket has been completed.");
                }
                else if (!InterfaceRestrictionAssignment.IsPICChangeAllowed(pic, RisqueContext.CurrentUser) && !AuthorizationProvider.HasPermission("PICLockBypass"))
                {
                    // check if PIC is locked
                    valid = false;
                    alert.AddError("PIC locked", "The PIC at line " + values[0] + " is locked and changes cannot be submitted by you.");
                }
                else if (pic.Device.DeviceDefinition.DeviceTypeID == 1005 && !AuthorizationProvider.HasPermission("APPICSubmitter"))
                {
                    // check if AP PIC
                    valid = false;
                    alert.AddError("AP PIC", "Sorry, but the PIC at line " + values[0] + " is reserved for use only by ITaP Data Networks personnel. Please select a different PIC ID to proceed.");
                }
                else if (validPiCs.Contains(values[2], StringComparer.InvariantCultureIgnoreCase))
                {
                    valid = false;
                    alert.AddError("Bad pic",
                        "PIC ID: <b>" + values[2] + "</b> at line item <b>" + values[0] +
                        "</b> is duplicated in this file. Please correct the file and try again.");
                }
                else //--Add Valid PICs to a List--//
                    validPiCs.Add(values[2]);
            }
            else
            {
                valid = false;
                alert.AddError("Bad pic", "PIC ID value at line " + values[0] + " is required.");
            }
            // Leave the rest of this method if it is a Phone Only Connection
            if (values[14] == "Y".ToUpperInvariant())
            {
                var roomId = pic.Device.RoomID.ToString();
                var isVoip = string.Empty;
                isVoip = Risque.Utility.SqlHelper.GetSingleSqlValue(@"SELECT location.IsVoip AS VOIP
                                FROM Records.dbo.Rooms AS room
                                JOIN Records.dbo.Locations AS location
                                      ON room.LocationID = location.ID
                                WHERE room.ID = " + roomId + ";", Risque.Utility.SqlHelper.GetConnectionString("Records"));
                if (isVoip != "True")
                {
                    //Return to user -- building is not listed as a VOIP Building in records.
                    alert.AddWarning("Phone Only", "PIC ID: <b>" + values[2] + "</b> at line item <b>" + values[0] + "</b>  is not designated as a VoIP building. Please correct the file and try again.");
                    valid = false;
                    return valid;
                }
                // Check voice only account numbers for activate and modify only.
                if (action != null && (action.Name == "Modify" || action.Name == "Activate"))
                    valid = AcctValidation_csv(values, alert);
                return valid;
            }

            // check if on the default vlan
            var hasDefaultVlan = false;
            foreach (InterfaceVLAN vlan in pic.InterfaceVLANs)
            {
                if (vlan.Vlan.Number == 1)
                {
                    hasDefaultVlan = true;
                    break;
                }
            }

            if (!(pic.InterfaceVLANs.Count == 0 || hasDefaultVlan))
            {
                // PIC is active
                if (action != null && action.Name == TicketsBusiness.Action.Activate)
                {
                    valid = false;
                    alert.AddError("Bad pic", "Cannot " + action.Name + " PIC at line " + values[0] + " because it is already active.");
                }
            }
            else
            {
                // PIC is inactive
                if (action != null && action.Name != TicketsBusiness.Action.Activate)
                {
                    valid = false;
                    alert.AddError("Bad pic", "Cannot " + action.Name + " PIC at line " + values[0] + " because it is inactive.");
                }
            }

            // We have a valid pic so we can check the other fields as well, if activate or modify
            if (action != null && (valid && (action.Identification == 1 || action.Identification == 2)))
            {
                CheckLineSpecialCases_csv(values);

                // validate speed
                if (values[3] != string.Empty)
                {
                    List<string> validSpeed = new List<string> {"1", "2"};

                    // Constructor.
                    IReadOnlyCollection<string> read = new ReadOnlyCollection<string>(validSpeed);

                    InterfaceSpeedList speedMatches = InterfaceSpeedList.GetByCriteria(new InterfaceSpeedCriteria { Name = values[3] });

                    if (speedMatches.Count < 1)
                    {
                        valid = false;
                        alert.AddError("Bad speed", "Speed value at line " + values[0] + " is not a valid speed in Risque.");
                    }
                    else if (speedMatches.Count > 1)
                    {
                        valid = false;
                        alert.AddError("Bad speed", "Speed value at line " + values[0] + " is ambiguous.");
                    }
                    else
                    {
                        // check if speed is valid for this pic
                        bool found = false;
                        InterfaceSpeed speed = speedMatches[0];
                        List<InterfaceSpeed> validSpeeds = InterfaceSpeedList.GetValidSpeedsByInterface(pic);

                        foreach (InterfaceSpeed ispeed in validSpeeds)
                        {
                            if (ispeed.Identification == speed.Identification)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            valid = false;
                            alert.AddError("Bad speed", "Speed value at line " + values[0] + " is invalid for the given PIC.");
                        }
                    }
                }
                else
                {
                    valid = false;
                    alert.AddError("Bad speed", "Speed value at line " + values[0] + " is required.");
                }

                // validate vlans
                if (values[4] != string.Empty)
                {
                    List<Vlan> vlanMatches = VlanList.FetchByFriendlyName(values[4]);

                    if (vlanMatches.Count < 1)
                    {
                        valid = false;
                        alert.AddError("Bad vlan", "VLAN value at line " + values[0] + " contains a VLAN that is not in Risque.");
                    }
                    else if (vlanMatches.Count > 1)
                    {
                        valid = false;
                        alert.AddError("Bad vlan", "VLAN value at line " + values[0] + " contains a VLAN that is ambiguous.");
                    }
                    else
                    {
                        // check if vlan is valid for this pic
                        bool found = false;
                        Vlan match = vlanMatches[0];
                        List<VlanList.SimpleVLAN> validVlans = VlanList.GetAllowedByLocation(pic.Device.Room.LocationID);

                        foreach (VlanList.SimpleVLAN v in validVlans)
                        {
                            if (v.Identification == match.Identification)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            valid = false;
                            alert.AddError("Bad vlan", "VLAN value at line " + values[0] + " contains a VLAN that is invalid for the given PIC.");
                        }
                    }
                }
                else
                {
                    valid = false;
                    alert.AddError("Bad vlan", "VLAN value at line " + values[0] + " is required.");
                }

                // validate tagged vlans
                if (values[5] != string.Empty)
                {
                    string[] vlans = values[5].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();

                    foreach (string vlan in vlans)
                    {
                        if (vlan == values[4])
                        {
                            valid = false;
                            alert.AddError("Bad vlan", "Tagged VLAN(s) value at line " + values[0] + " contains a VLAN that is the same as the native VLAN. Please ensure all VLANs are unique.");
                        }

                        List<Vlan> vlanMatches = VlanList.FetchByFriendlyName(vlan);

                        if (vlanMatches.Count < 1)
                        {
                            valid = false;
                            alert.AddError("Bad vlan", "Tagged VLAN(s) value at line " + values[0] + " contains a VLAN that is not in Risque.");
                        }
                        else if (vlanMatches.Count > 1)
                        {
                            valid = false;
                            alert.AddError("Bad vlan", "Tagged VLAN(s) value at line " + values[0] + " contains a VLAN that is ambiguous.");
                        }
                        else
                        {
                            // check if vlan is valid for this pic
                            bool found = false;
                            Vlan match = vlanMatches[0];
                            List<VlanList.SimpleVLAN> validVlans = VlanList.GetAllowedByLocation(pic.Device.Room.LocationID);

                            foreach (VlanList.SimpleVLAN v in validVlans)
                            {
                                if (v.Identification == match.Identification)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                                alert.AddError("Bad vlan",
                                    "Tagged VLAN(s) value at line " + values[0] +
                                    " contains a VLAN that is invalid for the given PIC.");
                        }
                    }
                }

                // validate services
                if (values[6] != string.Empty)
                {
                    string[] services = values[6].Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray();

                    foreach (string service in services)
                    {
                        ServiceList serviceMatches = ServiceList.GetByCriteria(new ServiceCriteria { Name = service });

                        if (serviceMatches.Count < 1)
                        {
                            valid = false;
                            alert.AddError("Bad service", "Advanced value at line " + values[0] + " contains a service that is not in Risque.");
                        }
                        else if (serviceMatches.Count > 1)
                        {
                            valid = false;
                            alert.AddError("Bad service", "Advanced value at line " + values[0] + " contains a service that is ambiguous.");
                        }
                    }
                }

                // Validate Account Info
                if (AcctValidation_csv(values, alert) == false)
                    valid = false;
            }
            else if (valid && action.Identification == 4)
            {
                // repair validation
                if (values[13] != string.Empty)
                {
                    if (values[13].Length < 10)
                    {
                        valid = false;
                        alert.AddError("Bad repair", "Repair Notes value at line " + values[0] + " must be at least 10 characters.");
                    }
                }
                else
                {
                    valid = false;
                    alert.AddError("Bad repair", "Repair Notes value at line " + values[0] + " is required.");
                }
            }
            return valid;
        }
コード例 #7
0
ファイル: CreateTicket.aspx.cs プロジェクト: drewjst/Risque
        //Validate Account Data
        private static bool AcctValidation_csv(IReadOnlyList<string> accountNums, Alert alert)
        {
            string fund        = accountNums[7]; // Fund
            string costCenter  = accountNums[8]; // Cost Center
            string realOrder   = accountNums[9]; // Real Order
            string wbsElement  = accountNums[10]; // WBS Element
            string siOrder     = accountNums[11]; //Statistical Internal order
            string bpn         = accountNums[12]; // Business Partner Number
            long validator; // Validator for TryParse to determine if it contains all numbers. (Faster than regex).

            // Cost Center
            if (!string.IsNullOrEmpty(fund) && !string.IsNullOrEmpty(costCenter))
            {
                // cost center
                if (fund.Trim().Length != 8 || !long.TryParse(fund.Trim(), out validator) || !LineItem.VerifyNumber("FUND", fund.Trim()))
                {
                    alert.AddError("Bad Fund",
                        "Fund at line " + accountNums[0] + "  must be a valid 8-digit number.");
                    return false;
                }
                if (costCenter.Trim().Length != 10 || !long.TryParse(costCenter.Trim(), out validator) || !LineItem.VerifyNumber("COST", costCenter.Trim()))
                {
                    alert.AddError("Bad Cost Center",
                        "Cost Center at line " + accountNums[0] + "  must be a valid 10-digit number.");
                    return false;
                }
                if ((siOrder.Trim().Length != 0 && siOrder.Trim().Length != 10) || (siOrder.Trim().Length != 0 && !long.TryParse(siOrder.Trim(), out validator)))
                {
                    alert.AddError("Bad SIO",
                        "SIO at line " + accountNums[0] + "  must be a 10-digit number.");
                    return false;
                }
                if (!string.IsNullOrWhiteSpace(bpn) || !string.IsNullOrWhiteSpace(wbsElement) || !string.IsNullOrWhiteSpace(realOrder))
                {
                    alert.AddError("Invalid Account",
                        "Account number at line " + accountNums[0] + " does not match a valid billing scenario.");
                    return false;
                }
            }
            // Real Order
            else if (!string.IsNullOrEmpty(fund) && !string.IsNullOrEmpty(realOrder))
            {
                if (fund.Trim().Length != 8 || !long.TryParse(fund.Trim(), out validator) || !LineItem.VerifyNumber("FUND", fund.Trim()))
                {
                    alert.AddError("Bad Fund", "Fund at line " + accountNums[0] + "  must be a valid 8-digit number.");
                    return false;
                }
                if (realOrder.Trim().Length != 10 || !long.TryParse(realOrder.Trim(), out validator) || !LineItem.VerifyNumber("ORDER", realOrder.Trim()))
                {
                    alert.AddError("Bad Real Order", "Real Order at line " + accountNums[0] + "  must be a valid 10-digit number.");
                    return false;
                }
                if (!string.IsNullOrWhiteSpace(siOrder) || !string.IsNullOrWhiteSpace(bpn) || !string.IsNullOrWhiteSpace(costCenter))
                {
                    alert.AddError("Invalid Account1",
                        "Account number at line " + accountNums[0] + " does not match a valid billing scenario.");
                    return false;
                }
            }
            else if (!string.IsNullOrEmpty(wbsElement))
            {
                Match match = Regex.Match(wbsElement, @"\bC[.][0-9][0-9][.][0-9][0-9][0-9][0-9][0-9]\b");
                if (wbsElement.Trim().Length != 10 || !match.Success || !LineItem.VerifyNumber("WBS", wbsElement.Trim().Replace(".", string.Empty)))
                {
                    alert.AddError("Bad WBS", "WBS at line " + accountNums[0] + " must be a valid 7-digit number.");
                    return false;
                }
                if ((siOrder.Trim().Length != 0 && siOrder.Trim().Length != 10) || (siOrder.Trim().Length != 0 && !long.TryParse(siOrder.Trim(), out validator)))
                {
                    alert.AddError("Bad SIO", "SIO at line " + accountNums[0] + " must be a 10-digit number.");
                    return false;
                }
                if (!string.IsNullOrWhiteSpace(bpn) || !string.IsNullOrWhiteSpace(fund) || !string.IsNullOrWhiteSpace(costCenter) || !string.IsNullOrWhiteSpace(realOrder))
                {
                    alert.AddError("Invalid Account1",
                            "Account number at line " + accountNums[0] + " does not match a valid billing scenario.");
                    return false;
                }
            }
            // Business Parter Number (BPN)
            else if (!string.IsNullOrEmpty(bpn))
            {
                if (bpn.Trim().Length != 7 || !bpn.Trim().StartsWith("3") || !long.TryParse(bpn.Trim(), out validator))
                {
                    alert.AddError("Bad BPN", "Business Partner Number at line " + accountNums[0] + " must be a 7-digit number starting with '3'.");
                    return false;
                }
                if (!string.IsNullOrWhiteSpace(fund) || !string.IsNullOrWhiteSpace(wbsElement) || !string.IsNullOrWhiteSpace(realOrder) || !string.IsNullOrWhiteSpace(costCenter) || !string.IsNullOrWhiteSpace(siOrder))
                {
                    alert.AddError("Invalid Account1",
                            "Account number at line " + accountNums[0] + " does not match a valid billing scenario.");
                    return false;
                }
            }
            else // No Valid Account
            {
                alert.AddError("Bad account", "No valid account number detected at line " + accountNums[0] + ".");
                return false;
            }
            return true;
        }
コード例 #8
0
ファイル: CreateTicket.aspx.cs プロジェクト: drewjst/Risque
 // Billing and Text Box Rule Validation and Bulk Upload Validation
 protected bool AcctValidation(Alert alert)
 {
     bool canSave = true;
     // Verify Account Info
     switch (ddlAccountType.SelectedValue)
     {
         case "1": // Cost Center
             {
                 long validator;
                 if (txtFund.Text.Trim().Length != 8 || !long.TryParse(txtFund.Text.Trim(), out validator) || !LineItem.VerifyNumber("FUND", txtFund.Text.Trim()))
                 {
                     canSave = false;
                     alert.AddError("Bad Fund", "Fund must be a valid 8-digit number.");
                 }
                 if (txtCostCenter.Text.Trim().Length != 10 || !long.TryParse(txtCostCenter.Text.Trim(), out validator) || !LineItem.VerifyNumber("COST", txtCostCenter.Text.Trim()))
                 {
                     canSave = false;
                     alert.AddError("Bad Cost Center", "Cost Center must be a valid 10-digit number.");
                 }
                 if ((txtSIO.Text.Trim().Length != 0 && txtSIO.Text.Trim().Length != 10) || (txtSIO.Text.Trim().Length != 0 && !long.TryParse(txtSIO.Text.Trim(), out validator)))
                 {
                     canSave = false;
                     alert.AddError("Bad SIO", "SIO must be a 10-digit number.");
                 }
                 break;
             }
         case "2": // Real Order
             {
                 long validator;
                 if (txtFund.Text.Trim().Length != 8 || !long.TryParse(txtFund.Text.Trim(), out validator) || !LineItem.VerifyNumber("FUND", txtFund.Text.Trim()))
                 {
                     canSave = false;
                     alert.AddError("Bad Fund", "Fund must be a valid 8-digit number.");
                 }
                 if (txtRealOrder.Text.Trim().Length != 10 || !long.TryParse(txtRealOrder.Text.Trim(), out validator) || !LineItem.VerifyNumber("ORDER", txtRealOrder.Text.Trim()))
                 {
                     canSave = false;
                     alert.AddError("Bad Real Order", "Real Order must be a valid 10-digit number.");
                 }
                 break;
             }
         case "3": // WBS Element
             {
                 long validator;
                 Match match = Regex.Match(txtWBS.Text, @"\bC[.][0-9][0-9][.][0-9][0-9][0-9][0-9][0-9]\b");
                 if (txtWBS.Text.Trim().Length != 10 || !match.Success || !LineItem.VerifyNumber("WBS", txtWBS.Text.Trim().Replace(".", string.Empty)))
                 {
                     canSave = false;
                     alert.AddError("Bad WBS", "WBS must be a valid 7-digit number.");
                 }
                 if ((txtSIO.Text.Trim().Length != 0 && txtSIO.Text.Trim().Length != 10) || (txtSIO.Text.Trim().Length != 0 && !long.TryParse(txtSIO.Text.Trim(), out validator)))
                 {
                     canSave = false;
                     alert.AddError("Bad SIO", "SIO must be a 10-digit number.");
                 }
                 break;
             }
         case "4": // Business Partner Number
             {
                 long validator;
                 if (txtBPN.Text.Trim().Length != 7 || !txtBPN.Text.Trim().StartsWith("3") || !long.TryParse(txtBPN.Text.Trim(), out validator))
                 {
                     canSave = false;
                     alert.AddError("Bad BPN", "Business Partner Number must be a 7-digit number starting with '3'.");
                 }
                 break;
             }
         default:
             {
                 canSave = false;
                 alert.AddWarning("No Account", "Select an Account Type");
                 break;
             }
     }
     if (canSave == false) // Send back to user to fix Account Errors
     {
         alert.ShowBrokenRules();
         return false;
     }
     else
         return true;
 }
コード例 #9
0
ファイル: CreateTicket.aspx.cs プロジェクト: drewjst/Risque
        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();
        }