public void MergeTest()
        {
            var dictionary1 = new Dictionary <int, int> {
                { 1, 2 }
            };
            var dictionary2 = new Dictionary <int, int> {
                { 3, 4 }
            };
            var dictionary3 = new Dictionary <int, int> {
                { 5, 6 }
            };
            var kvp = new KeyValuePair <int, int>(7, 8);

            dictionary1.Count.ShouldBe(1);
            dictionary2.Count.ShouldBe(1);
            dictionary3.Count.ShouldBe(1);

            Dicts.Add(dictionary1, dictionary2);

            dictionary1.Count.ShouldBe(2);
            dictionary2.Count.ShouldBe(1);
            dictionary3.Count.ShouldBe(1);

            dictionary1.Add(dictionary3);

            dictionary1.Count.ShouldBe(3);
            dictionary2.Count.ShouldBe(1);
            dictionary3.Count.ShouldBe(1);

            dictionary1.Add(kvp);

            dictionary1.Count.ShouldBe(4);
            dictionary2.Count.ShouldBe(1);
            dictionary3.Count.ShouldBe(1);
        }
Ejemplo n.º 2
0
 protected void btnok_Click(object sender, System.EventArgs e)
 {
     if (base.Action.Equals(ActionType.Add.ToString()) && !base.IsAuthorizedOp(ActionType.Add.ToString()))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else if (base.Action.Equals(ActionType.Modify.ToString()) && !base.IsAuthorizedOp(ActionType.Modify.ToString()))
     {
         base.ShowMsg("Không có thẩm quyền");
     }
     else
     {
         DictsInfo dictsInfo = new DictsInfo();
         if (base.IsEdit)
         {
             dictsInfo = Dicts.GetDataById(base.OpID);
         }
         dictsInfo.DictName    = WebUtils.GetString(this.TextBox1.Text);
         dictsInfo.DisplayName = WebUtils.GetString(this.TextBox2.Text);
         if (string.IsNullOrEmpty(dictsInfo.DictName))
         {
             base.ShowMsg("Tên từ điển không thể để trống");
         }
         else if (string.IsNullOrEmpty(dictsInfo.DisplayName))
         {
             base.ShowMsg("Tên hiển thị không thể để trống");
         }
         else
         {
             if (base.Action.Equals(ActionType.Add.ToString()))
             {
                 if (Dicts.ExistsForName(dictsInfo.DictName))
                 {
                     base.ShowMsg("Khóa từ điển đã tồn tại!");
                 }
                 else
                 {
                     dictsInfo.IsSystem = false;
                     if (Dicts.Add(dictsInfo) > 0)
                     {
                         CacheUtils.Del("JsonLeeCMS_CacheForGetDicts");
                         PageBase.log.AddEvent(base.LoginAccount.AccountName, "Thêm từ điển [" + dictsInfo.DictName + "] thành công");
                         MessageUtils.DialogCloseAndParentReload(this);
                     }
                     else
                     {
                         base.ShowMsg("Thao tác thất bại");
                     }
                 }
             }
             if (base.Action.Equals(ActionType.Modify.ToString()))
             {
                 if (Dicts.Update(dictsInfo))
                 {
                     CacheUtils.Del("JsonLeeCMS_CacheForGetDicts");
                     PageBase.log.AddEvent(base.LoginAccount.AccountName, "Sửa đổi từ điển [" + dictsInfo.DictName + "] thành công");
                     MessageUtils.DialogCloseAndParentReload(this);
                 }
                 else
                 {
                     base.ShowMsg("Thao tác thất bại");
                 }
             }
         }
     }
 }