コード例 #1
0
        private void btn_apply_Click(object sender, EventArgs e)
        {
            if (tb_name.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"name\"");
                return;
            }
            if (tb_title.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"title\"");
                return;
            }
            if (rtb_description.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"description\"");
                return;
            }
            if (rtb_content.Equals(string.Empty))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"content\"");
                return;
            }
            if (FeatureImage.Equals(null))
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"Feature Image\"");
                return;
            }
            if (chlb_catogary.CheckedItems.Count == 0)
            {
                Common.Functions.ShowMessgeError("Chưa nhập thông tin \"catogary\"");
                return;
            }

            string CollectionLink = string.Empty;

            if (Obj == null)
            {
                CollectionLink = CheckExistCollectionLink(Common.Functions.getWebNameValid(tb_name.Text));
                if (CollectionLink.Equals(string.Empty))
                {
                    Common.Functions.ShowMessgeError("Không có kết nối đến máy chủ");
                    return;
                }
            }
            else
            {
                CollectionLink = Obj.name;
            }



            var lstImage = pn_imageattach.GetImageAttachList();
            var DeletedImageAttachList = pn_imageattach.DeletedImageAttachList;

            Web_Collections_Model obj = new Web_Collections_Model()
            {
                id           = (Obj == null) ? -1 : Obj.id,
                name         = CollectionLink,
                title        = tb_title.Text,
                content      = rtb_content.Text,
                featureimage = FeatureImage.Link,
                description  = rtb_description.Text,
                relatedmenu  = (int)(chlb_catogary.CheckedItems[0] as Web_Menu_Model).id,
                isdraft      = (Obj == null) ? true: Obj.isdraft
            };

            long id = -1;

            if (controller.Save(obj, ref id))
            {
                obj.id = id;
                if (SendImage(ref obj, ref lstImage, ref DeletedImageAttachList))
                {
                    controller.Update(obj);
                    pn_imageattach.ClearDeletedImageAttachList();
                    //pn_imageattach.StoreImageAttachList(lstImage);
                    Obj = obj;
                    Common.Functions.ShowMessgeInfo("Success");
                    //TODO preview
                    System.Diagnostics.Process.Start(AppConfig.WebUrl + "/other/collectionPreview.php?id=" + obj.id);
                }
                else
                {
                    controller.Delete(obj);
                    Common.Functions.ShowMessgeInfo("Fail");
                }
            }
            else
            {
                Common.Functions.ShowMessgeInfo("Fail");
            }
        }