コード例 #1
0
ファイル: YiRenCharge.cs プロジェクト: Bobom/kuanmai
        public void ImportProducts(int resourceId, int operate_user)
        {
            chargebitEntities db = null;
            try
            {
                bool succeed = false;
                List<WebRequestParameters> parmeters = new List<WebRequestParameters>();
                parmeters.Add(new WebRequestParameters("V",version,false));
                parmeters.Add(new WebRequestParameters("Action", "getPackage", false));
                db = new chargebitEntities();
                db.Configuration.AutoDetectChangesEnabled = false;
                KMBit.DAL.Resrouce_interface rInterface = (from ri in db.Resrouce_interface where ri.Resource_id == resourceId select ri).FirstOrDefault<Resrouce_interface>();
                ServerUri = new Uri(rInterface.ProductApiUrl);
                SortedDictionary<string, string> paras = new SortedDictionary<string, string>();
                paras["Account"] = rInterface.Username;
                paras["Type"] = "0";
                string signStr = "";
                foreach(KeyValuePair<string,string> p in paras)
                {
                    if(signStr==string.Empty)
                    {
                        signStr += p.Key.ToLower() + "=" + p.Value;
                    }else
                    {
                        signStr += "&"+p.Key.ToLower() + "=" + p.Value;
                    }
                }
                signStr += "&key="+KMAes.DecryptStringAES(rInterface.Userpassword);
                paras["Sign"] = UrlSignUtil.GetMD5(signStr);
                foreach (KeyValuePair<string, string> p in paras)
                {
                    parmeters.Add(new WebRequestParameters(p.Key,p.Value,false));
                }

                SendRequest(parmeters, false, out succeed);
                if(succeed)
                {
                    if(!string.IsNullOrEmpty(Response))
                    {
                        JObject json = JObject.Parse(Response);
                        string code = json["Code"]!=null? json["Code"].ToString():"";
                        string message= json["Message"] != null ? json["Message"].ToString() : "";
                        if(!string.IsNullOrEmpty(code) && code=="0" && !string.IsNullOrEmpty(message) && message=="OK")
                        {
                            JArray packages = (JArray)json["Packages"];
                            if(packages!=null)
                            {
                                for(int i=0;i<packages.Count;i++)
                                {
                                    JObject package = (JObject)packages[i];

                                    if(package!=null)
                                    {
                                        Resource_taocan taocan = null;
                                        int sp = 0;
                                        int spId = 0;
                                        int.TryParse(package["Type"].ToString(),out sp);
                                        int quantity = 0;
                                        int.TryParse(package["Package"].ToString(), out quantity);
                                        float price = 0;
                                        float.TryParse(package["Price"].ToString(), out price);

                                        if (sp == 2)
                                        {
                                            spId = 3;
                                        }
                                        else if (sp == 1)
                                        {
                                            spId = 1;
                                        }
                                        else if (sp ==3)
                                        {
                                            spId = 2;
                                        }

                                        taocan = (from t in db.Resource_taocan where t.Resource_id==rInterface.Resource_id && t.Quantity==quantity && t.Sp_id== spId select t).FirstOrDefault<Resource_taocan>();
                                        if (taocan != null)
                                        {
                                            taocan.Purchase_price = price;
                                            taocan.UpdatedBy = operate_user;
                                            taocan.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                                            db.SaveChanges();
                                        }
                                        else
                                        {
                                            taocan = new Resource_taocan()
                                            {
                                                Area_id = 0,
                                                CreatedBy = operate_user,
                                                Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                                                Enabled = false,
                                                EnableDiscount = true,
                                                Purchase_price = price,
                                                Quantity = quantity,
                                                Resource_id = rInterface.Resource_id,
                                                Sale_price = price,
                                                Serial = "",
                                                Sp_id = spId,
                                                Taocan_id = 0,
                                                Resource_Discount = 1
                                            };

                                            Taocan ntaocan = (from t in db.Taocan where t.Sp_id == taocan.Sp_id && t.Quantity == taocan.Quantity select t).FirstOrDefault<Taocan>();
                                            Sp spO = (from s in db.Sp where s.Id == taocan.Sp_id select s).FirstOrDefault<Sp>();
                                            if (ntaocan == null)
                                            {
                                                string taocanName = spO != null ? spO.Name + " " + taocan.Quantity.ToString() + "M" : "全网 " + taocan.Quantity.ToString() + "M";
                                                ntaocan = new Taocan() { Created_time = taocan.Created_time, Description = taocanName, Name = taocanName, Sp_id = taocan.Sp_id, Quantity = taocan.Quantity, Updated_time = 0 };
                                                db.Taocan.Add(ntaocan);
                                                db.SaveChanges();
                                            }
                                            if (ntaocan.Id > 0)
                                            {
                                                taocan.Taocan_id = ntaocan.Id;
                                                db.Resource_taocan.Add(taocan);
                                            }
                                        }
                                    }

                                }
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Fatal(ex);
            }
            finally
            {
                if(db!=null)
                {
                    db.Dispose();
                }
            }
        }
コード例 #2
0
ファイル: ResourceManagement.cs プロジェクト: Bobom/kuanmai
        public bool CreateResourceTaocan(Resource_taocan taocan)
        {
            bool ret = false;
            if (!CurrentLoginUser.Permission.CREATE_RESOURCE_TAOCAN)
            {
                throw new KMBitException("没有权限创建资源套餐");
            }

            if (taocan.Quantity <= 0)
            {
                throw new KMBitException("套餐容量不能为零");
            }

            if (taocan.Resource_id <= 0)
            {
                throw new KMBitException("套餐资源信息不能为空");
            }
            int total = 0;
            List<BResource> resources = FindResources(taocan.Resource_id, null, 0, out total);
            if (total == 0)
            {
                throw new KMBitException("资源编号为:" + taocan.Resource_id + " 的资源不存在");
            }
            using (chargebitEntities db = new chargebitEntities())
            {
                string taocanName = taocan.Area_id > 0 ? "省内 " + taocan.Quantity.ToString() + "M" : "全国 " + taocan.Quantity.ToString() + "M";
                Taocan ntaocan = (from t in db.Taocan where t.Sp_id == taocan.Sp_id && t.Quantity == taocan.Quantity && t.Name== taocanName select t).FirstOrDefault<Taocan>();
                Sp sp = (from s in db.Sp where s.Id == taocan.Sp_id select s).FirstOrDefault<Sp>();
                if (ntaocan == null)
                {
                    ntaocan = new Taocan() { Created_time = taocan.Created_time, Description = taocanName, Name = taocanName, Sp_id = taocan.Sp_id, Quantity = taocan.Quantity, Updated_time = taocan.Updated_time };
                    db.Taocan.Add(ntaocan);
                    db.SaveChanges();
                }
                if (ntaocan.Id > 0)
                {
                    Resource_taocan t = (from r in db.Resource_taocan where r.Serial.Trim() == taocan.Serial.Trim() && r.Resource_id==taocan.Resource_id select r).FirstOrDefault<Resource_taocan>();
                    if(t!=null)
                    {
                        throw new KMBitException(string.Format("套餐编号为 {0} 的套餐已经存在", taocan.Serial));
                    }
                    taocan.Taocan_id = ntaocan.Id;
                    db.Resource_taocan.Add(taocan);
                    db.SaveChanges();
                    ret = true;
                }
                else
                {
                    throw new KMBitException("套餐创建失败");
                }

            }
            return ret;
        }
コード例 #3
0
ファイル: ChongBaCharge.cs プロジェクト: Bobom/kuanmai
        public void ImportProducts(int resourceId,int operate_user)
        {
            chargebitEntities db = null;
            try
            {
                bool succeed = false;
                List<WebRequestParameters> parmeters = new List<WebRequestParameters>();
                db = new chargebitEntities();
                db.Configuration.AutoDetectChangesEnabled = false;
                KMBit.DAL.Resrouce_interface rInterface = (from ri in db.Resrouce_interface where ri.Resource_id == resourceId select ri).FirstOrDefault<Resrouce_interface>();
                ServerUri = new Uri(rInterface.ProductApiUrl);
                parmeters.Add(new WebRequestParameters("appKey", rInterface.Username, false));
                parmeters.Add(new WebRequestParameters("appSecret",KMAes.DecryptStringAES(rInterface.Userpassword), false));
                SendRequest(parmeters, false, out succeed);
                if(succeed)
                {
                   if(!string.IsNullOrEmpty(Response))
                    {
                        JArray products = JArray.Parse(Response);
                        if(products!=null && products.Count>0)
                        {
                            for(int i=0;i<products.Count;i++)
                            {
                                Resource_taocan taocan = null;
                                string serial = products[i]["ccode"].ToString();
                                string name = products[i]["cname"].ToString();
                                int quantity = 0;
                                int spId = int.Parse(products[i]["iprotypeid"].ToString());
                                char[] names = name.ToCharArray();
                                StringBuilder qStr = new StringBuilder();
                                Regex regex = new Regex("[^0-9]");
                                for (int j=0;j<names.Length;j++)
                                {
                                    char tmp = names[j];
                                    if (!regex.IsMatch(tmp.ToString()))
                                    {
                                        qStr.Append(tmp.ToString());
                                    }

                                    if(tmp.ToString().ToLower()=="g")
                                    {
                                        quantity = int.Parse(qStr.ToString()) * 1024;
                                        break;
                                    }
                                }
                                if (quantity==0 && qStr.ToString() != "")
                                {
                                    quantity = int.Parse(qStr.ToString());
                                }

                                taocan = (from t in db.Resource_taocan where t.Resource_id==resourceId && t.Serial==serial select t).FirstOrDefault<Resource_taocan>();

                                if (taocan==null)
                                {
                                    //create new product taocan
                                    taocan = new Resource_taocan()
                                    {
                                        Area_id = 0,
                                        CreatedBy = operate_user,
                                        Serial = serial,
                                        Purchase_price = float.Parse(products[i]["iprice"].ToString()),
                                        Quantity = quantity,
                                        Resource_id = resourceId,
                                        Created_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                                        Sale_price = 0,
                                        Enabled = false
                                    };
                                    if (spId == 2)
                                    {
                                        taocan.Sp_id = 1;
                                    }
                                    else if (spId == 3)
                                    {
                                        taocan.Sp_id = 3;
                                    }
                                    else if (spId == 4)
                                    {
                                        taocan.Sp_id = 2;
                                    }

                                    Taocan ntaocan = (from t in db.Taocan where t.Sp_id == taocan.Sp_id && t.Quantity == taocan.Quantity select t).FirstOrDefault<Taocan>();
                                    Sp sp = (from s in db.Sp where s.Id == taocan.Sp_id select s).FirstOrDefault<Sp>();
                                    if (ntaocan == null)
                                    {
                                        string taocanName = sp != null ? sp.Name + " " + taocan.Quantity.ToString() + "M" : "全网 " + taocan.Quantity.ToString() + "M";
                                        ntaocan = new Taocan() { Created_time = taocan.Created_time, Description = taocanName, Name = taocanName, Sp_id = taocan.Sp_id, Quantity = taocan.Quantity, Updated_time = 0 };
                                        db.Taocan.Add(ntaocan);
                                        db.SaveChanges();
                                    }
                                    if (ntaocan.Id > 0)
                                    {
                                        taocan.Taocan_id = ntaocan.Id;
                                        db.Resource_taocan.Add(taocan);
                                    }

                                }else
                                {
                                    //update product taocan
                                    taocan.Purchase_price = float.Parse(products[i]["iprice"].ToString());
                                    taocan.UpdatedBy = operate_user;
                                    taocan.Updated_time = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                                    db.SaveChanges();
                                }
                            }

                            db.SaveChanges();
                        }
                    }
                }
            }
            catch(KMBitException ex)
            { }
            catch(Exception ex)
            { }
            finally
            {
                if (db != null)
                    db.Dispose();
            }
        }
コード例 #4
0
ファイル: ResourceManagement.cs プロジェクト: Bobom/kuanmai
        public bool UpdateResourceTaocan(Resource_taocan taocan)
        {
            bool ret = false;
            if (!CurrentLoginUser.Permission.UPDATE_RESOURCE_TAOCAN)
            {
                throw new KMBitException("没有权限更新资源套餐");
            }
            if (taocan == null || taocan.Id <= 0)
            {
                throw new KMBitException("输入数据不正确,不能更新套餐");
            }

            using (chargebitEntities db = new chargebitEntities())
            {
                Resource_taocan dbTaocan = (from t in db.Resource_taocan where t.Id == taocan.Id select t).FirstOrDefault<Resource_taocan>();
                if (dbTaocan == null)
                {
                    throw new KMBitException("套餐不存在不能更新");
                }
                SyncObjectProperties(dbTaocan, taocan);
                db.SaveChanges();
                ret = true;
            }
            return ret;
        }