コード例 #1
0
        /// <summary>
        /// Thêm mới tin tức
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckCondition())
                {
                    int    id         = 0;
                    string CategoryId = Request.QueryString["ID"];
                    if (int.TryParse(CategoryId, out id))
                    {
                        var cn = db.ImageAlbums.SingleOrDefault(a => a.ImageAlbumId == id);
                        cn.CategoryId     = Convert.ToInt32(ddlCategory.SelectedValue);
                        cn.ImageAlbumText = txtNote.Text;
                        cn.ImageAlbumUrl  = txtLink.Text;
                        cn.ImageOrder     = Convert.ToInt32(txtNumber.Text);
                        cn.ImageTag       = txtImageTag.Text;
                        //thay thế ảnh mới nếu có
                        if (fulImage.HasFile)
                        {
                            //delete ảnh nếu có
                            if (ParadiseHotelPath.Banner_Image_Default != cn.ImageAlbumUrl)//khác default
                            {
                                ParadiseHotelFile.DeleteFile(Setup.host + cn.ImageAlbumUrl);
                            }
                            if (ParadiseHotelPath.Banner_Image_Default != cn.ImageAlbumUrlSmall)//khác default
                            {
                                ParadiseHotelFile.DeleteFile(Setup.host + cn.ImageAlbumUrlSmall);
                            }

                            // thêm ảnh mới
                            if (ParadiseHotelFile.IsFileImage(fulImage.FileName))
                            {
                                ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Banner_Image_Small_Upload);
                                ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Banner_Image_Upload);
                                if (ParadiseHotelFile.StrFoder != "")
                                {
                                    ParadiseHotelFile.CreateFile(ParadiseHotelFile.StrFoder,
                                                                 ParadiseHotelFile.StyleFile.HOUR_MINUTE_SECOND.ToString(),
                                                                 fulImage.FileName);

                                    if (ParadiseHotelFile.StrFile != "")
                                    {
                                        fulImage.PostedFile.SaveAs(ParadiseHotelFile.StrFile);
                                        ParadiseHotelFile.ThayDoiKichThuocAnhNho(ParadiseHotelFile.StrFoder + "Small", ParadiseHotelFile.StrFile.Substring(ParadiseHotelFile.StrFile.LastIndexOf('/') + 1), 200, fulImage.PostedFile.InputStream);
                                        cn.ImageAlbumUrlSmall = ParadiseHotelFile.StrFile.Replace(Setup.host, "").Replace("Banner", "BannerSmall");
                                        cn.ImageAlbumUrl      = ParadiseHotelFile.StrFile.Replace(Setup.host, "");
                                    }
                                }
                            }
                        }

                        db.SubmitChanges();
                        messError.Visible   = false;
                        messSuccess.Visible = true;
                        LoadItem();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
コード例 #2
0
        /// <summary>
        /// Thêm mới
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //try
            //{

            if (CheckCondition())
            {
                var    cn    = new ImageAlbum();
                string index = ddlCategory.SelectedValue.Trim();
                if (index != "-1")
                {
                    cn.CategoryId = Convert.ToInt32(ddlCategory.SelectedValue);
                }


                cn.ImageAlbumText = txtNote.Text;
                cn.ImageOrder     = Convert.ToInt32(txtNumber.Text);
                cn.Ishow          = true;
                cn.ImageTag       = txtImageTag.Text;
                // xu ly anh

                if (fulImage.HasFile)
                {
                    if (ParadiseHotelFile.IsFileImage(fulImage.FileName))
                    {
                        ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Banner_Image_Small_Upload);
                        ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Banner_Image_Upload);
                        if (ParadiseHotelFile.StrFoder != "")
                        {
                            ParadiseHotelFile.CreateFile(ParadiseHotelFile.StrFoder,
                                                         ParadiseHotelFile.StyleFile.HOUR_MINUTE_SECOND.ToString(),
                                                         fulImage.FileName);



                            if (ParadiseHotelFile.StrFile != "")
                            {
                                fulImage.PostedFile.SaveAs(ParadiseHotelFile.StrFile);
                                ParadiseHotelFile.ThayDoiKichThuocAnhNho(ParadiseHotelFile.StrFoder + "Small", ParadiseHotelFile.StrFile.Substring(ParadiseHotelFile.StrFile.LastIndexOf('/') + 1), 200, fulImage.PostedFile.InputStream);
                                cn.ImageAlbumUrlSmall = ParadiseHotelFile.StrFile.Replace(Setup.host, "").Replace("Banner", "BannerSmall");
                                cn.ImageAlbumUrl      = ParadiseHotelFile.StrFile.Replace(Setup.host, "");
                            }
                            else
                            {
                                cn.ImageAlbumUrl      = ParadiseHotelPath.Banner_Image_Default;
                                cn.ImageAlbumUrlSmall = ParadiseHotelPath.Banner_Image_Default;
                            }
                        }
                        else
                        {
                            cn.ImageAlbumUrl      = ParadiseHotelPath.Banner_Image_Default;
                            cn.ImageAlbumUrlSmall = ParadiseHotelPath.Banner_Image_Default;
                        }
                    }
                    else
                    {
                        cn.ImageAlbumUrl      = ParadiseHotelPath.Banner_Image_Default;
                        cn.ImageAlbumUrlSmall = ParadiseHotelPath.Banner_Image_Default;
                    }
                }
                else
                {
                    cn.ImageAlbumUrl      = ParadiseHotelPath.Banner_Image_Default;
                    cn.ImageAlbumUrlSmall = ParadiseHotelPath.Banner_Image_Default;
                }

                db.ImageAlbums.InsertOnSubmit(cn);
                db.SubmitChanges();
                Clear();
                messError.Visible   = false;
                messSuccess.Visible = true;
            }
            //}
            //catch (Exception)
            //{

            //}
        }
コード例 #3
0
        /// <summary>
        /// Cập nhật lại dữ liệu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var pa = db.Contacts.SingleOrDefault(a => a.ContactId != -1);
                if (pa != null)
                {
                    pa.ContactAddress     = txtAddress.Text;
                    pa.ContactAddressEng  = txtAddressEng.Text;
                    pa.Description        = ckDescription.Text;
                    pa.DescriptionEng     = ckDescriptionEng.Text;
                    pa.DescriptionSort    = txtDescriptionSort.Text;
                    pa.DescriptionSortEng = txtDescriptionSortEng.Text;
                    pa.ContactDetail      = ckContactDetail.Text;
                    pa.ContactDetailEng   = ckContactDetailEng.Text;
                    pa.phone = txtPhone.Text;
                    pa.Fax   = txtFax.Text;
                    pa.Email = txtEmail.Text;
                    //thay thế ảnh mới nếu có
                    if (fulImage.HasFile)
                    {
                        //delete ảnh nếu có
                        if (ParadiseHotelPath.Contact_Image_Upload != pa.ImageUrl)//khác default
                        {
                            ParadiseHotelFile.DeleteFile(Setup.host + pa.ImageUrl);
                        }
                        // thêm ảnh mới
                        if (ParadiseHotelFile.IsFileImage(fulImage.FileName))
                        {
                            ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Contact_Image_Upload);
                            if (ParadiseHotelFile.StrFoder != "")
                            {
                                ParadiseHotelFile.CreateFile(ParadiseHotelFile.StrFoder,
                                                             ParadiseHotelFile.StyleFile.HOUR_MINUTE_SECOND.ToString(),
                                                             fulImage.FileName);

                                if (ParadiseHotelFile.StrFile != "")
                                {
                                    fulImage.PostedFile.SaveAs(ParadiseHotelFile.StrFile);

                                    pa.ImageUrl = ParadiseHotelFile.StrFile.Replace(Setup.host, "");
                                }
                                else
                                {
                                    pa.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                                }
                            }
                            else
                            {
                                pa.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                            }
                        }
                        else
                        {
                            pa.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                        }
                    }


                    db.SubmitChanges();
                }
                else
                {
                    var ct = new Contact();
                    ct.ContactAddress     = txtAddress.Text;
                    ct.ContactAddressEng  = txtAddressEng.Text;
                    ct.Description        = ckDescription.Text;
                    ct.DescriptionEng     = ckDescriptionEng.Text;
                    ct.DescriptionSort    = txtDescriptionSort.Text;
                    ct.DescriptionSortEng = txtDescriptionSortEng.Text;
                    ct.ContactDetail      = ckContactDetail.Text;
                    ct.ContactDetailEng   = ckContactDetailEng.Text;
                    ct.phone = txtPhone.Text;
                    ct.Fax   = txtFax.Text;
                    ct.Email = txtEmail.Text;
                    // xu ly anh

                    if (fulImage.HasFile)
                    {
                        if (ParadiseHotelFile.IsFileImage(fulImage.FileName))
                        {
                            ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Contact_Image_Upload);
                            if (ParadiseHotelFile.StrFoder != "")
                            {
                                ParadiseHotelFile.CreateFile(ParadiseHotelFile.StrFoder,
                                                             ParadiseHotelFile.StyleFile.HOUR_MINUTE_SECOND.ToString(),
                                                             fulImage.FileName);

                                if (ParadiseHotelFile.StrFile != "")
                                {
                                    fulImage.PostedFile.SaveAs(ParadiseHotelFile.StrFile);

                                    ct.ImageUrl = ParadiseHotelFile.StrFile.Replace(Setup.host, "");
                                }
                                else
                                {
                                    ct.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                                }
                            }
                            else
                            {
                                ct.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                            }
                        }
                        else
                        {
                            ct.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                        }
                    }
                    else
                    {
                        ct.ImageUrl = ParadiseHotelPath.Contact_Image_Default;
                    }


                    db.Contacts.InsertOnSubmit(ct);
                    db.SubmitChanges();
                }
                messError.Visible   = false;
                messSuccess.Visible = true;
            }
            catch (Exception)
            {
            }
        }
コード例 #4
0
        /// <summary>
        /// Thêm mới một bản ghi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (CheckCondition("", ""))
                {
                    Category cb = new Category();
                    cb.AccountId = Session["AccountId"] != null?int.Parse(Session["AccountId"].ToString()) : 1;  //nho fix sau khi lam xong login

                    cb.CategoryName    = txtCategoryName.Text;
                    cb.CategoryNameEng = txtCategoryNameEng.Text;
                    if (ddlCategory.SelectedIndex == 0)
                    {
                        cb.CategoryParent = 0;
                    }
                    else
                    {
                        cb.CategoryParent = int.Parse(ddlCategory.SelectedValue);
                    }
                    //Tin
                    cb.Title         = txtTitle.Text;
                    cb.TitleEng      = txtTitleEng.Text;
                    cb.Summary       = txtSubTitle.Text;
                    cb.SummaryEng    = txtSubTitleEng.Text;
                    cb.Content       = fckDetail.Text;
                    cb.ContentEng    = fckDetailEng.Text;
                    cb.IsDisplayMain = chkSelectView.Checked ? true : false;
                    cb.IsShow        = chkIshow.Checked ? true : false;
                    cb.Date          = DateTime.Now;

                    if (txtNumber.Text != "")
                    {
                        cb.CategoryOrder = Convert.ToInt32(txtNumber.Text);
                    }
                    else
                    {
                        cb.CategoryOrder = (MaxNumber() + 1);
                    }
                    //
                    if (fulImage.HasFile)
                    {
                        if (ParadiseHotelFile.IsFileImage(fulImage.FileName))
                        {
                            ParadiseHotelFile.CreateFoder(Setup.host + ParadiseHotelPath.Cate_Image_Upload);
                            if (ParadiseHotelFile.StrFoder != "")
                            {
                                ParadiseHotelFile.CreateFile(ParadiseHotelFile.StrFoder,
                                                             ParadiseHotelFile.StyleFile.HOUR_MINUTE_SECOND.ToString(),
                                                             fulImage.FileName);

                                if (ParadiseHotelFile.StrFile != "")
                                {
                                    fulImage.PostedFile.SaveAs(ParadiseHotelFile.StrFile);

                                    cb.ImageUrl = ParadiseHotelFile.StrFile.Replace(Setup.host, "");
                                }
                                else
                                {
                                    cb.ImageUrl = ParadiseHotelPath.Category_Image_Default;
                                }
                            }
                            else
                            {
                                cb.ImageUrl = ParadiseHotelPath.Category_Image_Default;
                            }
                        }
                        else
                        {
                            cb.ImageUrl = ParadiseHotelPath.Category_Image_Default;
                        }
                    }
                    else
                    {
                        cb.ImageUrl = ParadiseHotelPath.Category_Image_Default;
                    }


                    db.Categories.InsertOnSubmit(cb);
                    db.SubmitChanges();

                    FillData();
                    Clear();
                    messSuccess.Visible       = true;
                    messSuccessText.InnerText = "Thêm chuyên mục \"" + cb.CategoryName + "\" thành công";
                }
            }
            catch (Exception)
            {
            }
        }