示例#1
0
        public int createSupply(SupplyVM vm)
        {
            int ret = 0;


            using (var tran = new TransactionScope())
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    try
                    {
                        var supply = new Supply();
                        supply.CatalogID    = vm.CatalogId;
                        supply.Quantity     = vm.Quantity;
                        supply.Mobile       = vm.Mobile;
                        supply.Contact      = vm.Contact;
                        supply.Description  = vm.Description;
                        supply.DeliveryType = vm.DeliveryType;
                        supply.SupplyType   = vm.SupplyType;
                        supply.Product      = vm.Product;
                        supply.Creater      = vm.Creater;
                        supply.Price        = vm.Price;
                        //supply.isChecked = false;初始为空,0拒绝,1同意

                        var provice = ctx.Provinces.FirstOrDefault(o => o.Name == vm.Provice);
                        if (provice != null)
                        {
                            var city = ctx.Provinces.FirstOrDefault(o => o.ParentID == provice.ID && o.Name == vm.City);
                            if (city != null)
                            {
                                supply.ProviceID = city.ID;
                            }
                        }
                        supply.CreateDate = DateTime.Now;
                        ctx.Supplies.Add(supply);
                        ctx.SaveChanges();

                        foreach (var imgName in vm.Images)
                        {
                            Image img = new Image();
                            img.Name     = imgName;
                            img.SupplyID = supply.ID;
                            ctx.Images.Add(img);
                        }
                        ctx.SaveChanges();
                        tran.Complete();
                        ret = supply.ID;
                    }
                    catch (DbEntityValidationException)
                    {
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(ret);
        }
 public bool SaveUserCompany(string mobile, UserCompanyInfoVM company)
 {
     using (var ctx = new ShtxSms2008Entities())
     {
         try
         {
             var cb = ctx.CustomerBases.FirstOrDefault(o => o.SendInterFace == 102 && o.Tel.Contains(mobile));
             if (cb != null)
             {
                 cb.AppAddressDesc  = company.AppAddressDesc;
                 cb.AppBusinessDesc = company.AppBusinessDesc;
                 cb.AppCity         = company.AppCity;
                 cb.AppCompanyName  = company.AppCompanyName;
                 cb.AppCompanyPics  = company.AppCompanyPics;
                 cb.AppCustomerName = company.AppCustomerName;
                 cb.AppIndustry     = company.AppIndustry;
                 cb.AppProduct      = company.AppProduct;
                 cb.AppProvince     = company.AppProvince;
                 cb.IsOpenMsg       = company.IsOpenMsg;
                 cb.AppTel          = company.AppTel;
                 ctx.SaveChanges();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
示例#3
0
        public bool deleteSupply(int id)
        {
            bool flag = false;

            using (TransactionScope tran = new TransactionScope())
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    var images = ctx.Images.Where(o => o.SupplyID == id).ToList();
                    foreach (var image in images)
                    {
                        ctx.Images.Remove(image);
                    }
                    var supply = ctx.Supplies.FirstOrDefault(o => o.ID == id);
                    if (supply != null)
                    {
                        ctx.Supplies.Remove(supply);
                    }
                    ctx.SaveChanges();
                    tran.Complete();
                    flag = true;
                }
            }

            return(flag);
        }
        public bool saveTrade(TradeVM tradeVm, string tradePics)
        {
            bool flag = false;

            using (var tran = new TransactionScope())
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    try
                    {
                        Supply supply = new Supply();
                        supply.buissnes     = tradeVm.Buissnes; //所属行业
                        supply.Product      = tradeVm.Product;  //名称
                        supply.Quantity     = tradeVm.Quantity;
                        supply.Price        = tradeVm.Price;
                        supply.Contact      = tradeVm.Contact;
                        supply.Mobile       = tradeVm.ContactTel;
                        supply.Description  = tradeVm.Description;
                        supply.DocumentType = tradeVm.DocumentType;
                        supply.provinceName = tradeVm.Province;
                        supply.cityName     = tradeVm.City;
                        supply.Creater      = tradeVm.Mobile;
                        supply.CreateDate   = DateTime.Now;

                        ctx.Supplies.Add(supply);

                        if (!string.IsNullOrWhiteSpace(tradePics))
                        {
                            string[] pics = tradePics.Split(new string[] { "|||" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var pic in pics)
                            {
                                Image image = new Image();
                                image.SupplyID = supply.ID;
                                image.Name     = pic;
                                var path    = Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "upload");
                                var picPath = Path.Combine(path, pic);
                                var path1   = Path.GetFileNameWithoutExtension(picPath) + "-1" + Path.GetExtension(picPath);

                                System.Drawing.Image imgOutput  = System.Drawing.Bitmap.FromFile(picPath);
                                System.Drawing.Image imgOutput2 = imgOutput.GetThumbnailImage(60, 60, null, IntPtr.Zero);
                                imgOutput2.Save(path1);

                                ctx.Images.Add(image);
                            }
                        }

                        ctx.SaveChanges();

                        tran.Complete();
                        flag = true;
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(flag);
        }
 public void addCount()
 {
     using (var ctx = new ShtxSms2008Entities())
     {
         ApkDownload download = new ApkDownload()
         {
             downloadtime = DateTime.Now
         };
         ctx.ApkDownloads.Add(download);
         ctx.SaveChanges();
     }
 }
示例#6
0
        public bool saveGroupChannel(string mobile, string groupChannels, int flag)
        {
            bool       ret    = false;
            List <int> groups = new List <int>();

            string[] strGroups = groupChannels.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < strGroups.Length; i++)
            {
                if (!string.IsNullOrWhiteSpace(strGroups[i]))
                {
                    int groupId = Convert.ToInt32(strGroups[i]);
                    if (groupId != 0)
                    {
                        groups.Add(groupId);
                    }
                }
            }
            try
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    var myAppGroups = ctx.MyAppGroups.Where(o => o.tel == mobile && o.Flag == flag).ToList();
                    ctx.MyAppGroups.RemoveRange(myAppGroups);

                    int index = 1;
                    foreach (var groupId in groups)
                    {
                        MyAppGroup group = new MyAppGroup();
                        group.tel          = mobile;
                        group.GroupID      = groupId;
                        group.DisplayOrder = index++;
                        group.Flag         = flag;
                        ctx.MyAppGroups.Add(group);
                    }
                    ctx.SaveChanges();
                    ret = true;
                }
            }
            catch (Exception)
            {
            }

            return(ret);
        }
        public bool renew(string mobile)
        {
            bool flag = false;

            using (var ctx = new ShtxSms2008Entities())
            {
                CustomerExtend ce = ctx.CustomerExtend.FirstOrDefault(o => o.SendInterFace == 102 && o.Tel.Contains(mobile));
                if (ce != null)
                {
                    DateTime endTime = ce.EndDate.Value;
                    ce.FirstDate = endTime;
                    ce.EndDate   = endTime.AddYears(1);
                    ce.Valid     = true;
                    ce.CusKind   = 1;
                    ctx.SaveChanges();
                    flag = true;
                }
            }
            return(flag);
        }
示例#8
0
 public bool ClearSaltByMobile(string mobile)
 {
     try
     {
         using (var ctx = new ShtxSms2008Entities())
         {
             var cbs = ctx.AppCustomerTokens.Where(o => o.tel.Contains(mobile));
             foreach (var cb in cbs)
             {
                 cb.salt = 0;
             }
             ctx.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
        public bool SetUserInfoSound(string mobile, bool isSound)
        {
            bool flag = false;

            try
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    var appCustomer = ctx.AppCustomerTokens.FirstOrDefault(o => o.tel == mobile);
                    if (appCustomer != null)
                    {
                        appCustomer.isSound = isSound;
                        ctx.SaveChanges();
                    }
                }
                flag = true;
            }
            catch (Exception)
            {
            }

            return(flag);
        }
        public bool addGps(string mobile, int productId, bool isOrder)
        {
            bool flag = false;

            lock (obj)
            {
                using (var ctx = new ShtxSms2008Entities())
                {
                    try
                    {
                        CustomerBase cb = ctx.CustomerBases.FirstOrDefault(o => o.Tel.Contains(mobile) && o.SendInterFace == 102);
                        if (cb != null)
                        {
                            string tel = cb.Tel;
                            if (isOrder)
                            {
                                //订阅
                                var count = ctx.Gps.Count(o => o.Tel == tel && o.ProductID == productId);
                                if (count > 0)
                                {
                                    return(true);
                                }
                                else
                                {
                                    var product = ctx.SmsProducts.FirstOrDefault(o => o.ProductId == productId);
                                    if (product != null)
                                    {
                                        Gp gps = new Gp();
                                        gps.MarketID    = product.MarketId;
                                        gps.Tel         = tel;
                                        gps.ProductID   = productId;
                                        gps.RoleID      = 15;
                                        gps.ProductNum  = product.ProductNum;
                                        gps.ProductSum  = product.ProductSum;
                                        gps.ProductKind = product.ProductKind;
                                        ctx.Gps.Add(gps);
                                        ctx.SaveChanges();
                                        flag = true;
                                    }
                                }
                            }
                            else
                            {
                                //取消
                                Gp gps = ctx.Gps.FirstOrDefault(o => o.Tel == tel && o.ProductID == productId);
                                if (gps != null)
                                {
                                    ctx.Gps.Remove(gps);
                                    ctx.SaveChanges();
                                    flag = true;
                                }
                                else
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(flag);
        }
        public bool Login(string mobile, string pwd, string token, int phoneType)
        {
            bool loginSuccess  = false;
            var  flag          = false;
            var  tokenTel      = "";
            var  tokenToken    = "";
            var  exitPhoneType = "0";

            if (mobile.Length != 11)
            {
                //电话号码不正确
                return(false);
            }
            //using (TransactionScope tran = new TransactionScope())
            //{
            using (var ctx = new ShtxSms2008Entities())
            {
                try
                {
                    loginSuccess = CheckUser(mobile, pwd);
                    if (loginSuccess)
                    {
                        var list   = ctx.CustomerBases.Where(o => o.Tel.Contains(mobile));
                        var tokens = ctx.AppCustomerTokens.Where(o => o.tel == mobile).ToList();
                        int count  = 0;
                        for (int i = 0; i < tokens.Count(); i++)
                        {
                            if (!string.IsNullOrWhiteSpace(tokens[i].devicetoken))
                            {
                                count++;
                            }
                        }
                        if (count == 0)
                        {
                            var appCustomerToken = ctx.AppCustomerTokens.FirstOrDefault(o => o.tel == mobile);
                            if (appCustomerToken == null)
                            {
                                var appToken = new AppCustomerToken();
                                appToken.tel         = mobile;
                                appToken.salt        = 0;
                                appToken.devicetoken = token;
                                appToken.updatedate  = DateTime.Now;
                                appToken.PhoneType   = phoneType;
                                ctx.AppCustomerTokens.Add(appToken);
                                //Log.WriteLog("Login,count=0", "tel=" + mobile + ",token=" + token);
                            }
                            else
                            {
                                appCustomerToken.tel         = mobile;
                                appCustomerToken.salt        = 0;
                                appCustomerToken.devicetoken = token;
                                appCustomerToken.PhoneType   = phoneType;
                                appCustomerToken.updatedate  = DateTime.Now;
                            }
                        }
                        else
                        {
                            var appToken = ctx.AppCustomerTokens.FirstOrDefault(o => o.tel.Contains(mobile));
                            if (appToken.devicetoken != token)
                            {
                                ////写一条记录到app——sms
                                //AddMagForAPPSMS(appToken.tel,appToken.devicetoken);
                                tokenTel              = appToken.tel;
                                tokenToken            = appToken.devicetoken;
                                appToken.salt         = 0;
                                appToken.devicetoken  = token;
                                appToken.PrePhoneType = appToken.PhoneType;
                                exitPhoneType         = appToken.PrePhoneType.Value.ToString();
                                flag = true;
                            }
                            appToken.PhoneType  = phoneType;
                            appToken.updatedate = DateTime.Now;
                        }
                        ctx.SaveChanges();

                        //tran.Complete();
                    }
                    //return loginSuccess;
                }
                catch
                {
                }
                //}
            }

            if (flag)
            {
                //写一条记录到app——sms
                AddMagForAPPSMS(tokenTel, tokenToken, exitPhoneType);
            }
            return(loginSuccess);
        }
        public TrialError addTrial(string mobile)
        {
            string tel;

            if (mobile.Length != 11)
            {
                return(TrialError.Invalid);
            }

            lock (obj)
            {
                TrialError error = canotAdd(mobile);
                if (error == TrialError.OK)
                {
                    try
                    {
                        string pwd = createPwd();
                        using (TransactionScope tran = new TransactionScope())
                        {
                            using (var ctx = new ShtxSms2008Entities())
                            {
                                var          cbs   = ctx.CustomerBases.Where(o => o.Tel.Contains(mobile)).OrderByDescending(o => o.Tel).ToList();
                                CustomerBase maxCb = cbs.FirstOrDefault();
                                if (cbs.Count() > 0)
                                {
                                    var maxTel = maxCb.Tel;
                                    if (maxTel == mobile)
                                    {
                                        tel = mobile + "-01";
                                    }
                                    else
                                    {
                                        var suf = int.Parse(maxTel.Split(new char[] { '-' })[1]);
                                        tel = mobile + "-" + ((suf + 1).ToString().PadLeft(2, '0'));
                                    }
                                }
                                else
                                {
                                    tel = mobile;
                                }

                                CustomerExtend maxCe = null;
                                if (maxCb != null)
                                {
                                    maxCe = ctx.CustomerExtend.FirstOrDefault(o => o.Tel == maxCb.Tel);
                                }

                                CustomerBase cb = new CustomerBase();
                                cb.Tel           = tel;
                                cb.Name          = (maxCb == null ? "app试用用户" : maxCb.Name);
                                cb.CompanyName   = (maxCb == null ? "app试用用户" : maxCb.CompanyName);
                                cb.SendInterFace = 102;
                                cb.BargainID     = 0;
                                cb.Province      = (maxCb == null ? 3 : maxCb.Province);
                                cb.Sort          = 0;

                                cb.Appsecret   = pwd;
                                cb.ProductLine = 1;

                                CustomerExtend ce = new CustomerExtend();
                                ce.Tel = tel;
                                DateTime today = DateTime.Today;
                                ce.FirstDate        = today;
                                ce.UpdateDate       = DateTime.Now;
                                ce.EndDate          = today.AddDays(14);
                                ce.IsPayment        = false;
                                ce.CusTerm          = 0;
                                ce.UnitPrice        = 0;
                                ce.TotalCon         = 0;
                                ce.CusKind          = 2;
                                ce.Valid            = true;
                                ce.Mid              = (maxCe == null ? "admin" : maxCe.Mid);
                                ce.Defer            = 0;
                                ce.SendInterFace    = 102;
                                ce.BargainID        = 0;
                                ce.RoleID           = 15;
                                ce.EnFlag           = 1;
                                ce.CusSendAttribute = 1;
                                ce.SendRank         = 10;
                                ce.ExtendID         = Guid.NewGuid();

                                App_user user = ctx.App_user.Where(u => u.Tel == mobile).FirstOrDefault();
                                if (user != null)
                                {
                                    user.applyCount++;
                                }
                                else
                                {
                                    user            = new App_user();
                                    user.Tel        = mobile;
                                    user.applyCount = 1;
                                    ctx.App_user.Add(user);
                                }

                                ctx.CustomerBases.Add(cb);
                                ctx.CustomerExtend.Add(ce);

                                ctx.SaveChanges();
                                tran.Complete();
                            }
                        }
                        sendSms(mobile, getMsg(mobile, pwd));
                        return(TrialError.OK);
                    }
                    catch
                    {
                        return(TrialError.SystemError);
                    }
                }
                else
                {
                    return(error);
                }
            }
        }