public ActionResult DeleteConfirmed(int id)
        {
            DropDownType dropDownType = db.DropDownTypes.Find(id);

            db.DropDownTypes.Remove(dropDownType);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #2
0
    public void SetPickupType(int type, int color)
    {
        Initialization();

        type  = Mathf.Min(typeCount - 1, type);
        color = Mathf.Min(colorCount - 1, color);

        pickupType  = (DropDownType)type;
        pickupColor = (DropDownColor)color;
        UpdateAppearance();
    }
        // GET: DropDownTypes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DropDownType dropDownType = db.DropDownTypes.Find(id);

            if (dropDownType == null)
            {
                return(HttpNotFound());
            }
            return(View(dropDownType));
        }
 public ActionResult Edit([Bind(Include = "Name,Code,IsActive")] DropDownType dropDownType)
 {
     if (ModelState.IsValid)
     {
         if (!string.IsNullOrEmpty(Session["UserName"].ToString()))
         {
             dropDownType.ModifiedBy   = Session["UserName"].ToString();
             dropDownType.ModifiedDate = DateTime.Now;
         }
         db.Entry(dropDownType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(dropDownType));
 }
Example #5
0
        public static void Populate(this DropDownList ddl, DropDownType type, string defaultSelectionValue = null, bool retainFirst = false)
        {
            switch (type)
            {
                case DropDownType.Role:
                    using (RolesController rc = new RolesController())
                    {
                        var roles = rc.Get().Select(i => new { Label = i.RoleName, Value = i.RoleID }).OrderBy(i => i.Label).ToList();
                        ddl.DataSource = roles;
                    }
                    break;

                case DropDownType.ScopeType:
                    using (ScopesController sc = new ScopesController())
                    {
                        var scopes = sc.Get().Select(i => new { Label = i.ScopeName, Value = i.ScopeID }).OrderBy(i => i.Label).ToList();
                        ddl.DataSource = scopes;
                    }
                    break;

                case DropDownType.Permission:
                    using (PermissionsController pc = new PermissionsController())
                    {
                        var permissions = pc.Get().Select(i => new { Label = i.PermissionName, Value = i.PermissionID }).OrderBy(i => i.Label).ToList();
                        ddl.DataSource = permissions;
                    }
                    break;

                default: break;
            }

            Reset(ddl, retainFirst);
            ddl.DataValueField = "Value";
            ddl.DataTextField = "Label";
            ddl.DataBind();

            SelectDefault(ddl, defaultSelectionValue);
        }
        public static IHtmlContent Select2MultipleFor <TModel, TValue, T1, T2, T3, T4>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <T1, T2> source1, Dictionary <T3, T4> source2, bool unique = true, string width = "100%", string col1Style = "", string col2Style = "", DropDownType type1 = DropDownType.Selec2DropDown, DropDownType type2 = DropDownType.Selec2DropDown)
        {
            var metadata      = html.GetModelExplorer(expression);
            var htmlFieldName = html.FieldNameFor(expression);
            var id            = html.FieldIdFor(expression);
            var name          = html.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName);
            var displayName   = metadata.Metadata.DisplayName ?? metadata.Metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            //var value = metadata.Model == null ? new List<KeyValuePair<string,string>>() : (IEnumerable<KeyValuePair<string, string>>)metadata.Model ;
            var value    = (((IEnumerable <KeyValuePair <T1, T3> >)metadata.Model) ?? new List <KeyValuePair <T1, T3> >()).ToArray();
            var id1      = id + "_Select1";
            var id2      = id + "_Select2";
            var divId    = id + "_MultipleSelect";
            var template =
                @"<tr class=""row-multipleSelect"">
                <td style='" + col1Style + @"'>
                    {0}
                </td>
                <td style='" + col2Style + @"'>
                    {1}
                </td>
                <td style=""width: 35px; text-align: center;vertical-align: top; padding-top: 13px;"">
                    {2}
                </td>
            </tr>";
            const string imgPlus  = @"<button class=""btn btn-primary btn-xs add-item""><i class=""fa fa-plus fa-lg""></i></button>";
            const string imgMinus = @"<button class=""btn btn-danger btn-xs remove-item"" style=""opacity: 0.8;""><i class=""fa fa-minus fa-lg""></i></button>";
            var          item1    = "";
            var          item2    = "";

            switch (type1)
            {
            case DropDownType.DropDownList:
                item1 = html.DropDownList(id1, new SelectList(source1, "Key", "Value"), new { @class = "form-control", style = "width: 100%" }).ToHtmlString();
                break;

            case DropDownType.Selec2DropDown:
                item1 = html.Select2DropDown(id1, default, source1).ToHtmlString();
                break;
            }
            switch (type2)
            {
            case DropDownType.DropDownList:
                item2 = html.DropDownList(id2, new SelectList(source2, "Key", "Value"), new { @class = "form-control", style = "width: 100%" }).ToHtmlString();
                break;

            case DropDownType.Selec2DropDown:
                item2 = html.Select2DropDown(id2, default, source2).ToHtmlString();
                break;
            }
            var result = string.Format(template,
                                       item1 +
                                       html.HiddenFor(expression, new { Name = id + "_HiddenInput" }).ToHtmlString() +
                                       html.ValidationMessageFor(expression, null, new Dictionary <string, object> {
                ["data-valmsg-for"] = id + "_HiddenInput"
            }).ToHtmlString(),
                                       item2,
                                       imgPlus);

            for (var i = 0; i < value.Length; i++)
            {
                var item  = value[i];
                var name1 = name + string.Format("[{0}].Key", i);
                var name2 = name + string.Format("[{0}].Value2", i);
                var text1 = source1[item.Key].ConvertTo <string>();
                var text2 = source2[item.Value].ConvertTo <string>();
                result += string.Format(template,
                                        html.Label("", text1, new { style = "color: black;" }).ToHtmlString() + "\n" +
                                        html.Hidden(name1, item.Key).ToHtmlString(),
                                        html.Label("", text2, new { style = "color: black;" }).ToHtmlString() + "\n" +
                                        html.Hidden(name2, item.Value).ToHtmlString(),
                                        imgMinus);
            }
            var values = string.Join(", \n", value.Select(p => string.Format("{{ value1: {0}, value2: {1} }}", p.Key, p.Value)));

            html.Script(@"
            <script>
                $(function(){
                    var index = " + value.Length + @";
                    var array = [ " + values + @" ];
                    $(""#" + divId + @" .add-item"").click(function (e) {
                        e.preventDefault();
                        var select1 = $(""#" + id1 + @""");
                        var select2 = $(""#" + id2 + @""");
                        var text1 = select1.find(""option:selected"").text();
                        var value1 = select1.val();
                        var text2 = select2.find(""option:selected"").text();
                        var value2 = select2.val();
                        var item = { value1: value1, value2: value2 };
                        var isUnique = true;
                        " + (unique ? @"array.forEach(function(entry) {
                            if (entry.value1 == value1 && entry.value2 == value2)
                                isUnique = false
                        });" : "") + @"
                        if (isUnique) {
                            array.push(item);
                            var htmlString = '<tr class=""row-multipleSelect"">' +
                            '    <td>' +
                            '        <label style=""color: black;"">' + text1 + '</label>' +
                            '        <input type=""hidden"" name=""" + name + "[' + index + '].Key" + @""" value=""' + value1 + '"" />' +
                            '    </td>' +
                            '    <td>' +
                            '        <label style=""color: black;"">' + text2 + '</label>' +
                            '        <input type=""hidden"" name=""" + name + "[' + index + '].Value" + @""" value=""' + value2 + '"" />' +
                            '    </td>' +
                            '    <td style=""width: 35px; text-align: center;vertical-align: middle;"">' +
                            '        " + imgMinus + @"' +
                            '    </td>' +
                            '</tr>';
                            var newItem = $(htmlString);
                            $(this).closest(""#" + divId + @""").append(newItem);
                            $(""input[name=" + id + @"_HiddenInput]"").val(""HasValue"").trigger('change').valid();
                            $(""#" + divId + @" .remove-item"").click(function (e) {
                                e.preventDefault();
                                var hid = $(this).closest("".row-multipleSelect"").find(""input:hidden"");
                                var value1 = hid.eq(0).val();
                                var value2 = hid.eq(1).val();
                                $(this).closest("".row-multipleSelect"").remove();
                                index--;
                                " + (unique ? @"array.forEach(function(entry, ii) {
                                    if (entry.value1 == value1 && entry.value2 == value2) {
                                        array.splice(ii, 1);
                                        if (array.length == 0)
                                            $(""input[name=" + id + @"_HiddenInput]"").val('').trigger('change').valid();
                                    }
                                });" : "") + @"
                            });
                            index++;
                        }
                    });
                    $(""#" + divId + @" .remove-item"").click(function (e) {
                        e.preventDefault();
                        var hid = $(this).closest("".row-multipleSelect"").find(""input:hidden"");
                        var value1 = hid.eq(0).val();
                        var value2 = hid.eq(1).val();
                        $(this).closest("".row-multipleSelect"").remove();
                        index--;
                        " + (unique ? @"array.forEach(function(entry, ii) {
                            if (entry.value1 == value1 && entry.value2 == value2) {
                                array.splice(ii, 1);
                                if (array.length == 0)
                                    $(""input[name=" + id + @"_HiddenInput]"").val('').trigger('change').valid();
                            }
                        });" : "") + @"
                    });
                });
            </script>");
            return(new HtmlString(@"<table id=""" + divId + @""" style=""width: " + width + @""" class=""table table-hover"">
                                    " + result + @"
                                    </table>"));
        }
        public static MvcHtmlString BsSelect2MultipleFor <TModel, TValue, T1, T2, T3, T4>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <T1, T2> source1, Dictionary <T3, T4> source2, bool unique = true, int lable_col = 2, int editor_col = 4, string width = "100%", DropDownType type1 = DropDownType.Selec2DropDown, DropDownType type2 = DropDownType.Selec2DropDown)
        {
            string displayName = null;

            SetVariables(html, expression, ref displayName, out string style, out string dirName, out string label, out string validator, out object value, lable_col, ComponentDirection.RightToLeft);
            var editor = html.Select2MultipleFor(expression, source1, source2, unique, width, col2Style: "width: 35%", type1: type1, type2: type2);
            //var result = SetTemplate(label, icon, editor_col, validator, editor, dirName);
            var result =
                "<div class=\"form-group\">"
                + label
                + "<div class=\"col-sm-" + (editor_col / 2) + "\" style=\"padding: 0\">"
                //+ validator
                + editor
                + "</div>"
                + "<div class=\"col-sm-6\"></div>"
                + "</div>";

            return(MvcHtmlString.Create(result));
        }
Example #8
0
    /// <summary>
    /// bind data to dropdownlist control
    /// </summary>
    /// <param name="ddl">control reference</param>
    /// <param name="type">tag type</param>
    /// <param name="filter"></param>
    public void BindDropDownList(DropDownList ddl, DropDownType type, params string[] filter)
    {
        switch (type)
        {
        case DropDownType.Plant:
            List <Plant> plants = Service.GetPlants();
            ddl.DataTextField  = "PlantCode";
            ddl.DataValueField = "PlantID";
            ddl.DataSource     = plants;
            break;

        case DropDownType.PartCategory:
            List <PartCategory> pcs = Service.QueryPartCategorys(new PartCategory());
            ddl.DataTextField  = "CategoryName";
            ddl.DataValueField = "CategoryID";
            ddl.DataSource     = pcs;
            break;

        case DropDownType.PartStatus:
            List <PartStatus> pss = Service.QueryPartStatuss(new PartStatus());
            ddl.DataTextField  = "StatusName";
            ddl.DataValueField = "StatusID";
            ddl.DataSource     = pss;
            break;

        case DropDownType.Workshop:
            List <Workshop> workshops = Service.GetWorkshopbyPlantID(int.Parse(filter[0]));
            ddl.DataTextField  = "WorkshopCode";
            ddl.DataValueField = "WorkshopID";
            ddl.DataSource     = workshops;
            break;

        case DropDownType.Segment:
            List <Segment> ss = Service.GetSegmentbyWorkshopID(int.Parse(filter[0]));
            ddl.DataTextField  = "SegmentName";
            ddl.DataValueField = "SegmentID";
            ddl.DataSource     = ss;
            break;

        case DropDownType.CycleCountLevel:
            List <CycleCountLevel> ccls = Service.QueryCycleCountLevels(new CycleCountLevel());
            ddl.DataTextField  = "LevelName";
            ddl.DataValueField = "LevelID";
            ddl.DataSource     = ccls;
            break;

        case DropDownType.PartGroup:
            List <PartGroup> pgs = Service.QueryPartGroups(new PartGroup());
            ddl.DataTextField  = "GroupName";
            ddl.DataValueField = "GroupID";
            ddl.DataSource     = pgs;
            break;

        case DropDownType.StoreLocationType:
            List <StoreLocationType> slts = Service.QueryStoreLocationTypes(new StoreLocationType());
            ddl.DataTextField  = "TypeName";
            ddl.DataValueField = "TypeID";
            ddl.DataSource     = slts;
            break;

        case DropDownType.StocktakePriority:
            List <StocktakePriority> stps = Service.GetStocktakePriorities();
            ddl.DataTextField  = "PriorityName";
            ddl.DataValueField = "PriorityID";
            ddl.DataSource     = stps;
            break;

        case DropDownType.StoreLocation:
            List <StoreLocation> sls = Service.GetStoreLocations();
            ddl.DataTextField  = "LocationName";
            ddl.DataValueField = "LocationID";
            ddl.DataSource     = sls;
            break;
        }
        ddl.DataBind();
        ddl.Items.Insert(0, new ListItem("--", ""));
    }
        private static Dictionary <string, string> GetBallyDropdownListOverrideSettings(DropDownType type, int listLength, string targetControlID, string actionUrl, StylePropertyBag style, short tabIndex, string onChangeFunction, object value, string cssClass, string cascadeInputFunction = "")
        {
            Dictionary <string, string> overrideSettings;

            overrideSettings = new Dictionary <string, string>();
            overrideSettings.Add(ControlLibConstants.TAB_INDEX, tabIndex.ToString());
            overrideSettings.Add(ControlLibConstants.LIST_LENGTH, listLength.ToString());
            overrideSettings.Add(ControlLibConstants.ON_CHANGE_FUNCTION, onChangeFunction);
            overrideSettings.Add(ControlLibConstants.TARGET_CONTROL_ID, targetControlID);
            overrideSettings.Add(ControlLibConstants.ACTION_URL, actionUrl);
            overrideSettings.Add(ControlLibConstants.TYPE, type.ToString());
            overrideSettings.Add(ControlLibConstants.CSS_CLASS, cssClass);
            overrideSettings.Add(ControlLibConstants.CASCADE_INPUT_FUNCTION, cascadeInputFunction);
            overrideSettings.Add(ControlLibConstants.SELECTED_VALUE, Convert.ToString(value));
            SetStyleSettings(style, overrideSettings);
            return(overrideSettings);
        }
        public static MvcHtmlString BallyDropDownList <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, ItemDataSource dataSource, string[] disabled = null, DropDownType type = DropDownType.SingleSelect, int listLength = -1, StylePropertyBag style = null, short tabIndex = 0, string onChangeFunction = "", string cssClass = "", IDictionary <string, object> attributes = null, bool?isEnabled = null, bool?isReadOnly = null)
        {
            string propertyName       = string.Empty;
            string modelName          = string.Empty;
            object value              = string.Empty;
            string errMsg             = string.Empty;
            string dropDownHTMLString = string.Empty;
            Dictionary <string, string> overrideSettings;
            string configKey = string.Empty;
            DropDownHTMLEmitter dropDownHTMLEmitter;

            ControlExtension.GetPropertyNameAndValue <TModel, TProperty>(htmlHelper, expression, out propertyName, out modelName, out value, out errMsg, out configKey);

            overrideSettings = GetBallyDropdownListOverrideSettings(type, listLength, "", "", style, tabIndex, onChangeFunction, value, cssClass);
            FillerParams fillerParams = null;

            if (dataSource != null)
            {
                fillerParams = new FillerParams(modelName, propertyName, overrideSettings, list: dataSource.DataSource, valueMember: dataSource.ValueMember, displayMember: dataSource.DisplayMember, disabled: disabled, attributes: attributes, isEnabled: isEnabled, isReadOnly: isReadOnly, configKey: configKey);
            }
            else
            {
                fillerParams = new FillerParams(modelName, propertyName, overrideSettings, list: null, valueMember: string.Empty, displayMember: string.Empty, disabled: disabled, attributes: attributes, isEnabled: isEnabled, configKey: configKey);
            }

            var fillers             = ControlPropertyFillerFactory.Get();
            var dropDownpropertyBag = new DropDownPropertyBag(fillerParams);

            dropDownpropertyBag.Accept(fillers);
            dropDownpropertyBag.ErrorMessage = errMsg;
            dropDownpropertyBag.IsDirty      = string.IsNullOrEmpty(errMsg) ? false : true;
            dropDownHTMLEmitter = new DropDownHTMLEmitter(value != null ? value.ToString() : string.Empty, dropDownpropertyBag);

            dropDownHTMLEmitter.Emit(out dropDownHTMLString);
            return(MvcHtmlString.Create(dropDownHTMLString));
        }