Beispiel #1
0
        public void GenerateQRCodeForMarketingOrders(int activityTaocanId)
        {
            AppSettings settings = AppSettings.GetAppSettings();
            string      qrfolder = System.IO.Path.Combine(settings.RootDirectory, settings.QRFolder);

            using (chargebitEntities db = new chargebitEntities())
            {
                Marketing_Activities    activity = null;
                Customer                customer = null;
                List <Marketing_Orders> orders   = (from o in db.Marketing_Orders where o.ActivityTaocanId == activityTaocanId select o).ToList <Marketing_Orders>();
                if (orders.Count > 0)
                {
                    foreach (Marketing_Orders order in orders)
                    {
                        if (order.Used)
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(order.CodePath))
                        {
                            string tmpPhysicalPath = Path.Combine(settings.RootDirectory, order.CodePath.Replace('/', '\\'));
                            if (File.Exists(tmpPhysicalPath))
                            {
                                continue;
                            }
                        }
                        if (activity == null)
                        {
                            activity = (from a in db.Marketing_Activities where a.Id == order.ActivityId select a).FirstOrDefault <Marketing_Activities>();
                            if (activity == null)
                            {
                                continue;
                            }

                            if (customer == null)
                            {
                                customer = (from c in db.Customer where c.Id == activity.CustomerId select c).FirstOrDefault <Customer>();
                            }
                        }

                        string midPhysicalPath = string.Format("{0}\\{1}", activity.AgentId, activity.CustomerId);
                        string fileName        = Guid.NewGuid().ToString() + ".png";
                        string urlAbsPath      = string.Format("{0}/{1}/{2}", activity.AgentId, activity.CustomerId, fileName);
                        string parameter       = string.Empty; //string.Format("agentId={0}&customerId={1}&activityId={2}&activityOrderId={3}", activity.AgentId, activity.CustomerId,activity.Id,order.Id);
                        SortedDictionary <string, string> ps = new SortedDictionary <string, string>();
                        ps["agentId"]         = activity.AgentId.ToString();
                        ps["customerId"]      = activity.CustomerId.ToString();
                        ps["activityId"]      = activity.Id.ToString();
                        ps["activityOrderId"] = order.Id.ToString();
                        StringBuilder pstr  = new StringBuilder();
                        int           count = 1;
                        foreach (KeyValuePair <string, string> p in ps)
                        {
                            pstr.Append(p.Key);
                            pstr.Append("=");
                            pstr.Append(p.Value);
                            if (count < ps.Count)
                            {
                                pstr.Append("&");
                            }
                            count++;
                        }
                        parameter = pstr.ToString();
                        pstr.Append("&key=");
                        pstr.Append(customer.Token);
                        parameter = parameter + "&signature=" + UrlSignUtil.GetMD5(pstr.ToString());
                        parameter = KMEncoder.Encode(parameter);
                        string codeContent = string.Format("{0}/Product/SaoMa?p={1}", settings.WebURL, parameter);
                        string fullFolder  = Path.Combine(qrfolder, midPhysicalPath);
                        QRCodeUtil.CreateQRCode(fullFolder, fileName, codeContent);
                        if (File.Exists(Path.Combine(fullFolder, fileName)))
                        {
                            order.CodePath = urlAbsPath;
                        }
                    }

                    db.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public string GenerateActivityQRCode(int agendId, int customerId, int activityId)
        {
            string codePath = string.Empty;

            agendId = agendId > 0 ? agendId : CurrentLoginUser.User.Id;
            AppSettings settings = AppSettings.GetAppSettings();

            using (chargebitEntities db = new chargebitEntities())
            {
                Marketing_Activities activity = (from a in db.Marketing_Activities where a.Id == activityId select a).FirstOrDefault <Marketing_Activities>();
                if (activity == null)
                {
                    throw new KMBitException(string.Format("编号为:{0}的活动不存在", activityId));
                }
                if (activity.CustomerId != customerId)
                {
                    throw new KMBitException(string.Format("编号为{0}的活动不属于编号为{1}的客户", activityId, customerId));
                }
                if (activity.AgentId != agendId)
                {
                    throw new KMBitException(string.Format("编号为{0}的活动不属于编号为{1}的代理的客户的活动", activityId, agendId));
                }

                Customer customer = (from c in db.Customer where c.Id == customerId select c).FirstOrDefault <Customer>();
                codePath = agendId + "\\" + customerId;
                string fileName      = Guid.NewGuid().ToString() + ".png";
                string absPath       = agendId + "/" + customerId + "/" + fileName;
                string fullDirectory = Path.Combine(settings.RootDirectory + "\\" + settings.QRFolder, codePath);
                if (!string.IsNullOrEmpty(activity.CodePath) && File.Exists(Path.Combine(settings.RootDirectory + "\\" + settings.QRFolder, activity.CodePath.Replace('/', '\\'))))
                {
                    return(activity.CodePath);
                }
                string parameter = string.Empty;// string.Format("agentId={0}&customerId={1}&activityId={2}", agendId, customerId, activityId);
                SortedDictionary <string, string> ps = new SortedDictionary <string, string>();
                ps["agentId"]    = activity.AgentId.ToString();
                ps["customerId"] = activity.CustomerId.ToString();
                ps["activityId"] = activity.Id.ToString();

                StringBuilder pstr  = new StringBuilder();
                int           count = 1;
                foreach (KeyValuePair <string, string> p in ps)
                {
                    pstr.Append(p.Key);
                    pstr.Append("=");
                    pstr.Append(p.Value);
                    if (count < ps.Count)
                    {
                        pstr.Append("&");
                    }
                    count++;
                }
                parameter = pstr.ToString();
                pstr.Append("&key=");
                pstr.Append(customer.Token);
                parameter = parameter + "&signature=" + UrlSignUtil.GetMD5(pstr.ToString());
                parameter = KMEncoder.Encode(parameter);
                string codeContent = string.Format("{0}/Product/SaoMa?p={1}", settings.WebURL, parameter);
                QRCodeUtil.CreateQRCode(fullDirectory, fileName, codeContent);
                if (File.Exists(Path.Combine(fullDirectory, fileName)))
                {
                    activity.CodePath = absPath;
                }

                db.SaveChanges();
                return(absPath);
            }
        }