Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# (c) { Console.WriteLine(“数据已经在字典中”); } 其他的 { 添加(数据[1],szerokosc); } } 其他的 { 添加(数据[1],数据[2]); } } 其他的 { Dictionary newprofile=新字典_C#_Jquery_Asp.net Mvc_Csv_Dropdownlistfor - Fatal编程技术网

C# (c) { Console.WriteLine(“数据已经在字典中”); } 其他的 { 添加(数据[1],szerokosc); } } 其他的 { 添加(数据[1],数据[2]); } } 其他的 { Dictionary newprofile=新字典

C# (c) { Console.WriteLine(“数据已经在字典中”); } 其他的 { 添加(数据[1],szerokosc); } } 其他的 { 添加(数据[1],数据[2]); } } 其他的 { Dictionary newprofile=新字典,c#,jquery,asp.net-mvc,csv,dropdownlistfor,C#,Jquery,Asp.net Mvc,Csv,Dropdownlistfor,(c) { Console.WriteLine(“数据已经在字典中”); } 其他的 { 添加(数据[1],szerokosc); } } 其他的 { 添加(数据[1],数据[2]); } } 其他的 { Dictionary newprofile=新字典(); 新增(数据[1],数据[2]); srednicaDict.Add(数据[0],新文件); } } Srednica,Profil,Szerokosc 17.00,60.00,120.00 17.00,70.00,120.00 17.

(c) { Console.WriteLine(“数据已经在字典中”); } 其他的 { 添加(数据[1],szerokosc); } } 其他的 { 添加(数据[1],数据[2]); } } 其他的 { Dictionary newprofile=新字典(); 新增(数据[1],数据[2]); srednicaDict.Add(数据[0],新文件); } }
Srednica,Profil,Szerokosc
17.00,60.00,120.00
17.00,70.00,120.00
17.00,80.00,130.00
18.00,80.00,130.00
13.00,70.00,135.00 
(...)
public DataTable ReadCSVFile (string pathCSV, DataTable dataTable)
        {
            string[] contentFile = File.ReadAllLines(pathCSV);
            if (contentFile.Count() > 0)
            {
                string[] col = contentFile[0].Split(',');

                for (int i = 0; i < col.Count(); i++)
                {
                    dataTable.Columns.Add(col[i]);
                }

                for (int i = 1; i<contentFile.Count(); i++)
                {
                    string[] row = contentFile[i].Split(',');
                    dataTable.Rows.Add(row);
                }
            }
            return dataTable;
        }

    public ActionResult Index()
        {
            ReadCSV readCSV = new ReadCSV();
            readCSV.ReadCSVFile(pathCSV, dataTable);

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                var selectedlistitem = new SelectListItem { Text = dataTable.Rows[i]["Szerokosc"].ToString(), Value = dataTable.Rows[i]["Szerokosc"].ToString() };
                if (!listSzerokosc.Any(l => l.Text == selectedlistitem.Text))
                {
                    listSzerokosc.Add(selectedlistitem);
                }
            }
            ViewBag.Szerokosc = listSzerokosc;

            return View();
        }

        public JsonResult GetProfil(string value)
        {
            List<SelectListItem> listProfil = new List<SelectListItem>();
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                if (value != dataTable.Rows[i]["Profil"].ToString())
                    continue;
                var selectedlistitem = new SelectListItem { Text = dataTable.Rows[i]["Profil"].ToString(), Value = dataTable.Rows[i]["Profil"].ToString() };
                if (!listProfil.Any(l => l.Text == selectedlistitem.Text))
                {
                    listProfil.Add(selectedlistitem);
                }
            }
            return Json(new SelectList(listProfil, "Value", "Text", JsonRequestBehavior.AllowGet));

  }
     @using (Html.BeginForm())
{
    @Html.DropDownList("Szerokosc", ViewBag.Szerokosc as SelectList, "---Select szerokosc---", new { @id = "MainDropDownListID" })
    @Html.DropDownList("Profil", new SelectList(string.Empty, "Value", "Text"), "---Select profil---", new { style = "width:250px" })
    @Html.DropDownList("Srednica", new SelectList(string.Empty, "Value", "Text"), "---Select Srednice---", new { style = "width:250px" })
}


<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#Szerokosc").change(function () {
            $("#Profil").empty();
            $.ajax({
                type: 'POST',
                url: '@Url.Action("GetProfil")',
                dataType: 'json',
                data: { id: $("#Szerokosc").val() },
                success: function (profile) {
                    $.each(profile, function (i, profil) {
                        $("#Profil").append('<option value="' + profil.Value + '">' +
                            profil.Text + '</option>');
                    });
                },
            });
            return false;
        })
    });
</script>
            Dictionary<decimal, Dictionary<decimal, decimal>> srednicaDict = new Dictionary<decimal, Dictionary<decimal, decimal>>();



            string input = "17.00,60.00,120.00\n" +
                             "17.00,70.00,120.00\n" +
                             "17.00,80.00,130.00\n" +
                             "18.00,80.00,130.00\n" +
                             "13.00,70.00,135.00";

            StringReader reader = new StringReader(input);
            string line = "";
            while ((line = reader.ReadLine()) != null)
            {
                decimal[] data = line.Split(new char[] { ',' }).Select(x => decimal.Parse(x)).ToArray();
                Dictionary<decimal, decimal> srednica = null;
                decimal szerokosc = 0;
                if (srednicaDict.ContainsKey(data[0]))
                {
                    srednica = srednicaDict[data[0]];
                    KeyValuePair<decimal, decimal> profil;
                    if (srednica.ContainsKey(data[1]))
                    {
                        szerokosc = srednica[data[1]];
                        if (data[2] == szerokosc)
                        {
                            Console.WriteLine("Data Already in dictionary");
                        }
                        else
                        {
                            srednica.Add(data[1], szerokosc);
                        }
                    }
                    else
                    {
                        srednica.Add(data[1],data[2]);
                    }
                }
                else
                {
                    Dictionary<decimal, decimal> newProfil = new Dictionary<decimal, decimal>();
                    newProfil.Add(data[1], data[2]);
                    srednicaDict.Add(data[0],newProfil);
                }

            }