Beispiel #1
0
        private int AddData()
        {
            string culturecode = ddlCultureList.SelectedValue;
            int    vendorid    = Convert.ToInt32(VendorId);
            int    height      = Convert.ToInt32(txtHeight.Text);
            int    width       = Convert.ToInt32(txtWidth.Text);
            string title       = txtTitle.Text;
            string url         = txtUrl.Text;
            int    position    = Convert.ToInt32(ddlPosition.SelectedValue);
            string description = txtDescription.Text;
            string tags        = txtTags.Text;

            /*** UPLOAD ****************************************************************************************************************************************/
            string         thumb_image = "", main_image = "";
            HttpPostedFile myfile = FileInput.PostedFile;

            if (myfile.FileName != string.Empty)
            {
                string front_img_path = Server.MapPath(thumb_banner_dir_path);
                string main_img_path  = Server.MapPath(main_banner_dir_path);

                if (!Directory.Exists(banner_dir_path))
                {
                    Directory.CreateDirectory(banner_dir_path);
                }

                if (!Directory.Exists(front_img_path))
                {
                    Directory.CreateDirectory(front_img_path);
                }

                if (!Directory.Exists(main_img_path))
                {
                    Directory.CreateDirectory(main_img_path);
                }

                FileHandleClass file_handle_obj = new FileHandleClass();
                string[]        FileImg         = new String[2];
                FileImg     = file_handle_obj.uploadFrontMainInputFile(myfile, front_img_path, main_img_path, 120, 120);
                main_image  = FileImg[0].ToString();
                thumb_image = FileImg[1].ToString();
            }
            /*************************************************************************************************************************************************/

            #region xu ly thoi gian  ====================================================================================
            System.Globalization.DateTimeFormatInfo MyDateTimeFormatInfo = new System.Globalization.DateTimeFormatInfo();
            MyDateTimeFormatInfo.ShortDatePattern = "dd/MM/yyyy";

            string start_date = null, end_date = null;
            if (txtStartDate.Text != string.Empty)
            {
                DateTime _start_date = DateTime.Parse(txtStartDate.Text, MyDateTimeFormatInfo);
                start_date = _start_date.ToString("yyyy-MM-dd");
            }
            if (txtEndDate.Text != string.Empty)
            {
                DateTime _end_date = DateTime.Parse(txtEndDate.Text, MyDateTimeFormatInfo);
                end_date = _end_date.ToString("yyyy-MM-dd");
            }
            if (txtStartDate.Text != string.Empty && txtEndDate.Text != string.Empty)
            {
                DateTime _start_date = DateTime.Parse(txtStartDate.Text, MyDateTimeFormatInfo);
                DateTime _end_date   = DateTime.Parse(txtEndDate.Text, MyDateTimeFormatInfo);

                if (DateTime.Compare(_start_date, _end_date) > 0)
                {
                    string scriptCode = "<script>alert('Thời điểm bắt đầu phải nhỏ hơn thời điểm kết thúc');</script>";
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptName", scriptCode);
                }
            }
            #endregion ================================================================================================

            bool   bStatus = ChkBoxStatus.Checked;
            string status  = string.Empty;
            if (bStatus == true)
            {
                status = "1";
            }
            else
            {
                status = "0";
            }

            BannerController banner_obj = new BannerController();
            int i = banner_obj.Insert(vendorid, culturecode, title, main_image, thumb_image, url, position, description, tags, width, height, start_date, end_date, status);
            return(i);
        }
        private int AddData()
        {
            string culturecode = ddlCultureList.SelectedValue;
            int vendorid = Convert.ToInt32(VendorId);
            int height = Convert.ToInt32(txtHeight.Text);
            int width = Convert.ToInt32(txtWidth.Text);
            string title = txtTitle.Text;
            string url = txtUrl.Text;
            int position =Convert.ToInt32(ddlPosition.SelectedValue);
            string description = txtDescription.Text;
            string tags = txtTags.Text;
           
            /*** UPLOAD ****************************************************************************************************************************************/
            string thumb_image = "", main_image = "";
            HttpPostedFile myfile = FileInput.PostedFile;
            if (myfile.FileName != string.Empty)
            {
                string front_img_path = Server.MapPath(thumb_banner_dir_path);
                string main_img_path = Server.MapPath(main_banner_dir_path);

                if (!Directory.Exists(banner_dir_path))
                    Directory.CreateDirectory(banner_dir_path);

                if (!Directory.Exists(front_img_path))
                    Directory.CreateDirectory(front_img_path);

                if (!Directory.Exists(main_img_path))
                    Directory.CreateDirectory(main_img_path);

                FileHandleClass file_handle_obj = new FileHandleClass();
                string[] FileImg = new String[2];
                FileImg = file_handle_obj.uploadFrontMainInputFile(myfile, front_img_path, main_img_path, 120, 120);
                main_image = FileImg[0].ToString();
                thumb_image = FileImg[1].ToString();
            }
            /*************************************************************************************************************************************************/

            #region xu ly thoi gian  ====================================================================================
            System.Globalization.DateTimeFormatInfo MyDateTimeFormatInfo = new System.Globalization.DateTimeFormatInfo();
            MyDateTimeFormatInfo.ShortDatePattern = "dd/MM/yyyy";

            string start_date = null, end_date = null;
            if (txtStartDate.Text != string.Empty)
            {
                DateTime _start_date = DateTime.Parse(txtStartDate.Text, MyDateTimeFormatInfo);
                start_date = _start_date.ToString("yyyy-MM-dd");
            }
            if (txtEndDate.Text != string.Empty)
            {
                DateTime _end_date = DateTime.Parse(txtEndDate.Text, MyDateTimeFormatInfo);
                end_date = _end_date.ToString("yyyy-MM-dd");
            }
            if (txtStartDate.Text != string.Empty && txtEndDate.Text != string.Empty)
            {
                DateTime _start_date = DateTime.Parse(txtStartDate.Text, MyDateTimeFormatInfo);
                DateTime _end_date = DateTime.Parse(txtEndDate.Text, MyDateTimeFormatInfo);

                if (DateTime.Compare(_start_date, _end_date) > 0)
                {
                    string scriptCode = "<script>alert('Thời điểm bắt đầu phải nhỏ hơn thời điểm kết thúc');</script>";
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptName", scriptCode);
                }
            }
            #endregion ================================================================================================

            bool bStatus = ChkBoxStatus.Checked;
            string status = string.Empty;
            if (bStatus == true)           
                status = "1";           
            else           
                status = "0";
            
            BannerController banner_obj = new BannerController();
            int i = banner_obj.Insert(vendorid, culturecode, title, main_image, thumb_image, url, position, description, tags, width, height, start_date, end_date, status);
            return i;            
        }