public void CreateWord(string text, float duration)
 {
     //print(text);
     ChangeFont();
     text_Voice.text = PinYin.GetShowText(text);
     MoveWord(rightPosX, leftPosX, duration);
 }
Exemple #2
0
        public static int CreateUserCategory(string tableName, int pid, int uid, string name, string pinyin = null, string pinyinabbr = null, string ename = null)
        {
            if (pinyin == null)
            {
                pinyin = HZ.ToPinYin(name, true);
            }
            if (pinyinabbr == null)
            {
                pinyinabbr = PinYin.GetInitial(name);
            }
            if (ename == null)
            {
                ename = pinyin;
            }

            return(EB <UserCategoryEntity> .Create(QA.DBCS_CMS, new UserCategoryEntity()
            {
                uid = uid,
                pid = pid,
                name = name,
                pinyin = pinyin,
                pinyinabbr = pinyinabbr,
                ename = ename
            }, tableName));
        }
        public override void InitData()
        {
            LogHelper.Info("初始化{0}数据", RedisKey);

            AddEntity("wenshi", "温室类", "", "");
            AddEntity("wenshi-" + PinYin.Get("花卉"), "花卉", "wenshi", "");
            AddEntity("wenshi-" + PinYin.Get("蔬菜"), "蔬菜", "wenshi", "");

            AddEntity("datian", "大田类", "", "");
            AddEntity("datian-" + PinYin.Get("水稻"), "水稻", "datian", "");
            AddEntity("datian-" + PinYin.Get("小麦"), "小麦", "datian", "");
            AddEntity("datian-" + PinYin.Get("茶叶"), "茶叶", "datian", "");

            AddEntity("bird", "禽类", "", "");
            AddEntity("bird-" + PinYin.Get("鸡舍"), "鸡舍", "bird", "");
            AddEntity("bird-" + PinYin.Get("鸭舍"), "鸭舍", "bird", "");

            AddEntity("livestock", "畜牧类", "", "");
            AddEntity("livestock-" + PinYin.Get("猪舍"), "猪舍", "livestock", "");
            AddEntity("livestock-" + PinYin.Get("羊舍"), "羊舍", "livestock", "");

            AddEntity("aquatic", "水产类", "", "");
            AddEntity("aquatic-" + PinYin.Get("虾"), "虾", "aquatic", "");
            AddEntity("aquatic-" + PinYin.Get("蟹"), "蟹", "aquatic", "");
            AddEntity("aquatic-" + PinYin.Get("鱼"), "鱼", "aquatic", "");

            var result = Repository.Commit();

            LogHelper.Info("共初始化设施类型数据{0}条", result);
        }
Exemple #4
0
        public static int UpdateUserCategory(string tableName, int id, int pid, int uid, string name, string pinyin = null, string pinyinabbr = null, string ename = null)
        {
            if (pinyin == null)
            {
                pinyin = HZ.ToPinYin(name, true);
            }
            if (pinyinabbr == null)
            {
                pinyinabbr = PinYin.GetInitial(name);
            }
            if (ename == null)
            {
                ename = pinyin;
            }

            //check pid & uid
            if (pid != 0 && !DBH.GetBoolean(QA.DBCS_CMS, CommandType.Text, "SELECT COUNT(id) FROM " + tableName + " WHERE pid=@pid AND uid=@uid", new SqlParameter("@pid", pid), new SqlParameter("@uid", uid)))
            {
                return(-1);
            }

            return(EB <UserCategoryEntity> .Update(QA.DBCS_CMS, new UserCategoryEntity()
            {
                id = id,
                uid = uid,
                pid = pid,
                name = name,
                pinyin = pinyin,
                pinyinabbr = pinyinabbr,
                ename = ename
            }, tableName));
        }
Exemple #5
0
        public AjaxMessage CreateSaleSource(FD_SaleSource saleSource)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";
            try
            {
                if (saleSource != null)
                {
                    saleSource.CreateDate     = DateTime.Now;
                    saleSource.CreateEmployee = LoginInfo.UserInfo.EmployeeId;
                    saleSource.Status         = (byte)SysStatus.Enable;
                    saleSource.letter         = PinYin.GetFirstLetter(saleSource.SourceName);

                    var result = _SaleSourceSerrvice.Add(saleSource);
                    if (result != null)
                    {
                        ajax.Message   = "添加成功";
                        ajax.IsSuccess = true;
                    }
                }
            }
            catch (Exception e)
            {
                ajax.Message = e.Message;
            }
            return(ajax);
        }
Exemple #6
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string zi    = context.Request["zi"];
            int    count = Convert.ToInt32(context.Request["count"]);

            List <Books> list = (List <Books>)CacheHelper.GetCache("books");

            if (list == null)
            {
                list = bbl.GetModelList("");
                CacheHelper.SetCache("books", list);
            }
            PinYin p     = new PinYin();
            var    books = list.Where(b => p.GetFirstLetter(b.Title).Contains(zi.ToUpper())).Take(count);

            //每次搜索之后都要将搜索的字存到数据库中
            SearchDetails sd = new SearchDetails()
            {
                KeyWords       = zi,
                SearchDateTime = DateTime.Now
            };

            new SearchDetailsBll().Add(sd);
            //序列化
            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            string json = jss.Serialize(books);

            //输出
            context.Response.Write(json);
        }
        private void PhoneticNotation_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Word[] words = new Word[InputText.Text.Length];
                for (int i = 0; i != InputText.Text.Length; i++)
                {
                    string kana = "";
                    string tone = "";
                    if (initialTable[PinYin.GetPinYin(InputText.Text[i])] != null)
                    {
                        foreach (string temp in initialTable[PinYin.GetPinYin(InputText.Text[i])].ToObject <string[]>())
                        {
                            kana = kana + temp + " ";
                            tone = PinYin.GetTone(InputText.Text[i]);
                        }
                    }

                    words[i] = new Word
                    {
                        Tone       = tone,
                        Kana       = kana,
                        SourceText = InputText.Text[i].ToString()
                    };
                }

                WordItemsControl.ItemsSource = words;
            }
            catch (Exception ex)
            {
                MainWindow.ContentFrame.Navigate(new Crush_Page(ex));
            }
        }
 /// <summary>
 /// 修改商品
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 public bool Update(UpdateGoodsDto dto)
 {
     using (var commodityDbContext = new CommodityDbContext())
     {
         dto.Price = System.Decimal.Round(System.Decimal.Floor(dto.Price * 100) / 100, 2);
         //判断标签的id是否存在
         if (commodityDbContext.LabelRepos.Where(o => dto.Tags.Contains(o.Id)).Count() != dto.Tags.Length)
         {
             throw new Exception("有标签不存在");
         }
         //修改Goods表
         var entity = commodityDbContext.GoodsRepos.Where(o => o.Id == dto.Id).FirstOrDefault();
         if (entity == null)
         {
             throw new Exception("商品不存在");
         }
         entity.Name     = dto.Name;
         entity.Pinyin   = PinYin.ConvertCh(dto.Name).ToLower();
         entity.Price    = dto.Price;
         entity.Describe = dto.Describe;
         //删除label_goods表中所有与该商品有关的记录
         commodityDbContext.Database.ExecuteSqlCommand(@"delete from label_goods where goods_id = @p0", dto.Id);
         //往label_goods表中添加该商品的标签
         foreach (var Tag in dto.Tags)
         {
             commodityDbContext.LabelGoodsRepos.Add(new LabelGoodsRepo()
             {
                 Goods_id = entity.Id,
                 Label_id = Tag
             });
         }
         return(commodityDbContext.SaveChanges() > 0);
     }
 }
 public virtual JsonResult DropList(string filterExpression, string pySearch)
 {
     try
     {
         ClearClientPageCache(Response);
         IEntry rep = EntryRepository;
         CacheInit.RefreshCache(HttpContext, rep, ControllerName + "DropList", DateTime.Now.AddMinutes(CacheExpiryMinute), CachePriority, CacheCreateType.IfNoThenGenerated);
         DataTable source = (DataTable)HttpContext.Cache[ControllerName + "DropList"];
         filterExpression = DFT.HandleExpress(filterExpression);
         List <DropListSource> dropList = rep.DropList(source, filterExpression);
         if (DataConvert.ToString(pySearch) != "")
         {
             List <DropListSource> filterDrop = new List <DropListSource>();
             foreach (var obj in dropList)
             {
                 string   pyf  = PinYin.GetFirstPinyin(DataConvert.ToString(obj.Text)).ToUpper();
                 string[] pyfs = pyf.Split(',');
                 foreach (string py in pyfs)
                 {
                     if (py.StartsWith(pySearch.ToUpper()) && !filterDrop.Contains(obj))
                     {
                         filterDrop.Add(obj);
                     }
                 }
             }
             return(DropListJson(filterDrop));
         }
         return(DropListJson(dropList));
     }
     catch (Exception ex)
     {
         AppLog.WriteLog(AppMember.AppText["SystemUser"], LogType.Error, "MasterController.DropList", ControllerName + "[Message]:" + ex.Message + " [StackTrace]:" + ex.StackTrace);
         return(new JsonResult());
     }
 }
Exemple #10
0
        /// <summary>
        /// 数据绑定
        /// </summary>
        public void BinderData()
        {
            int sourceCount = 0;
            List <Expression <Func <FD_SaleSource, bool> > > parmList = new List <Expression <Func <FD_SaleSource, bool> > >();
            Expression <Func <FD_SaleSource, DateTime?> >    Order    = c => c.CreateDate;

            if (!string.IsNullOrEmpty(Request["txtSourceName"]))
            {
                string name = Request["txtSourceName"].ToString();
                parmList.Add(c => c.SourceName.Contains(name));
            }

            if (ddlSaleType.SelectedValue.ToInt32() > 0)
            {
                parmList.Add(c => c.SaleTypeId.ToString() == ddlSaleType.SelectedValue);
            }

            var DataList = _saleSourceService.GetPagedList <DateTime?>(CtrPageIndex.CurrentPageIndex, CtrPageIndex.PageSize, ref sourceCount, parmList, Order, false);

            CtrPageIndex.RecordCount = sourceCount;
            foreach (var item in DataList)
            {
                item.letter = PinYin.GetFirstLetter(item.SourceName);
                _saleSourceService.Update(item);
            }
            SavePage(CtrPageIndex);
            repSaleSource.DataSource = DataList;
            repSaleSource.DataBind();
        }
        public AjaxMessage InsertHotel(FD_Hotel hotel)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";
            if (hotel != null)
            {
                bool isExists = _hotelService.IsExists(hotel.HotelName);
                if (isExists == false)          //酒店不存在  就新增
                {
                    hotel.CreateDate = DateTime.Now;
                    hotel.Letter     = PinYin.GetFirstLetter(hotel.HotelName.ToString());
                    hotel.Status     = (byte)SysStatus.Enable;

                    int result = _hotelService.Insert(hotel);
                    if (result > 0)
                    {
                        ajax.IsSuccess = true;
                        ajax.Message   = "添加成功";
                    }
                }
                else
                {
                    ajax.Message = "酒店名称已经存在";
                }
            }

            return(ajax);
        }
Exemple #12
0
        public static int RenameUserCategory(string tableName, int id, string name)
        {
            string pinyin     = HZ.ToPinYin(name, true);
            string pinyinabbr = PinYin.GetInitial(name);

            return(DBH.ExecuteText(QA.DBCS_CMS, "UPDATE " + tableName + " SET name=@name,pinyin=@pinyin,pinyinabbr=@pinyinabbr,ename=@ename WHERE id=@id",
                                   new SqlParameter("@name", name), new SqlParameter("@pinyin", pinyin), new SqlParameter("@pinyinabbr", pinyinabbr), new SqlParameter("@ename", pinyin), new SqlParameter("@id", id)));
        }
Exemple #13
0
        public void TestGetPinYin()
        {
            var text = "万科新网大厦 11-402";

            var text2 = "导语:为病患的生命考虑售卖“印度药”,在法律层面的确有争议,但在道德层面,善恶层面,是非层面,不应该有争议。文 | 丁阳2月25日,山东卫视播出的山东新闻联播“今日聚焦”播出了一期节目《聊城:主任医师竟然开假药》,说的是聊城市肿瘤医院陈医生向患者推荐抗癌药“卡博替尼”(印度仿制药)并提供购买渠道,使用之后,患者出现各种不良反应,然后去世。家属把药拿去食药监鉴定,结论是该药没有批准文号,被认定为假药。节目于是就猛烈抨击陈医生“卖假药”。该节目在医生群体中引发了轩然大波,称这又是一起陆勇案,甚至抨击报道之余还自嘲“病人死活,关你什么事”。如何看待这起事件?陈医生“好心没好报”,只会让医患关系更加紧张,让医生诊疗时趋向保守该事件曝光之后,有很多人立马想到了数年前引发关注的陆勇案,以及去年的话题电影《我不是药神》。没错,这两个事件以及电影,核心问题都在于,一些“国外仿制药”因为没有中国药监机构的生产或进口批文,而被认定为假药。“卡博替尼”,并不是那种一般认识上那种骗钱的、用淀粉制成的假药,而是货真价实的抗癌药,只不过陈医生推荐的是在印度生产的“仿制版”,在印度都没有批文,遑论在中国了。在很多医生看来,陈医生可以说是有着“把患者当亲人”的心态,才会把“卡博替尼”以及相关购买渠道推荐给癌症患者的——在正规治疗和药物已经没有办法的情况下,冒着风险介绍了“非正规”的续命手段,用“假药”来给癌细胞踩刹车。结果呢,家属当时就录了音,用来作为陈医生主动“卖假药”的证据,在患者离世后,找媒体曝光,严厉指责陈医生卖假药。这岂不是典型的“好心没好报”吗?不少医生自嘲,陈医生错就错在不应该提供购买渠道,“病人死活,关你什么事。你推荐他们买的药这么贵,治好了病人有可能说你是拿了回扣。病人要是最后还是死了,你就是卖假药,图财害命。”“以后就算是要推荐最新抗癌靶向药,一定不能推荐购买渠道,病人买不到关你什么事。”样的人完全没有违法,而是认为其有触犯法律,这是对法律的尊重,对执法人员的尊重,也能保护医药生产商开发新药的积极性,但出于情理考虑,由于情节轻微可以不起诉。当然,前面提到的最高检“意见”——即在某些情况下销售“仿制药”不视为犯罪,能更加让陆勇们放心。一些专家认为,从法律层面来看,“不起诉”、“意见”等措施已经是比较好的做法。法律层面做不到的,舆论层面应该做到——支持陈医生,谴责纵容家属泼污的不良报道然而法律层面这种偏灵活性的做法,其缺点在于,相对模糊,很多人依然无法搞明白国家对陆勇案或者本次聊城假药案的态度。像这次的山东媒体,在医生群体发出了强烈的抗议讯号之后,依然不觉得报道有问题,拿着法律条文坚持陈医生推荐特殊的情形,合理的办法还是“酌定不起诉”。换句话说,就是不能认为陆勇这的就是假药,甚至对当地公安施加压力,从之前的因情节显著轻微不予刑事立案,到现在对陈医生进行立案侦查。对于这种情况,从法律层面对陈医生进行维护,从此前司法机关的态度来看,或不是关键。重要的是,在舆论层面,对陈医生进行维护。没错,为病患的生命考虑售卖“印度药”,在法律层面的确有争议,但在道德层面,善恶层面,是非层面,不应该有争议。在陆勇案与《我不是药神》引发社会反响后,媒体在报道涉“印度药”的选题时,本来就应该非常谨慎——这并不是说,媒体就不该理会患者家属的看法,一昧偏帮医生,而是说,报道一定要有根有据。决不能够说,怀疑其中有猫腻,认为需要媒体监督,就随意在新闻报道中称某个医生或某个病人在“销售假药”。这对于本就艰难,处于灰色地带的特定人群来说,这种报道可能会构成毁灭性的打击。毕竟,媒体作为公器,也会对执法者构成压力。媒体决不能为了吸引眼球,为了把事情搞大,就罔顾基本道义与良知,做片面报道。";

            var pinYin            = PinYin.GetPinYin(text, PinYinType.拼音);
            var pinYinFirstLetter = PinYin.GetPinYin(text, PinYinType.拼音首字母);
        }
Exemple #14
0
 /// <summary>
 /// 初始化
 /// </summary>
 public override void Init()
 {
     base.Init();
     if (!PinYin.IsEmpty())
     {
         PinYin = PinYin.ToLower();
     }
     Code = "1";
 }
Exemple #15
0
        static void Test2()
        {
            var ss = PinYin.GetMulti('石');

            Console.WriteLine(ss.Join());

            var count = UserX.Meta.Count;

            "共有{0}行数据".F(count).SpeakAsync();
        }
        /// <summary>
        /// 获取给定拼音的所有同音字。该操作不考虑拼音字符串中所包含的声调部分,意即返回该拼音全拼部分所有声调(1声 - 5声)的所有同音字。
        /// <para>如果传入的字符串不是一个有效的拼音值,则该方法将返回 null。</para>
        /// </summary>
        /// <param name="pinyin"></param>
        /// <returns></returns>
        public static ReadOnlyCollection <char> GetCharsWithNonTone(string pinyin)
        {
            PinYin p = null;

            if (!PinYin.TryParse(pinyin, false, out p))
            {
                return(null);
            }
            return(p.GetCharsWithNonTone());
        }
        private ReadOnlyCollection <PinYin> GetPinYins()
        {
            List <PinYin> list = new List <PinYin>(this.PinYinTexts.Count);

            foreach (string text in this.PinYinTexts)
            {
                PinYin pinyin = PinYin.Parse(text);
                list.Add(pinyin);
            }
            return(new ReadOnlyCollection <PinYin>(list));
        }
        protected void btnChangeCustCode_Click(object sender, EventArgs e)
        {
            CustomerService svr      = new CustomerService();
            DataTable       dt       = svr.GetCustomer();
            string          custCode = "";

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                custCode = PinYin.GetChineseSpell(dt.Rows[i]["CustName"].ToString());
                svr.dataCtx.ExecuteCommand("update crmcustomer set custcode='" + custCode + "' where custID=" + dt.Rows[i]["CustID"]);
            }
        }
Exemple #19
0
        protected override void InitData()
        {
            base.InitData();

            // InitData一般用于当数据表没有数据时添加一些默认数据,该实体类的任何第一次数据库操作都会触发该方法,默认异步调用
            // Meta.Count是快速取得表记录数
            if (Meta.Count > 0)
            {
                return;
            }

            // 需要注意的是,如果该方法调用了其它实体类的首次数据库操作,目标实体类的数据初始化将会在同一个线程完成
            if (XTrace.Debug)
            {
                XTrace.WriteLine("开始初始化{0}[{1}]数据……", typeof(Info).Name, Meta.Table.DataTable.DisplayName);
            }

            // 遍历分类
            NewLife.CMX.Category.Meta.Session.WaitForInitData();

            var sb = new StringBuilder();

            for (var i = 0; i < 20; i++)
            {
                sb.AppendLine("新生命开发团队,学无先后达者为师<br>");
            }
            var txt = sb.ToString();

            foreach (var item in NewLife.CMX.Category.FindAllWithCache())
            {
                var entity = new Info()
                {
                    ModelID     = item.ModelID,
                    CategoryID  = item.ID,
                    Title       = "{0}信息".F(item.Name),
                    ContentText = txt,
                };
                // 顶级分类的信息,设置编码
                if (item.ParentID == 0)
                {
                    entity.Code = PinYin.GetFirst(entity.Title);
                }

                entity.Insert();
            }

            if (XTrace.Debug)
            {
                XTrace.WriteLine("完成初始化{0}[{1}]数据!", typeof(Info).Name, Meta.Table.DataTable.DisplayName);
            }
        }
Exemple #20
0
        static void Main(string[] args)
        {
            PinYin p = new PinYin();

            Console.WriteLine(p.GetChineseSpell("甲乙丙丁"));
            Console.WriteLine(p.GetChineseSpell("重量"));
            Console.WriteLine(p.GetChineseSpell("重庆"));


            p.Test('国');
            p.Test('重');

            Console.ReadLine();
        }
Exemple #21
0
        public NodesFragment()
        {
            InitializeComponent();
            var loaded = Observable.FromEventPattern <RoutedEventArgs>(AllNodesFragment, nameof(AllNodesFragment.Loaded))
                         .SelectMany(x => ApiClient.GetNodes())
                         .Retry(10)
                         .Select(x =>
            {
                return(x.GroupBy(y =>
                {
                    var begin = y.Title.Trim().First();
                    if (begin >= 'A' && begin <= 'Z')
                    {
                        return $"{begin}";
                    }
                    if (begin >= 'a' && begin <= 'z')
                    {
                        return $"{(char)(begin + 'A' - 'a')}";
                    }
                    if (begin >= 0 && begin <= 256)
                    {
                        return "0-9";
                    }
                    var first = PinYin.GetFirstPinyin(begin.ToString());
                    return string.IsNullOrEmpty(first) ? "其他" : first;
                })
                       .Select(y => new NodeInGroup {
                    Key = y.Key, NodeContent = y.ToList()
                })
                       .OrderBy(y => y.Key));
            })
                         .ObserveOnCoreDispatcher()
                         .Subscribe(x =>
            {
                SortNodesCVS.Source = x;
                OutView.ItemsSource = SortNodesCVS.View.CollectionGroups;
                InView.ItemsSource  = SortNodesCVS.View;
            });
            var click = Observable.FromEventPattern <ItemClickEventArgs>(InView, nameof(InView.ItemClick))
                        .Select(x => x.EventArgs.ClickedItem as NodeModel)
                        .ObserveOnCoreDispatcher()
                        .Subscribe(x => PageStack.Next("Left", "Right", typeof(OneNodeTopicsView), x));

            this.Unloaded += (s, e) =>
            {
                loaded.Dispose();
                click.Dispose();
            };
        }
Exemple #22
0
 public async Task <IHttpActionResult> Update([FromBody] CompanyModel company)
 {
     return(await ResultFactory.Create(ModelState, async arg =>
     {
         var result = await companyService.UpdateAsync(new CompanyDto
         {
             Name = company.Name,
             Pinyin = PinYin.GetFirst(company.Name).ToUpper(),
             Sort = 0,
             Status = 1,
             UpdateTime = DateTime.Now
         }) > 0;
         return new ApiResult(result ? ExceptionCode.Success : ExceptionCode.InternalError, "", null);
     }, company, "success", "请检查请求参数"));
 }
Exemple #23
0
        void LoadFonts()
        {
            //装载系统字体
            InstalledFontCollection _installedFonts = new InstalledFontCollection();

            FontFamily[] fonts = _installedFonts.Families;

            foreach (FontFamily f in fonts)
            {
                if (f.IsStyleAvailable(FontStyle.Regular) && PinYin.IsHanzi(f.Name))
                {
                    listFontFamilies.Properties.Items.Add(f.Name);
                }
            }
        }
        private void AddEntity(string serialnum, string name, string parent, string description)
        {
            var entity = new FacilityType();

            entity.Serialnum              = serialnum;
            entity.Name                   = name;
            entity.ParentSerialnum        = parent;
            entity.PhotoUrl               = "FacilityType/" + PinYin.GetFirst(name) + ".png";
            entity.Css                    = "xzss-icon xzss-icon-" + PinYin.GetFirst(name);
            entity.Introduce              = description;
            entity.CreateTime             = DateTime.Now;
            entity.UpdateTime             = DateTime.Now;
            entity.UpdateSysUserSerialnum = "admin";
            entity.Remark                 = "systype";
            Repository.Add(entity);
        }
Exemple #25
0
 /// <summary>
 /// 添加商品
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 public bool Create(CreateGoodsDto dto)
 {
     using (var commodityDbContext = new CommodityDbContext())
     {
         var tran = commodityDbContext.Database.BeginTransaction();
         try
         {
             dto.Price = System.Decimal.Round(System.Decimal.Floor(dto.Price * 100) / 100, 2);
             //若商品编号重复,返回false
             if (commodityDbContext.GoodsRepos.Any(o => o.Number == dto.Number))
             {
                 throw new Exception("商品编号重复");
             }
             //判断标签的id是否存在
             if (commodityDbContext.LabelRepos.Where(o => dto.Tags.Contains(o.Id)).Count() != dto.Tags.Length)
             {
                 throw new Exception("有标签不存在");
             }
             GoodsRepo goods = new GoodsRepo()
             {
                 Number     = dto.Number,
                 Name       = dto.Name,
                 Pinyin     = PinYin.ConvertCh(dto.Name).ToLower(),
                 Price      = dto.Price,
                 Describe   = dto.Describe,
                 Updatetime = DateTime.Now
             };
             commodityDbContext.GoodsRepos.Add(goods);
             commodityDbContext.SaveChanges();
             //往label_goods表中添加该商品的标签
             foreach (var Tag in dto.Tags)
             {
                 commodityDbContext.LabelGoodsRepos.Add(new LabelGoodsRepo()
                 {
                     Goods_id = goods.Id,
                     Label_id = Tag
                 });
             }
             return(commodityDbContext.SaveChanges() > 0);
         }
         catch (Exception ex)
         {
             tran.Rollback();
             throw ex;
         }
     }
 }
Exemple #26
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            //// 如果没有脏数据,则不需要进行任何处理
            //if (!HasDirty) return;

            FixLevel();

            // 名称
            if (Name.IsNullOrEmpty() || Name == FullName)
            {
                FixName();
            }
            if (FullName.IsNullOrEmpty())
            {
                FullName = Name;
            }

            // 拼音
            if (PinYin.IsNullOrEmpty())
            {
                var py = NewLife.Common.PinYin.Get(Name);
                if (!py.IsNullOrEmpty())
                {
                    PinYin = py;
                }
            }
            if (JianPin.IsNullOrEmpty())
            {
                var py = NewLife.Common.PinYin.GetFirst(Name);
                if (!py.IsNullOrEmpty())
                {
                    JianPin = py;
                }
            }

            // 坐标
            //if (Longitude != 0 || Latitude != 0) GeoHash = NewLife.Data.GeoHash.Encode(Longitude, Latitude);
            if (isNew || Dirtys[nameof(Longitude)] || Dirtys[nameof(Latitude)])
            {
                if (Math.Abs(Longitude) > 0.001 || Math.Abs(Latitude) > 0.001)
                {
                    GeoHash = NewLife.Data.GeoHash.Encode(Longitude, Latitude);
                }
            }
        }
Exemple #27
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew"></param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (Name.IsNullOrEmpty())
            {
                throw new ArgumentNullException(_.Name, _.Name.DisplayName + "无效!");
            }
            if (Model == null)
            {
                throw new ArgumentNullException(__.ModelID, _.ModelID.DisplayName + "无效!");
            }

            // 建议先调用基类方法,基类方法会对唯一索引的数据进行验证
            base.Valid(isNew);

            if (Dirtys[__.Code])
            {
                // 已设置代码,检查是否唯一
                if (!Code.IsNullOrEmpty())
                {
                    CheckExist(__.Code);
                }
            }
            else if (isNew)
            {
                // 未设置代码,自动生成
                var code = PinYin.GetFirst(Name);
                Code = code;
                for (var i = 2; i < 100; i++)
                {
                    if (!Exist(__.Code))
                    {
                        break;
                    }

                    Code = code + i;
                }
            }
        }
        /// <summary>
        /// 识别字符是否有指定的读音。一个布尔参数指示在验证时是否同时当前汉字和传入的拼音参数的声调也是否相同。
        /// <para>如果参数 <paramref name="pinyin"/> 字符串尾部是一个不合法的声调数值(不为 1、2、3、4、5 中任何一个值),则无论参数 <paramref name="validateTone"/> 是否为 true,该方法都返回 false。</para>
        /// </summary>
        /// <param name="pinyin"></param>
        /// <param name="validateTone"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">如果参数 <paramref name="pinyin"/> 为 null 或空字符串,则抛出该异常。</exception>
        public bool HasSound(string pinyin, bool validateTone)
        {
            if (string.IsNullOrEmpty(pinyin))
            {
                throw new ArgumentNullException(pinyin);
            }

            PinYin p;

            if (!PinYin.TryParse(pinyin, validateTone, out p))
            {
                return(false);
            }

            return(validateTone
                   //? this.PinYins.Any(item => string.Equals(item.QuanPin, p.QuanPin, StringComparison.Ordinal) && item.Tone == p.Tone)
                ? this._charUnit.PinYinIndexes.Contains(p.PinYinIndex)
                : this.PinYins.Any(item => string.Equals(item.QuanPin, p.QuanPin, StringComparison.Ordinal)));
        }
Exemple #29
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (Name.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Name), "名称不能为空!");
            }

            if (Code.IsNullOrEmpty())
            {
                Code = PinYin.GetFirst(Name);
            }
        }
        public AjaxMessage UpdateHotel(FD_Hotel hotel)
        {
            AjaxMessage ajax = new AjaxMessage();

            ajax.IsSuccess = false;
            ajax.Message   = "";

            bool isExists = _hotelService.UpdateisExists(hotel.HotelID, hotel.HotelName);

            if (isExists == false)
            {
                var m_hotel = _hotelService.GetByID(hotel.HotelID);
                m_hotel.HotelName    = hotel.HotelName;
                m_hotel.Area         = hotel.Area;
                m_hotel.Address      = hotel.Address;
                m_hotel.HotelType    = hotel.HotelType;
                m_hotel.Phone        = hotel.Phone;
                m_hotel.DeskCount    = hotel.DeskCount;
                m_hotel.Start        = hotel.Start;
                m_hotel.End          = hotel.End;
                m_hotel.Sort         = hotel.Sort;
                m_hotel.Label        = hotel.Label;
                m_hotel.LabelContent = hotel.LabelContent;
                m_hotel.Description  = hotel.Description;

                m_hotel.Letter = PinYin.GetFirstLetter(hotel.HotelName.ToString());

                int result = _hotelService.Update(m_hotel);
                if (result > 0)
                {
                    ajax.IsSuccess = true;
                    ajax.Message   = "修改成功";
                }
            }
            else
            {
                ajax.Message = "酒店名称已经存在";
            }


            return(ajax);
        }
Exemple #31
0
 private void txtName_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         if (txtName.Text != string.Empty)
         {
             PinYin py = new PinYin(txtName.Text.Trim());
             string strShort = py.GetChineseSpell();
             this.txtHelpCode.Text = strShort;
             txtHelpCode.Focus();
         }
     }
 }