Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            nc_getEdiNo nc_getEdiNo = db.nc_getEdiNo.Find(id);

            db.nc_getEdiNo.Remove(nc_getEdiNo);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Create([Bind(Include = "id,TextBox1,txtAdress,txtData,txtPassword,txtPrivateKey,txtPublicKey,txtSender,txtRecever,txtMiWen,txtMingWen")] nc_getEdiNo nc_getEdiNo)
        {
            if (ModelState.IsValid)
            {
                db.nc_getEdiNo.Add(nc_getEdiNo);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(nc_getEdiNo));
        }
Beispiel #3
0
        // GET: nc_getEdiNo/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            nc_getEdiNo nc_getEdiNo = db.nc_getEdiNo.Find(id);

            if (nc_getEdiNo == null)
            {
                return(HttpNotFound());
            }
            return(View(nc_getEdiNo));
        }
Beispiel #4
0
        public ActionResult Edit([Bind(Include = "id,TextBox1,txtAdress,txtData,txtPassword,txtPrivateKey,txtPublicKey,txtSender,txtRecever,txtMiWen,txtMingWen")] nc_getEdiNo nc_getEdiNo, string action)
        {
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath("~/Web.config")));
            if (action == "Save")
            {
                if (ModelState.IsValid)
                {
                    db.Entry(nc_getEdiNo).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(nc_getEdiNo));
            }
            else if (action == "测试")
            {
                string jsonfile = "D:\\殷勇\\change\\json\\getEdiNo_s.json";
                using (System.IO.StreamReader file = System.IO.File.OpenText(jsonfile))
                {
                    using (Newtonsoft.Json.JsonTextReader reader = new Newtonsoft.Json.JsonTextReader(file))
                    {
                        try
                        {
                            //string json = System.IO.File.ReadAllText(jsonfile);
                            //json = json.Replace("\r\n", ""); ;
                            //json = json.Replace(" ", "");
                            //StringReader sr = new StringReader(json);

                            //反序列化 数据赋值到实体类
                            //Models.getEdiNo_sJsonRoot t = JsonConvert.DeserializeObject<Models.getEdiNo_sJsonRoot>(json);
                            Models.getEdiNo_sJsonRoot t = new Models.getEdiNo_sJsonRoot();
                            t.data             = new Models.getEdiNo_sJsonData();
                            t.data.customsCode = "2212";
                            t.data.agentCode   = "1108919038";
                            t.data.entryType   = "8";
                            t.data.userName    = "******";
                            //JsonSerializer serializer = new JsonSerializer();
                            //object o = serializer.Deserialize(new JsonTextReader(sr), typeof(Models.getEdiNo_sJsonRoot));
                            //Models.getEdiNo_sJsonData t = o as Models.getEdiNo_sJsonData;
                            //序列化 实体类生成数据
                            string json1 = JsonConvert.SerializeObject(t.data);
                            nc_getEdiNo.txtData = json1;
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.ToString());
                        }
                    }
                }



                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(nc_getEdiNo.txtAdress.Trim());
                httpWebRequest.ProtocolVersion = HttpVersion.Version11;
                httpWebRequest.Timeout         = 300 * 1000;
                httpWebRequest.UserAgent       = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko";
                httpWebRequest.ContentType     = "application/json;charset=utf8";
                httpWebRequest.Headers.Add("Accept-Encoding", "gzip,deflate");
                ServicePointManager.Expect100Continue = false;
                httpWebRequest.Headers.Add("X-SWGD-Sender", nc_getEdiNo.txtSender.Trim());
                httpWebRequest.Headers.Add("X-SWGD-Receiver", nc_getEdiNo.txtRecever.Trim());
                httpWebRequest.Headers.Add("X-SWGD-PublicKey", nc_getEdiNo.txtPublicKey.Trim());
                string txtSign = com.easipass.business.util.winx.SignUtil.getSign(nc_getEdiNo.txtPrivateKey.Trim(), nc_getEdiNo.txtData.Trim());
                string strData = "{\"data\":\"" + com.easipass.business.util.winx.AESUtil.encrypt(nc_getEdiNo.txtData.Trim(), nc_getEdiNo.txtPassword.Trim()) + "\"}";
                httpWebRequest.Headers.Add("X-SWGD-Sign", txtSign);
                httpWebRequest.Method = "POST";
                log.Info("发送头信息:::" + httpWebRequest.Headers.ToString());
                log.Info("发送信息:::" + strData);
                try
                {
                    byte[] dataBuff = Encoding.UTF8.GetBytes(strData);
                    httpWebRequest.ContentLength = dataBuff.Length;
                    using (Stream stream = httpWebRequest.GetRequestStream())
                    {
                        stream.Write(dataBuff, 0, dataBuff.Length);
                        stream.Close();
                    }

                    using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse())
                    {
                        string responseContentEncoding = httpWebResponse.ContentEncoding.ToLower();
                        string response = string.Empty;
                        using (StreamReader sr = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8))
                        {
                            response = sr.ReadToEnd();
                            sr.Close();
                        }

                        httpWebResponse.Close();
                        nc_getEdiNo.TextBox1 = response;
                        log.Info("返回信息:::" + nc_getEdiNo.TextBox1.Trim());
                    }
                    if (ModelState.IsValid)
                    {
                        db.Entry(nc_getEdiNo).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
                finally
                {
                    httpWebRequest.Abort();
                }
                return(RedirectToAction("edit"));
            }
            else if (action == "解码")
            {
                nc_getEdiNo.txtMingWen = com.easipass.business.util.winx.AESUtil.decrypt(nc_getEdiNo.txtMiWen.Trim(), nc_getEdiNo.txtPassword.Trim());
                log.Error(nc_getEdiNo.txtMingWen.Trim());
                if (ModelState.IsValid)
                {
                    db.Entry(nc_getEdiNo).State = EntityState.Modified;
                    db.SaveChanges();
                }
                return(RedirectToAction("edit"));
                //
            }
            else
            {
                return(RedirectToAction("edit"));
                //
            }
        }