Пример #1
0
        public ActionResult Coil()
        {
            CoilMasters details = new CoilMasters();

            //details.CoilDetails = new List<CoilMaster>();
            return(View(details));
        }
Пример #2
0
        public ActionResult Coil(CoilMasters model)
        {
            string ConnStr = ConfigurationManager.ConnectionStrings["GramLineConn"].ToString();

            string input;

            if (model.CoilDetails == null)
            {
                return(View(model));
            }

            if (model.CoilDetails[0].Flag == "UPLOAD")
            {
                input = model.CoilDetails[0].SaveTable;
            }
            else
            {
                input = model.CoilDetails[0].Input;
            }

            if (input == null)
            {
                return(View(model));
            }

            List <string> coilIDs = new List <string>();

            int coilIDCount = 0;

            string[] lines = input.Split(
                new[] { Environment.NewLine },
                StringSplitOptions.None
                );
            coilIDCount = lines.Length - 1;

            for (int i = 0; i < coilIDCount; i++)
            {
                coilIDs.Add(lines[i].Substring(0, CoilIDLength));
            }

            for (int i = 0; i < coilIDCount; i++)
            {
                using (SqlConnection newCon = new SqlConnection(ConnStr))
                {
                    if (model.CoilDetails[0].Flag == "UPLOAD")
                    {
                        var        date     = DateTime.Now;
                        var        UserName = ((Scanner.Models.User)Session["User"]).FirstName + " " + ((Scanner.Models.User)Session["User"]).LastName;
                        SqlCommand newCmd2  = new SqlCommand(("IF NOT EXISTS (SELECT * FROM GramOnline.dbo.TB_Y_X_COIL_TEST WHERE COILID = '" + coilIDs[i] + "') BEGIN INSERT INTO GramOnline.dbo.TB_Y_X_COIL_TEST (COILID, TYPE, COLOR, WEIGHT, GAUGE, WIDTH, DATE_INSERT, STATUS, UserName) VALUES ('" + coilIDs[i] + "' , '" + model.CoilDetails[i + 1].TYPE + "' , '" + model.CoilDetails[i + 1].COLOR + "' , " + model.CoilDetails[i + 1].WEIGHT + " , " + model.CoilDetails[i + 1].GAUGE + " , " + model.CoilDetails[i + 1].WIDTH + " , GETDATE(), 'N', '" + UserName + "') END"), newCon);
                        newCon.Open();
                        SqlDataReader rdr2 = newCmd2.ExecuteReader();

                        ViewBag.Upload = "Data uploaded!";
                        newCon.Close();
                    }
                    else
                    {
                        CoilMaster modelDetail = new CoilMaster();
                        modelDetail.COILID = coilIDs[i];
                        modelDetail.Save   = model.CoilDetails[0].Save;

                        string[] tokens = lines[i].Split('+');
                        modelDetail.COILID = tokens[0];
                        modelDetail.TYPE   = tokens[1];
                        modelDetail.COLOR  = tokens[2];
                        modelDetail.WEIGHT = Double.Parse(tokens[3]);
                        modelDetail.GAUGE  = Double.Parse(tokens[4]);
                        modelDetail.WIDTH  = Double.Parse(tokens[5]);
                        model.CoilDetails.Add(modelDetail);
                    }
                }
            }
            return(View(model));
        }