예제 #1
0
    protected void UpdateSettings_Click(object sender, EventArgs e)
    {
        anm_Utility dt    = new anm_Utility();
        Boolean     error = false;

        if ((txtSmtp.Text == dt.GetSetting("smtpserver")) && (txtUserMail.Text == dt.GetSetting("MailUser")) && (txtPswMail.Text == dt.GetSetting("MailPassword")) && (txtPort.Text == dt.GetSetting("port")))
        {
        }
        else
        {
            try
            {
                System.Configuration.Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
                System.Net.Configuration.MailSettingsSectionGroup mailSection = config.GetSectionGroup("system.net/mailSettings") as System.Net.Configuration.MailSettingsSectionGroup;
                mailSection.Smtp.From             = txtemail.Text;
                mailSection.Smtp.Network.Host     = txtSmtp.Text;
                mailSection.Smtp.Network.UserName = txtUserMail.Text;
                mailSection.Smtp.Network.Password = txtPswMail.Text;
                int  mailPort = 25;
                bool isNum    = int.TryParse(txtPort.Text, out mailPort);
                if (isNum)
                {
                    mailSection.Smtp.Network.Port = mailPort;
                }
                else
                {
                    mailSection.Smtp.Network.Port = 25;
                }
                config.Save(ConfigurationSaveMode.Modified);
            }
            catch
            {
                Label11.Text    = GetGlobalResourceObject("language", "nopermupdwebconf").ToString();
                Label11.Visible = true;
                error           = true;
            }
        }
        int archivetype = 0;

        if (chkType1.Checked)
        {
            archivetype = 1;
        }
        if (chkType2.Checked)
        {
            archivetype = 2;
        }

        string        strConn      = ConfigurationManager.ConnectionStrings["anmcs"].ToString();
        SqlConnection myConnection = new SqlConnection(strConn);
        SqlCommand    command      = new SqlCommand();

        command.Connection = myConnection;
        command.Parameters.Add("@SiteName", SqlDbType.NVarChar).Value = txtsn.Text.ToString();
        Cache.Insert("SiteName", txtsn.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@SiteEmail", SqlDbType.NVarChar).Value = txtemail.Text.ToString();
        Cache.Insert("SiteEmail", txtemail.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@SiteUrl", SqlDbType.NVarChar).Value = txturl.Text.ToString();
        Cache.Insert("SiteUrl", txturl.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@Search", SqlDbType.Bit).Value = CheckBox4.Checked;
        Cache.Insert("SearchMenu", CheckBox4.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@Validator", SqlDbType.Bit).Value = CheckBox3.Checked;
        Cache.Insert("Validator", CheckBox3.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@Archive", SqlDbType.Bit).Value = CheckBox5.Checked;
        Cache.Insert("ArchiveMenu", CheckBox5.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@LastNews", SqlDbType.Bit).Value = CheckBox6.Checked;
        Cache.Insert("LastNews", CheckBox6.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@LastComments", SqlDbType.Bit).Value = CheckBox7.Checked;
        Cache.Insert("LastComments", CheckBox7.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@CaptchaNewUser", SqlDbType.Bit).Value = CheckBox8.Checked;
        Cache.Insert("CaptchaNewUser", CheckBox8.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@CaptchaComments", SqlDbType.Bit).Value = CheckBox10.Checked;
        Cache.Insert("CaptchaComments", CheckBox10.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@EmailConfirm", SqlDbType.Bit).Value = CheckBox9.Checked;
        Cache.Insert("EmailConfirm", CheckBox9.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@smtpserver", SqlDbType.NVarChar).Value = txtSmtp.Text.ToString();
        Cache.Insert("smtpserver", txtSmtp.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@MailUser", SqlDbType.NVarChar).Value = txtUserMail.Text.ToString();
        Cache.Insert("MailUser", txtUserMail.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@MailPassword", SqlDbType.NVarChar).Value = txtPswMail.Text.ToString();
        Cache.Insert("MailPassword", txtPswMail.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@port", SqlDbType.NVarChar).Value = txtPort.Text.ToString();
        Cache.Insert("port", txtPort.Text.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@ViewNarticles", SqlDbType.Bit).Value = CheckBox1.Checked;
        Cache.Insert("ViewNarticles", CheckBox1.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@ArchiveType", SqlDbType.Int).Value = archivetype;
        Cache.Insert("ArchiveType", archivetype, null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@TagBox", SqlDbType.Bit).Value = CheckBox11.Checked;
        Cache.Insert("TagBox", CheckBox11.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@CaptchaType", SqlDbType.NVarChar).Value = DDcaptcha.SelectedValue;
        Cache.Insert("CaptchaType", DDcaptcha.SelectedValue.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        command.Parameters.Add("@OnlineUsers", SqlDbType.Bit).Value = CheckBox12.Checked;
        Cache.Insert("OnlineUsers", CheckBox12.Checked.ToString(), null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);
        string banner = "";

        if (CheckBox2.Checked & FileUpload1.FileName.ToString() == "" & txtBanner.Text.ToString() != "")
        {
            banner = txtBanner.Text.ToString();
        }
        else if (CheckBox2.Checked & FileUpload1.FileName.ToString() != "")
        {
            anm_Utility ut           = new anm_Utility();
            string      filename     = FileUpload1.FileName;
            string      tempfileName = "";
            string      savePath     = Server.MapPath("~\\images\\");
            string      pathToCheck  = savePath + filename;
            if (System.IO.File.Exists(pathToCheck))
            {
                int counter = 2;
                while (System.IO.File.Exists(pathToCheck))
                {
                    tempfileName = counter.ToString() + filename;
                    pathToCheck  = savePath + tempfileName;
                    counter++;
                }
                filename = tempfileName;
            }
            FileUpload1.SaveAs(Server.MapPath("~\\images\\full_") + filename);
            int newWidth  = 0;
            int newHeight = 0;
            if (txtW.Text != "")
            {
                newWidth = Convert.ToInt32(txtW.Text);
            }
            if (txtH.Text != "")
            {
                newHeight = Convert.ToInt32(txtH.Text);
            }
            ut.GenerateImage(Server.MapPath("~\\images\\full_") + filename, Server.MapPath("~\\images\\") + filename, newWidth, newHeight, "", "", "jpeg", "Black", "Arial", 13, "br");

            banner = filename;
        }
        command.Parameters.Add("@Banner", SqlDbType.NVarChar).Value = banner;
        Cache.Insert("Banner", banner, null, DateTime.Now.AddMonths(6), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.High, null);

        command.CommandText = "UPDATE anm_Settings SET SiteName=@SiteName,SiteEmail=@SiteEmail,SiteUrl=@SiteUrl,SearchMenu=@Search,Validator=@Validator,ArchiveMenu=@Archive,LastNews=@LastNews,LastComments=@LastComments,CaptchaNewUser=@CaptchaNewUser,CaptchaComments=@CaptchaComments,EmailConfirm=@EmailConfirm,smtpserver=@smtpserver,MailUser=@MailUser,MailPassword=@MailPassword,port=@port,Banner=@Banner,ViewNarticles=@ViewNarticles,ArchiveType=@ArchiveType,TagBox=@TagBox,CaptchaType=@CaptchaType,OnlineUsers=@OnlineUsers WHERE id=1";
        myConnection.Open();
        object accountNumber = command.ExecuteScalar();

        myConnection.Close();

        if (!error)
        {
            Response.Redirect("homepage.aspx");
        }
    }
예제 #2
0
 protected void NewArticle(object sender, EventArgs e)
 {
     if (txtNews.Text.ToString() == "")
     {
         Label1.Text    = Label2.Text = GetGlobalResourceObject("language", "InsertArticle").ToString();
         Label1.Visible = Label2.Visible = true;
     }
     else if (ddlcategory.Text == "Select a category:")
     {
         lblCategoryerr.Visible = true;
         Label1.Visible         = false;
     }
     else
     {
         anm_Utility    ut          = new anm_Utility();
         MembershipUser currentUser = Membership.GetUser();
         Boolean        approve;
         try { approve = Convert.ToBoolean(ut.GetSetting("ApproveArticles")); }
         catch { approve = true; }
         string filename = FileUpload1.FileName;
         if (DDimages.Text != "Choose the image from the server:")
         {
             filename = DDimages.Text;
         }
         else if (filename != "")
         {
             string tempfileName = "";
             string savePath     = Server.MapPath("~\\images\\");
             string pathToCheck  = savePath + filename;
             if (System.IO.File.Exists(pathToCheck))
             {
                 int counter = 2;
                 while (System.IO.File.Exists(pathToCheck))
                 {
                     tempfileName = counter.ToString() + filename;
                     pathToCheck  = savePath + tempfileName;
                     counter++;
                 }
                 filename = tempfileName;
             }
             FileUpload1.SaveAs(Server.MapPath("~\\images\\app_") + filename);
             string copyright = "";
             try
             {
                 if (Convert.ToBoolean(ut.GetSetting("Copyright")))
                 {
                     copyright = ut.GetSetting("SiteName");
                 }
             }
             catch
             {
                 copyright = "";
             }
             int width = 0;
             try
             {
                 width = Convert.ToInt32(ut.GetSetting("ArtImageWidth"));
             }
             catch
             {
                 width = 200;
             }
             ut.GenerateImage(Server.MapPath("~\\images\\app_") + filename, Server.MapPath("~\\images\\full_") + filename, 0, 0, copyright, "", "jpeg", "White", "Arial", 0, "bl");
             ut.GenerateImage(Server.MapPath("~\\images\\full_") + filename, Server.MapPath("~\\images\\") + filename, width, 0, "", "", "jpeg", "White", "Arial", 0, "bl");
             File.Delete(Server.MapPath("~\\images\\app_") + filename);
         }
         string title = txtTitle.Text;
         title = title.Replace("&", "&");
         string tags = txtTags.Text;
         tags = tags.Replace("&", "&");
         tags = tags.Replace(", ", ",");
         while (tags.Contains(".,"))
         {
             tags = tags.Replace(".,", ",");
         }
         tags = tags.TrimEnd(',');
         tags = tags.TrimEnd('.');
         ut.AddArticle(title.ToString(), currentUser.UserName.ToString(), filename, txtSummary.Text.ToString().Replace("&", "&"), txtNews.Text.ToString().Replace("&", "&"), ddlcategory.SelectedValue.ToString(), chkComments.Checked, !approve, chkHL.Checked, chkSN.Checked, chkPB.Checked, tags, chkSS.Checked);
         if (approve)
         {
             Response.Redirect(Page.Request.Url.AbsolutePath.ToString() + "?p=ApproveArticles");
         }
         else
         {
             Response.Redirect("homepage.aspx");
         }
     }
 }