示例#1
0
        protected void btnSaveMedia_Click(object sender, EventArgs e)
        {
            Accomodation_ID = new Guid(Request.QueryString["Hotel_Id"]);
            var resultAcco = AccSvc.GetHotelDetails(Accomodation_ID);

            MediaAbsPath = System.Configuration.ConfigurationManager.AppSettings["MediaAbsPath"] + resultAcco[0].ProductCategorySubType + "/" + resultAcco[0].CompanyHotelID.ToString() + "/";
            MediaAbsUrl  = System.Configuration.ConfigurationManager.AppSettings["MediaAbsURL"] + resultAcco[0].ProductCategorySubType + "/" + resultAcco[0].CompanyHotelID.ToString() + "/";

            if (Page.IsValid)
            {
                if (btnSaveMedia.CommandName == "AddMedia")
                {
                    MDMSVC.DC_Accommodation_Media newObj = new MDMSVC.DC_Accommodation_Media
                    {
                        Accommodation_Media_Id = Guid.NewGuid(),
                        Category    = (ddlFileCategory.SelectedIndex == 0 ? null : ddlFileCategory.SelectedItem.Text),
                        Description = txtDescription.Text,
                        //FileFormat = (ddlFileFormat.SelectedIndex == 0 ? null : ddlFileFormat.SelectedItem.Text),
                        // MediaID = txtMediaID.Text,
                        MediaType        = (ddlMediaType.SelectedIndex == 0 ? null : ddlMediaType.SelectedItem.Text),
                        Media_Position   = Convert.ToInt32(txtMediaPosition.Text),
                        RoomCategory     = (ddlRoomCategory.SelectedIndex == 0 ? null : ddlRoomCategory.SelectedItem.Text),
                        SubCategory      = (ddlSubCategory.SelectedIndex == 0 ? null : ddlSubCategory.SelectedItem.Text),
                        Accommodation_Id = Guid.Parse(Request.QueryString["Hotel_Id"]),
                        ValidFrom        = DateTime.ParseExact(txtValidFrom.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture),
                        ValidTo          = DateTime.ParseExact(txtValidTo.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture),
                        IsActive         = true,
                        Create_Date      = DateTime.Now,
                        Create_User      = System.Web.HttpContext.Current.User.Identity.Name,
                        MediaFileMaster  = (ddlFileMaster.SelectedIndex == 0 ? null : ddlFileMaster.SelectedItem.Text)
                    };

                    if (!string.IsNullOrWhiteSpace(hdnMediaName.Value))
                    {
                        //if(!string.IsNullOrWhiteSpace(txtMediaName.Text))
                        //{
                        //    newObj.MediaName = System.IO.Path.GetFileNameWithoutExtension(txtMediaName.Text) + System.IO.Path.GetExtension(hdnMediaName.Value);
                        //    newObj.Media_Path = MediaAbsPath + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(txtMediaName.Text) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value);
                        //    newObj.Media_URL  = MediaAbsUrl + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(txtMediaName.Text) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value);
                        //}
                        //else
                        //{
                        newObj.MediaName  = hdnMediaName.Value;
                        newObj.Media_Path = MediaAbsPath + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(hdnMediaName.Value) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value);
                        newObj.Media_URL  = MediaAbsUrl + resultAcco[0].CompanyHotelID.ToString() + "_" + System.IO.Path.GetFileNameWithoutExtension(hdnMediaName.Value) + "_Ori" + System.IO.Path.GetExtension(hdnMediaName.Value);
                        newObj.FileFormat = System.IO.Path.GetExtension(hdnMediaName.Value);
                        //}
                    }
                    else
                    {
                        newObj.MediaName  = string.Empty;
                        newObj.Media_Path = string.Empty;
                        newObj.Media_URL  = string.Empty;
                        newObj.FileFormat = string.Empty;
                    }

                    string sMediaPathToCheck = MediaAbsPath + hdnMediaName.Value;
                    if (!string.IsNullOrWhiteSpace(hdnMediaName.Value))
                    {
                        if (!System.IO.Directory.Exists(MapPath(MediaAbsPath)))
                        {
                            System.IO.Directory.CreateDirectory(MapPath(MediaAbsPath));
                        }

                        if (System.IO.File.Exists(MapPath(newObj.Media_Path)))
                        {
                            System.IO.File.Delete(MapPath(newObj.Media_Path));
                        }

                        FileInfo file = new FileInfo(MapPath(sMediaPathToCheck));
                        file.MoveTo(file.Directory.FullName + "\\" + System.IO.Path.GetFileName(MapPath(newObj.Media_Path)));
                        //System.Drawing.Image _img = ThumbnailImage(System.Drawing.Image.FromFile(file.Directory.FullName + "\\" + System.IO.Path.GetFileName(MapPath(newObj.Media_Path))), 90, 60);
                        //file.MoveTo(file.Directory.FullName + "\\" + System.IO.Path.GetFileName(MapPath(newObj.Media_Path)));
                    }

                    if (AccSvc.AddAccomodation_MediaDetails(newObj))
                    {
                        //Auto insert file attributes
                        try
                        {
                            //Shell32.Shell shell = new Shell32.Shell();
                            Type t = Type.GetTypeFromProgID("Shell.Application");

                            dynamic            shell      = Activator.CreateInstance(t);
                            Shell32.Folder     objFolder  = shell.NameSpace(System.IO.Path.GetDirectoryName(MapPath(newObj.Media_Path)));
                            Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(MapPath(newObj.Media_Path)));
                            List <string>      arrHeaders = new List <string>();
                            //Get file attribute list for consideratioins
                            string        strAttributeslist = Convert.ToString(ConfigurationManager.AppSettings["MediaAttributes"]);
                            List <string> _lstAttributes    = strAttributeslist.Split(',').ToList();


                            for (int i = 0; i < short.MaxValue; i++)
                            {
                                string header = objFolder.GetDetailsOf(null, i);
                                if (String.IsNullOrEmpty(header))
                                {
                                    break;
                                }
                                arrHeaders.Add(header);
                            }

                            for (int i = 0; i < arrHeaders.Count; i++)
                            {
                                string AttrTypr = arrHeaders[i];
                                if (!_lstAttributes.Contains(AttrTypr))
                                {
                                    continue;
                                }
                                string AttrVal = objFolder.GetDetailsOf(folderItem, i);

                                if (!string.IsNullOrWhiteSpace(AttrVal))
                                {
                                    MDMSVC.DC_Accomodation_Media_Attributes newObjAttr = new MDMSVC.DC_Accomodation_Media_Attributes
                                    {
                                        Accomodation_Media_Attributes_Id = Guid.NewGuid(),
                                        Accomodation_Media_Id            = newObj.Accommodation_Media_Id,
                                        AttributeType     = AttrTypr,
                                        AttributeValue    = AttrVal,
                                        IsActive          = true,
                                        Create_Date       = DateTime.Now,
                                        IsSystemAttribute = true,
                                        Create_User       = System.Web.HttpContext.Current.User.Identity.Name
                                    };

                                    AccSvc.AddAccomodation_MediaAttributesDetails(newObjAttr);
                                }
                            }
                        }
                        catch
                        {
                        }

                        BindMedia();
                        ClearMediaControls();
                        hdnFlag.Value = "true";
                        BootstrapAlert.BootstrapAlertMessage(dvMsg, "Media has been added successfully", BootstrapAlertType.Success);
                    }
                    else
                    {
                        BootstrapAlert.BootstrapAlertMessage(dvMsg, "Error Occurred", BootstrapAlertType.Warning);
                    }
                }
                else if (btnSaveMedia.CommandName == "UpdateMedia")
                {
                    Accomodation_ID = new Guid(Request.QueryString["Hotel_Id"]);
                    Guid myRow_Id         = Guid.Parse(gvMedia.SelectedDataKey.Value.ToString());
                    int  intMediaPosition = 0;
                    if (Int32.TryParse(txtMediaPosition.Text, out intMediaPosition))
                    {
                        intMediaPosition = Convert.ToInt32(txtMediaPosition.Text);
                    }
                    MDMSVC.DC_Accommodation_Media newObj = new MDMSVC.DC_Accommodation_Media
                    {
                        Accommodation_Media_Id = myRow_Id,
                        Category        = (ddlFileCategory.SelectedIndex == 0 ? null : ddlFileCategory.SelectedItem.Text),
                        MediaFileMaster = (ddlFileMaster.SelectedIndex == 0 ? null : ddlFileMaster.SelectedItem.Text),
                        Description     = txtDescription.Text,
                        //FileFormat = (ddlFileFormat.SelectedIndex == 0 ? null : ddlFileFormat.SelectedItem.Text),
                        MediaType      = (ddlMediaType.SelectedIndex == 0 ? null : ddlMediaType.SelectedItem.Text),
                        Media_Position = intMediaPosition,
                        RoomCategory   = (ddlRoomCategory.SelectedIndex == 0 ? null : ddlRoomCategory.SelectedItem.Text),
                        SubCategory    = (ddlSubCategory.SelectedIndex == 0 ? null : ddlSubCategory.SelectedItem.Text),
                        ValidFrom      = DateTime.ParseExact(txtValidFrom.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture),
                        ValidTo        = DateTime.ParseExact(txtValidTo.Text.Trim(), "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture),
                        IsActive       = true,
                        Edit_Date      = DateTime.Now,
                        Edit_User      = System.Web.HttpContext.Current.User.Identity.Name,
                    };

                    if (AccSvc.UpdateAccomodation_MediaDetails(newObj))
                    {
                        BindMedia();
                        ClearMediaControls();
                        hdnFlag.Value = "true";
                        BootstrapAlert.BootstrapAlertMessage(dvMsg, "Media has been updated successfully", BootstrapAlertType.Success);
                    }
                    else
                    {
                        BootstrapAlert.BootstrapAlertMessage(dvMsg, "Error Occurred", BootstrapAlertType.Warning);
                    }
                }

                dvBrowseMedia.Visible = true;
                UpMediaModal.Update();
            }
            //hdnFlag.Value = "true";
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop2" + DateTime.Today.Ticks.ToString(), "javascript:closeMediaModal();", true);
            // ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop2", "javascript:closeMediaModal();", true);
        }