コード例 #1
0
ファイル: ExeclUtility.cs プロジェクト: JonYuLi/SimInfoUpload
        public List <SimInfo> GetDataFromExcelByConn(bool hasTitle = false)
        {
            var    filePath = this.fileName;
            string fileType = System.IO.Path.GetExtension(filePath);

            if (string.IsNullOrEmpty(fileType))
            {
                return(null);
            }

            using (DataSet ds = new DataSet())
            {
                string strCon = string.Format("Provider=Microsoft.{4}.OLEDB.{0}.0;" +
                                              "Extended Properties=\"Excel {1}.0;HDR={2};IMEX=1;\";" +
                                              "data source={3};",
                                              (fileType == ".xls" ? 4 : 12), (fileType == ".xls" ? 8 : 12), (hasTitle ? "Yes" : "NO"), filePath, (fileType == ".xls" ? "Jet" : "ACE"));
                string strCom = " SELECT * FROM [Sheet1$]";
                using (OleDbConnection myConn = new OleDbConnection(strCon))
                    using (OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn))
                    {
                        myConn.Open();
                        myCommand.Fill(ds);
                    }
                if (ds == null || ds.Tables.Count <= 0)
                {
                    return(null);
                }
                System.Diagnostics.Debug.Write(ds.Tables[0].Rows[0][0]);

                List <SimInfo> simInfoList = new List <SimInfo>();

                execlCheckStatus = "";
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    SimInfo simInfo = new SimInfo()
                    {
                        num         = ds.Tables[0].Rows[i][0].ToString(),
                        ccid        = ds.Tables[0].Rows[i][1].ToString(),
                        description = ds.Tables[0].Rows[i][2].ToString()
                    };
                    if (CheckCCID(simInfo.ccid) == false)
                    {
                        execlCheckStatus += String.Format("{1}行: 无效的CCID {0}\r\n", simInfo.ccid, i + 1);
                        continue;
                    }
                    if (simInfoList.Find(q => (q.num == simInfo.num || q.ccid == simInfo.ccid)) == null)
                    {
                        simInfoList.Add(simInfo);
                    }
                    else
                    {
                        execlCheckStatus += String.Format(
                            "{2}行: num {0} ccid {1} 重复的号码或CCID\r\n",
                            simInfo.num, simInfo.ccid, i + 1);
                    }
                }

                return(simInfoList);
            }
        }
コード例 #2
0
ファイル: HttpUtility.cs プロジェクト: JonYuLi/SimInfoUpload
 public bool HttpPost(SimInfo simInfo)
 {
     try
     {
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://120.132.12.76:8080/i501-hg/sim");
         request.Method      = "POST";
         request.ContentType = "application/json";
         string       postStr = saveLoad(simInfo);
         StreamWriter writer  = new StreamWriter(request.GetRequestStream(), Encoding.UTF8);
         writer.Write(postStr);
         writer.Flush();
         HttpWebResponse response = (HttpWebResponse)request.GetResponse();
         string          encoding = response.ContentEncoding;
         if (encoding == null || encoding.Length < 1)
         {
             encoding = "UTF-8"; //默认编码
         }
         StreamReader reader    = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(encoding));
         string       retString = reader.ReadToEnd();
         System.Diagnostics.Debug.WriteLine("post return :  " + retString);
         return(true);
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine(e.ToString());
         return(false);
     }
 }
コード例 #3
0
 public Task <int> GetValueAsync(SimInfo simInfo)
 {
     return(Task.Run(() =>
     {
         HttpUtility httpHelper = new HttpUtility();
         if (httpHelper.getNumFormServer(simInfo.num) != null)
         {
             return 1;
         }
         if (httpHelper.getSimInfoByCCID(simInfo.ccid) != null)
         {
             return 2;
         }
         return 0;
     }));
 }
コード例 #4
0
ファイル: HttpUtility.cs プロジェクト: JonYuLi/SimInfoUpload
        public string saveLoad(SimInfo simInfo)
        {
            StringWriter sw     = new StringWriter();
            JsonWriter   writer = new JsonTextWriter(sw);

            writer.WriteStartObject();
            writer.WritePropertyName("number");
            writer.WriteValue(simInfo.num);
            writer.WritePropertyName("ccid");
            writer.WriteValue(simInfo.ccid);
            writer.WritePropertyName("description");
            writer.WriteValue(simInfo.description);
            writer.WriteEndObject();
            writer.Flush();
            string jsonText = sw.GetStringBuilder().ToString();

            return(jsonText);
        }
コード例 #5
0
ファイル: HttpUtility.cs プロジェクト: JonYuLi/SimInfoUpload
        private SimInfo JsonToObject(string jsonStr)
        {
            if (jsonStr == null)
            {
                return(null);
            }
            RootObject rootObject = (RootObject)JsonConvert.DeserializeObject(jsonStr, typeof(RootObject));

            if (rootObject._embedded.sim.Count <= 0)
            {
                return(null);
            }
            SimInfo simInfo = new SimInfo
            {
                num         = rootObject._embedded.sim[0].number,
                ccid        = rootObject._embedded.sim[0].ccid,
                description = rootObject._embedded.sim[0].description
            };

            return(simInfo);
        }