Esempio n. 1
0
 public void ActionSaveNew(SysResourceModel model)
 {
     if (ValidSave(model))
     {
         SaveNewRedirect(model.RecordID, entity.ID);
     }
 }
Esempio n. 2
0
 public void ActionSave(SysResourceModel model)
 {
     if (ValidSave(model))
     {
         SaveRedirect();
     }
 }
Esempio n. 3
0
        public void ActionIndex(SysResourceModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort, "[Code]");

            // tao danh sach
            var dbQuery = WebResourceService.Instance.CreateQuery()
                          .Where(o => o.LangID == model.LangID)
                          .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Code.Contains(model.SearchText))
                          .Take(model.PageSize)
                          .OrderBy(orderBy)
                          .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data      = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model     = model;
        }
Esempio n. 4
0
        public void ActionAdd(SysResourceModel model)
        {
            if (model.RecordID > 0)
            {
                entity = WebResourceService.Instance.GetByID(model.RecordID);

                // khoi tao gia tri mac dinh khi update
            }
            else
            {
                entity = new WebResourceEntity();

                // khoi tao gia tri mac dinh khi insert
                entity.LangID = model.LangID;
            }

            ViewBag.Data  = entity;
            ViewBag.Model = model;
        }
        public void ActionAdd(SysResourceModel model)
        {
            if (model.RecordID > 0)
            {
                entity = WebResourceService.Instance.GetByID(model.RecordID);

                // khoi tao gia tri mac dinh khi update
            }
            else
            {
                entity = new WebResourceEntity();

                // khoi tao gia tri mac dinh khi insert
                entity.LangID = model.LangID;
            }

            ViewBag.Data = entity;
            ViewBag.Model = model;
        }
Esempio n. 6
0
        private bool ValidSave(SysResourceModel model)
        {
            TryUpdateModel(entity);

            ViewBag.Data  = entity;
            ViewBag.Model = model;

            CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error;

            //kiem tra ma
            if (entity.Code.Trim() == string.Empty)
            {
                CPViewPage.Message.ListMessage.Add("Nhập mã.");
            }

            //kiem tra ton tai
            if (model.RecordID < 1 && WebResourceService.Instance.CP_HasExists(entity.Code, entity.LangID))
            {
                CPViewPage.Message.ListMessage.Add("Mã đã tồn tại.");
            }

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                try
                {
                    //save
                    WebResourceService.Instance.Save(entity);
                }
                catch (Exception ex)
                {
                    Global.Error.Write(ex);
                    CPViewPage.Message.ListMessage.Add(ex.Message);
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 7
0
        public void ActionApply(SysResourceModel model)
        {
            if (model.Type > 0)
            {
                if (model.Type == 1 && !string.IsNullOrEmpty(model.Value1))
                {
                    string[] Arr = model.Value1.Split('\n');
                    for (int i = 0; i < Arr.Length; i++)
                    {
                        string s = Arr[i].Trim();

                        if (string.IsNullOrEmpty(s))
                        {
                            continue;
                        }

                        if (s.StartsWith("//"))
                        {
                            continue;
                        }

                        int index = s.IndexOf('=');
                        if (index == -1)
                        {
                            continue;
                        }

                        string key   = s.Substring(0, index).Trim();
                        string value = s.Substring(index + 1).Trim();

                        if (WebResourceService.Instance.CP_HasExists(key, model.LangID1))
                        {
                            if (model.Overwrite1)
                            {
                                var rs = WebResourceService.Instance.CreateQuery()
                                         .Where(o => o.LangID == model.LangID1 && o.Code == key)
                                         .ToSingle();

                                rs.Value = value;

                                WebResourceService.Instance.Save(rs, o => o.Value);
                            }
                        }
                        else
                        {
                            WebResourceService.Instance.Save(new WebResourceEntity
                            {
                                LangID = model.LangID1,
                                Code   = key,
                                Value  = value
                            });
                        }
                    }
                }
                else if (model.Type == 2)
                {
                    if (model.FLangID2 != model.TLangID2)
                    {
                        var listRS = WebResourceService.Instance.CreateQuery()
                                     .Where(o => o.LangID == model.FLangID2)
                                     .ToList();

                        for (int i = 0; listRS != null && i < listRS.Count; i++)
                        {
                            string key   = listRS[i].Code;
                            string value = listRS[i].Value;

                            if (WebResourceService.Instance.CP_HasExists(key, model.TLangID2))
                            {
                                if (model.Overwrite2)
                                {
                                    var rs = WebResourceService.Instance.CreateQuery()
                                             .Where(o => o.LangID == model.TLangID2 && o.Code == key)
                                             .ToSingle();

                                    rs.Value = value;

                                    WebResourceService.Instance.Save(rs, o => o.Value);
                                }
                            }
                            else
                            {
                                WebResourceService.Instance.Save(new WebResourceEntity
                                {
                                    LangID = model.TLangID2,
                                    Code   = key,
                                    Value  = value
                                });
                            }
                        }
                    }
                }
                else if (model.Type == 3)
                {
                    var listRS = WebResourceService.Instance.CreateQuery()
                                 .Where(o => o.LangID == model.LangID3)
                                 .ToList();

                    for (int i = 0; listRS != null && i < listRS.Count; i++)
                    {
                        string key   = listRS[i].Code;
                        string value = GetTranslate(listRS[i].Value, model.FLangID3, model.TLangID3);

                        if (value != string.Empty)
                        {
                            listRS[i].Value = value;

                            WebResourceService.Instance.Save(listRS[i], o => o.Value);
                        }
                    }
                }

                if ((model.Type == 1 && !string.IsNullOrEmpty(model.Value1)) || model.Type == 2 || model.Type == 3)
                {
                    CPViewPage.SetMessage("Thông tin đã cập nhật.");

                    return;
                }
            }

            if (ValidSave(model))
            {
                ApplyRedirect(model.RecordID, entity.ID);
            }
        }
Esempio n. 8
0
 public void ActionImport(SysResourceModel model)
 {
     ViewBag.Model = model;
 }
Esempio n. 9
0
 public void ActionUpload(SysResourceModel model)
 {
     CPViewPage.Script("Redirect", "HLRedirect('Import')");
 }
        public void ActionApply(SysResourceModel model)
        {
            if (model.Type > 0)
            {
                if (model.Type == 1 && !string.IsNullOrEmpty(model.Value1))
                {
                    string[] Arr = model.Value1.Split('\n');
                    for (int i = 0; i < Arr.Length; i++)
                    {
                        string s = Arr[i].Trim();

                        if (string.IsNullOrEmpty(s))
                            continue;

                        if (s.StartsWith("//"))
                            continue;

                        int index = s.IndexOf('=');
                        if (index == -1)
                            continue;

                        string key = s.Substring(0, index).Trim();
                        string value = s.Substring(index + 1).Trim();

                        if (WebResourceService.Instance.CP_HasExists(key, model.LangID1))
                        {
                            if (model.Overwrite1)
                            {
                                var rs = WebResourceService.Instance.CreateQuery()
                                           .Where(o => o.LangID == model.LangID1 && o.Code == key)
                                           .ToSingle();

                                rs.Value = value;

                                WebResourceService.Instance.Save(rs, o => o.Value);
                            }
                        }
                        else
                        {
                            WebResourceService.Instance.Save(new WebResourceEntity
                            {
                                LangID = model.LangID1,
                                Code = key,
                                Value = value
                            });
                        }
                    }
                }
                else if (model.Type == 2)
                {
                    if (model.FLangID2 != model.TLangID2)
                    {
                        var listRS = WebResourceService.Instance.CreateQuery()
                                           .Where(o => o.LangID == model.FLangID2)
                                           .ToList();

                        for (int i = 0; listRS != null && i < listRS.Count; i++)
                        {
                            string key = listRS[i].Code;
                            string value = listRS[i].Value;

                            if (WebResourceService.Instance.CP_HasExists(key, model.TLangID2))
                            {
                                if (model.Overwrite2)
                                {
                                    var rs = WebResourceService.Instance.CreateQuery()
                                               .Where(o => o.LangID == model.TLangID2 && o.Code == key)
                                               .ToSingle();

                                    rs.Value = value;

                                    WebResourceService.Instance.Save(rs, o => o.Value);
                                }
                            }
                            else
                            {
                                WebResourceService.Instance.Save(new WebResourceEntity
                                {
                                    LangID = model.TLangID2,
                                    Code = key,
                                    Value = value
                                });
                            }
                        }
                    }
                }
                else if (model.Type == 3)
                {
                    var listRS = WebResourceService.Instance.CreateQuery()
                                    .Where(o => o.LangID == model.LangID3)
                                    .ToList();

                    for (int i = 0; listRS != null && i < listRS.Count; i++)
                    {
                        string key = listRS[i].Code;
                        string value = GetTranslate(listRS[i].Value, model.FLangID3, model.TLangID3);

                        if (value != string.Empty)
                        {
                            listRS[i].Value = value;

                            WebResourceService.Instance.Save(listRS[i], o => o.Value);
                        }
                    }
                }

                if ((model.Type == 1 && !string.IsNullOrEmpty(model.Value1)) || model.Type == 2 || model.Type == 3)
                {
                    CPViewPage.SetMessage("Thông tin đã cập nhật.");

                    return;
                }
            }

            if (ValidSave(model))
                ApplyRedirect(model.RecordID, entity.ID);
        }
        private bool ValidSave(SysResourceModel model)
        {
            TryUpdateModel(entity);

            ViewBag.Data = entity;
            ViewBag.Model = model;

            CPViewPage.Message.MessageType = Message.MessageTypeEnum.Error;

            //kiem tra ma
            if (entity.Code.Trim() == string.Empty)
                CPViewPage.Message.ListMessage.Add("Nhập mã.");

            //kiem tra ton tai
            if (model.RecordID < 1 && WebResourceService.Instance.CP_HasExists(entity.Code, entity.LangID))
                CPViewPage.Message.ListMessage.Add("Mã đã tồn tại.");

            if (CPViewPage.Message.ListMessage.Count == 0)
            {
                try
                {
                    //save
                    WebResourceService.Instance.Save(entity);
                }
                catch (Exception ex)
                {
                    Global.Error.Write(ex);
                    CPViewPage.Message.ListMessage.Add(ex.Message);
                    return false;
                }

                return true;
            }

            return false;
        }
 public void ActionUpload(SysResourceModel model)
 {
     CPViewPage.Script("Redirect", "HLRedirect('Import')");
 }
 public void ActionSaveNew(SysResourceModel model)
 {
     if (ValidSave(model))
         SaveNewRedirect(model.RecordID, entity.ID);
 }
 public void ActionSave(SysResourceModel model)
 {
     if (ValidSave(model))
         SaveRedirect();
 }
        public void ActionIndex(SysResourceModel model)
        {
            // sap xep tu dong
            string orderBy = AutoSort(model.Sort, "[Code]");

            // tao danh sach
            var dbQuery = WebResourceService.Instance.CreateQuery()
                                .Where(o => o.LangID == model.LangID)
                                .Where(!string.IsNullOrEmpty(model.SearchText), o => o.Code.Contains(model.SearchText))
                                .Take(model.PageSize)
                                .OrderBy(orderBy)
                                .Skip(model.PageIndex * model.PageSize);

            ViewBag.Data = dbQuery.ToList();
            model.TotalRecord = dbQuery.TotalRecord;
            ViewBag.Model = model;
        }
 public void ActionImport(SysResourceModel model)
 {
     ViewBag.Model = model;
 }