Esempio n. 1
0
    protected void SaveImageFile(object sender, EventArgs e)
    {
        ImageFileNameRegExpValidator.Validate();
        if (ImageFileNameRegExpValidator.IsValid)
        {
            if (ImageFileName.FileBytes.Length > 500 * 1024)
            {
                ErrorLiteral.Text    = "File size must be lesser than 500kb";
                ErrorLiteral.Visible = true;
            }
            else
            {
                Boolean   fileOK  = false;
                bool      success = true;
                LoginInfo regInfo = (LoginInfo)Session["loginInfo"];
                string    userId  = regInfo.UserId.ToString();
                string    path    = Server.MapPath("~/Members/UserData/" + userId + "/Images/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (ImageFileName.HasFile)
                {
                    String fileExtension =
                        System.IO.Path.GetExtension(ImageFileName.FileName).ToLower();
                    String[] allowedExtensions =
                    { ".gif", ".png", ".jpeg", ".jpg" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            fileOK = true;
                        }
                    }
                }

                if (fileOK)
                {
                    try
                    {
                        ImageFileName.PostedFile.SaveAs(path + ImageFileName.FileName);
                        userId = regInfo.UserId.ToString();
                        path   = Server.MapPath("~/Members/UserData/" + userId + "/Images/");
                        DirectoryInfo dirInfo = new DirectoryInfo(path);
                        FileInfo[]    files   = dirInfo.GetFiles();
                        ExistingImagesGridview.DataSource = files;
                        ExistingImagesGridview.DataBind();

                        string script = "<script language=JavaScript id='PopupWindow'>";
                        script += "imageDiv = document.getElementById(\"ExistingImagesDiv\");";
                        script += "imageDiv.style.display='block';";
                        script += "imageDiv = document.getElementById(\"FileUploadDiv\");";
                        script += "imageDiv.style.display='block';";
                        script += "s('IMAGE_FORM'+'" + HTMLEditTextBox.ClientID + "');";
                        script += "</script>";
                        ClientScript.RegisterStartupScript(this.GetType(), "ShowImageDiv", script);
                        ErrorLiteral.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Unknown error", ex);
                        ErrorLiteral.Text    = "File could not be uploaded.";
                        ErrorLiteral.Visible = true;
                        success = false;
                    }
                }
                else
                {
                    ErrorLiteral.Text    = "Cannot accept files of this type.";
                    ErrorLiteral.Visible = true;
                    success = false;
                }
            }
        }
    }
Esempio n. 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if ((IsFromModifyPage && Request.QueryString["MessageId"] == null && Session["SelectedMessage"] == null))
            {
                RedirectPage();
            }
            FillStatusDropDown();
            LoginInfo regInfo = (LoginInfo)Session["loginInfo"];
            int       userId  = regInfo.UserId;
            string    path    = Server.MapPath("~/Members/UserData/" + userId.ToString() + "/Images/");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            DirectoryInfo dirInfo = new DirectoryInfo(path);
            FileInfo[]    files   = dirInfo.GetFiles();
            ExistingImagesGridview.DataSource = files;
            ExistingImagesGridview.DataBind();
            if (IsFromModifyPage)
            {
                TitleLabel.Text    = "Modify Standard Message";
                SubTitleLabel.Text = "Please modify standard message details in the below form";
                MessageInfo dataSource = (MessageInfo)Session["SelectedMessage"];
                if (Session["SelectedMessage"] == null)
                {
                    MessageService msgService = ServiceAccess.GetInstance().GetMessage();
                    userId = regInfo.UserId;
                    DesignService designService = ServiceAccess.GetInstance().GetDesign();
                    DesignInfo[]  designs       = designService.GetList(regInfo.UserId);
                    string        gender        = string.Empty;
                    string        onDesignName  = string.Empty;

                    foreach (DesignInfo designInfo in designs)
                    {
                        DesignInfo allDesignInfo = designService.Get(designInfo.DesignId);
                        if (allDesignInfo.Gender != string.Empty && allDesignInfo.OnDesignName != string.Empty)
                        {
                            gender       = allDesignInfo.Gender;
                            onDesignName = allDesignInfo.OnDesignName;
                            break;
                        }
                    }

                    MessageInfo[] messageInfo = msgService.GetStandardMessageList(false, gender, onDesignName);
                    foreach (MessageInfo msgInfo in messageInfo)
                    {
                        if (msgInfo.MessageId == Convert.ToInt32(Request.QueryString["MessageId"]))
                        {
                            dataSource = msgInfo;
                            break;
                        }
                    }
                }
                MessageIdPanel.Visible = true;
                MessageIdLabel.Text    = dataSource.MessageId.ToString();
                foreach (ListItem listItem in StatusDropDownList.Items)
                {
                    if (listItem.Text == dataSource.Status.ToString())
                    {
                        listItem.Selected = true;
                        break;
                    }
                }
                ShortDescText.Text             = dataSource.ShortDesc;
                HTMLEditTextBox.Text           = dataSource.MessageText;
                DefaultMessageCheckBox.Checked = dataSource.IsDefaultMessage;
                if (dataSource.UsageCount > 0)
                {
                    StatusDropDownList.Enabled = false;
                }
                if (dataSource.IsDefaultMessage)
                {
                    DefaultMessageCheckBox.Enabled = false;
                }
            }
        }
    }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!IsAgentRole && Request.QueryString["userId"] == null ||
                (IsFromModifyPage && Request.QueryString["MessageId"] == null && Session["SelectedMessage"] == null))
            {
                RedirectPage(string.Empty);
            }

            FillStatusDropDown();
            FillStandardMessages();
            MessageTextRFValidator.Enabled = true;
            LoginInfo regInfo = (LoginInfo)Session["loginInfo"];
            int       userId  = 0;
            if (!IsAgentRole)
            {
                userId = Convert.ToInt32(Request.QueryString["userId"]);
            }
            else
            {
                userId = regInfo.UserId;
            }
            string path = Server.MapPath("~/Members/UserData/" + userId.ToString() + "/Images");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            DirectoryInfo dirInfo = new DirectoryInfo(path);
            FileInfo[]    files   = dirInfo.GetFiles();
            ExistingImagesGridview.DataSource = files;
            ExistingImagesGridview.DataBind();

            if (IsFromModifyPage)
            {
                TitleLabel.Text    = "Modify Custom Message";
                SubTitleLabel.Text = "Please modify custom message details in the below form";
                MessageInfo dataSource = (MessageInfo)Session["SelectedMessage"];
                if (Session["SelectedMessage"] == null)
                {
                    MessageService      msgService  = ServiceAccess.GetInstance().GetMessage();
                    IList <MessageInfo> messageInfo = msgService.GetCustomMessageList(userId);
                    foreach (MessageInfo msgInfo in messageInfo)
                    {
                        if (msgInfo.MessageId == Convert.ToInt32(Request.QueryString["MessageId"]))
                        {
                            dataSource = msgInfo;
                            break;
                        }
                    }
                }
                MessageIdPanel.Visible = true;
                MessageIdLabel.Text    = dataSource.MessageId.ToString();
                foreach (ListItem listItem in StatusDropDownList.Items)
                {
                    if (listItem.Text == dataSource.Status.ToString())
                    {
                        listItem.Selected = true;
                        break;
                    }
                }
                ShortDescTextBox.Text = dataSource.ShortDesc;
                HTMLEditTextBox.Text  = dataSource.MessageText;
                if (dataSource.UsageCount > 0)
                {
                    StatusDropDownList.Enabled = false;
                }
            }
            if (!IsAgentRole)
            {
                RegistrationService regservice  = ServiceAccess.GetInstance().GetRegistration();
                RegistrationInfo    registrInfo = regservice.GetDetails(Convert.ToInt32(Request.QueryString["userId"]));
                AgentLabel.Text    = "Selected Agent: " + registrInfo.UserName;
                AgentLabel.Visible = true;
            }
        }
        else
        {
            if (MessageTextHidden.Value != null && MessageTextHidden.Value != string.Empty)
            {
                FileInfo   fileInfo = new FileInfo(MessageTextHidden.Value);
                FileStream fs       = fileInfo.OpenRead();
                string     userId;
                if (!IsAgentRole)
                {
                    userId = Request.QueryString["userId"];
                }
                else
                {
                    LoginInfo regInfo = (LoginInfo)Session["loginInfo"];
                    userId = regInfo.UserId.ToString();
                }
                string path = Server.MapPath("~/Members/UserData/" + userId + "/Images");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                FileStream writeStream = File.Open(path + "/" + fileInfo.Name, FileMode.Create, FileAccess.Write);

                int length = 100;
                while (length < fs.Length)
                {
                    byte[] readBytes   = new byte[100];
                    int    noBytesRead = fs.Read(readBytes, 0, 100);
                    for (int i = 0; i < readBytes.Length; i++)
                    {
                        writeStream.WriteByte(readBytes[i]);
                    }
                    length += noBytesRead;
                }
                writeStream.Flush();
                writeStream.Close();
                fs.Close();
            }
        }
    }