示例#1
0
 /// <summary>
 /// 新增订阅信息
 /// </summary>
 /// <param name="type"></param>
 /// <param name="status"></param>
 /// <param name="cusno"></param>
 /// <param name="declarationcode"></param>
 /// <param name="cusno"></param>
 /// <param name="userid"></param>
 /// <param name="username"></param>
 /// <param name="openid"></param>
 /// <param name="codetype"></param>
 /// <returns></returns>
 public static bool insertSubscribe(string type, string[] status, string cusno, string declarationcode, int userid, string username, string openid, string codetype, string ordercode)
 {
     try
     {
         string        sql  = @"insert into wechat_subscribe(id,cusno,declarationcode,userid,username,substime,substype,status,openid,statusvalue,codetype,ordercode) 
         values(wechat_subscribe_id.nextval,'{0}','{1}','{2}','{3}',sysdate,'{4}','{5}','{6}','{7}','{8}','{9}')";
         List <string> sqls = new List <string>();
         for (int i = 0; i < status.Length; i++)
         {
             string statusvalue = SwitchHelper.switchValue(type, status[i]);
             sqls.Add(string.Format(sql, cusno, declarationcode, userid, username, type, status[i], openid, statusvalue, codetype, ordercode));
         }
         using (DBSession db = new DBSession())
         {
             return(db.ExecuteBatch(sqls) > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         LogHelper.Write("SubscribeModel_insertSubscribe:" + ex.Message + "——code:" + cusno + declarationcode);
         return(false);
     }
 }
示例#2
0
        public static string SaveFile(string mediaIds, string ordercode)
        {
            string str = "false";

            if (!string.IsNullOrEmpty(mediaIds))
            {
                string         url = string.Format("http://file.api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", ModelWeChat.TokenModel.AccessToken, mediaIds);
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
                using (WebResponse wr = req.GetResponse())
                {
                    string dicPath  = System.AppDomain.CurrentDomain.BaseDirectory;
                    string filename = Guid.NewGuid() + ".jpg";
                    string filepath = @"uploadimage\" + filename;

                    WebClient mywebclient = new WebClient();
                    mywebclient.DownloadFile(wr.ResponseUri, dicPath + filepath);

                    if (File.Exists(dicPath + filepath))//ftp 到文件服务器,然后往数据库插入一笔记录
                    {
                        FileInfo fi = new FileInfo(dicPath + filepath);

                        System.Uri Uri      = new Uri("ftp://" + ConfigurationManager.AppSettings["FTPServer"] + ":" + ConfigurationManager.AppSettings["FTPPortNO"]);
                        string     UserName = ConfigurationManager.AppSettings["FTPUserName"];
                        string     Password = ConfigurationManager.AppSettings["FTPPassword"];
                        FtpHelper  ftp      = new FtpHelper(Uri, UserName, Password);
                        string     ftppath  = "/67/" + ordercode + "/" + filename;
                        bool       bf       = ftp.UploadFile(dicPath + filepath, ftppath, true);;
                        if (bf)
                        {
                            using (DBSession db = new DBSession())
                            {
                                List <string> sqls         = new List <string>();
                                int           uploaduserid = 763;
                                string        customercode = "KSJSBGYXGS";

                                string sql = @"insert into LIST_ATTACHMENT (id
                                                ,filename,originalname,filetype,uploadtime,uploaduserid,customercode,ordercode
                                                ,sizes,filetypename,filesuffix)
                                        values(List_Attachment_Id.Nextval,'{0}','{1}','{2}',sysdate,{3},'{4}','{5}'
                                                ,'{6}','{7}','{8}')";
                                sql = string.Format(sql
                                                    , ftppath, filename, "67", uploaduserid, customercode, ordercode
                                                    , fi.Length, "查验文件", ".jpg");

                                string sql2 = "update list_order set checkpic=1 where code='" + ordercode + "'";

                                sqls.Add(sql); sqls.Add(sql2);

                                int i = db.ExecuteBatch(sqls);
                                if (i > 0)//插入成功,后删除本地文件
                                {
                                    str = "success";
                                    fi.Delete();
                                }
                                else//插入失败后,远程删除文件,本地文件暂且留着
                                {
                                    ftp.DeleteFile(ftppath);
                                }
                            }
                        }//ftp失败,本地文件暂且留着
                    }
                }
            }

            return(str);
        }