⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.cs

📁 简单项目管理系统源码 该源码为某公司的项目管理系统Demo版
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;
using System.Drawing;
using System.Web.Security;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.Common;
namespace projmanager
{
    public class Utilities
    {

        public static void SendMail(string from, string to, string subject, string body)
        {

            SmtpClient mailClient = new SmtpClient(/*BalloonShopConfiguration.MailServer*/"");

            MailMessage mailMessage = new MailMessage(from, to, subject, body);
            /*
               // For SMTP servers that require authentication
               message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
               message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "SmtpHostUserName");
               message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "SmtpHostPassword");
              */
            // Send mail
            mailClient.Send(mailMessage);
        }

        // Send error log mail

        /*
        public static void LogError(Exception ex)
        {
            // get the current date and time
            string dateTime = DateTime.Now.ToLongDateString() + ", at "
                            + DateTime.Now.ToShortTimeString();
            // stores the error message
            string errorMessage = "Exception generated on " + dateTime;
            // obtain the page that generated the error
            System.Web.HttpContext context = System.Web.HttpContext.Current;
            errorMessage += "\n\n Page location: " + context.Request.RawUrl;
            // build the error message
            errorMessage += "\n\n Message: " + ex.Message;
            errorMessage += "\n\n Source: " + ex.Source;
            errorMessage += "\n\n Method: " + ex.TargetSite;
            errorMessage += "\n\n Stack Trace: \n\n" + ex.StackTrace;
            // send error email in case the option is activated in Web.Config
            if (BalloonShopConfiguration.EnableErrorLogEmail)
            {
                string from = "noreply@cristiandarie.ro";
                string to = BalloonShopConfiguration.ErrorLogEmail;
                string subject = BalloonShopConfiguration.SiteName + " error report";
                string body = errorMessage;
                SendMail(from, to, subject, body);
            }
        }
         */


        public static int getWeeksByDate(DateTime dt)
        {
            int days = dt.DayOfYear;
            int weeks = 0;
            if (days % 7 == 0)
            {
                weeks = days / 7;
            }
            else
            {
                weeks = days / 7 + 1;
            }
            return weeks;
        }
    

        public static void TieButton(Page page, Control TextBoxToTie, Control ButtonToTie)
        {
            // Init jscript
            string jsString = "";

            // Check button type and get required jscript
            if (ButtonToTie is LinkButton)
            {
                jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"
                    + page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":", "$") + ";return false;} else return true;";
            }
            else if (ButtonToTie is ImageButton)
            {
                jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"
                    + page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":", "$") + ";return false;} else return true;";
            }
            else
            {
                jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {document."
                    + "forms[0].elements['" + ButtonToTie.UniqueID.Replace(":", "_") + "'].click();return false;} else return true; ";
            }

            // Attach jscript to the onkeydown attribute - we have to cater for HtmlControl or WebControl
            if (TextBoxToTie is HtmlControl)
            {
                ((HtmlControl)TextBoxToTie).Attributes.Add("onkeydown", jsString);
            }
            else if (TextBoxToTie is WebControl)
            {
                ((WebControl)TextBoxToTie).Attributes.Add("onkeydown", jsString);
            }
        }


        public static void BindingDataGridView(GridView dg, DataTable dt, string[] DataKeyNames)
        {
            dg.DataSource = dt;
            dg.DataKeyNames = DataKeyNames;
            dg.DataBind();
        }

        public static void BindingDropDownList(DropDownList ddl, DataTable dt, string strTextField, string strValueField)
        {
            ddl.DataSource = dt;
            ddl.DataTextField = strTextField;
            if (strValueField != "" || strValueField != null)
                ddl.DataValueField = strValueField;
            ddl.DataBind();
        }

        public static void BindingListBox(ListBox lb, DataTable dt, string strDisplayMember, string strValueMember)
        {
            lb.DataSource = dt;
            lb.DataTextField = strDisplayMember;
            if (strValueMember != "" || strValueMember != null)
                lb.DataValueField = strValueMember;
            lb.DataBind();
        }


        public static string GetValueInDDLByText(DropDownList ddl, string strSelectDisplayMember)
        {
            string str = String.Empty;
            foreach (ListItem li in ddl.Items)
            {
                if (li.Text == strSelectDisplayMember)
                {
                    str = li.Value;
                }
            }
            return str;
        }

        public static ArrayList GetFontsName()
        {
            ArrayList al = new ArrayList();
            foreach (FontFamily oneFontFamily in FontFamily.Families)
            {
                al.Add(oneFontFamily.Name);
            }
            return al;
        }

        public static void BindingDataList(DataList dl, DataTable dt, string datakeyfield)
        {
            dl.DataSource = dt;
            dl.DataKeyField = datakeyfield;
            dl.DataBind();
        }
        public static void BindingDropDownList(DropDownList ddl, ArrayList al)
        {
            ddl.DataSource = al;
            ddl.DataValueField = ddl.DataTextField;
            ddl.DataMember = ddl.DataValueField;
            ddl.DataBind();
        }

        public static void SetSelectDropDownListByDisplayMember(DropDownList ddl, string strDisplayMember)
        {
            int i = 0;
            foreach (ListItem li in ddl.Items)
            {
                if (li.Text == strDisplayMember)
                {
                    ddl.SelectedIndex = i;
                    break;
                }
                i++;
            }
        }

        public static void SetSelectDropDownListByValueMember(DropDownList ddl, string strValueMember)
        {
            int i = 0;
            foreach (ListItem li in ddl.Items)
            {
                if (li.Value == strValueMember)
                {
                    ddl.SelectedIndex = i;
                    break;
                }
                i++;
            }

        }


        public static string Encrypt(string strS)
        {
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(strS, true, 10);
            return (FormsAuthentication.Encrypt(ticket).ToString());
        }

        public static string Decrypt(string strS)
        {
            return (FormsAuthentication.Decrypt(strS).Name.ToString());
        }


        public static bool CheckEmpIsProjectManager(string employeeid,string departmentid)
        {
            bool IsProjectManager = false;
            string sql = "select projectid from project p where p.departmentid=" + departmentid + " and projectmanagerid=" + employeeid;
           
            if (DataAccess.ExecuteScalar(sql) !=null)
            {
                IsProjectManager = true;
            }
            
            return IsProjectManager;
        }

        public static int GetEmpGroupIDByGroupLeaderID(string groupleaderid, string departmentid)
        {
            int glid = -1;
            string sql = "select groupid from [group] g where g.groupleaderid =" + groupleaderid;
            object ret = DataAccess.ExecuteScalar(sql);
            if (ret != null)
            {
                glid = (int)ret;
            }
            return glid;
        }

        public static bool CheckEmpIsGroupLeader(string groupleaderid, string departmentid)
        {
            if (GetEmpGroupIDByGroupLeaderID(groupleaderid, departmentid) == -1)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        public static bool IsMyWeekly(string weeklyid,string employeeid)
        {
            bool ret = false;
            string sql = "select weeklyid from weekly where employeeid=" + employeeid + " and weeklyid=" + weeklyid;
            DbDataReader ddr = DataAccess.ExecuteDataReader(sql);
            if (ddr.HasRows)
            {
                ret = true;
            }
            ddr.Close();
            return ret;
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -