private void BindGrid()
    {
        Js.BLL.BaseDal bdal = new Js.BLL.BaseDal(FormID);
        DataTable dtSub = bdal.GetSubDetail("").Tables[0];

        Js.BLL.Account.UserDal dal = new Js.BLL.Account.UserDal();

        if (Session["UserType"].ToString() == "BU")
        {
            //營運用戶
            DataTable dt = dal.GetAllUsers().Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["UserName"].ToString() != Session["User"].ToString())
                {
                    DataRow dr = dtSub.NewRow();
                    dr["AnnounceID"] = this.txtAnnounceID.Text;
                    dr["ReceiverUserName"] = dt.Rows[i]["UserName"];
                    dr["ReceiverFlag"] = 0;
                    Js.BLL.BusinessUnit.CompanyDal cdal = new Js.BLL.BusinessUnit.CompanyDal();
                    Js.Model.BusinessUnit.CompanyInfo model = cdal.GetModel();

                    dr["ReceiveUnitNo"] = model.CompanyNo;
                    dr["Receiver"] = dt.Rows[i]["PersonName"];

                    dtSub.Rows.Add(dr);
                }
            }
            //各企業用戶
            DataTable dtEP = dal.GetEnterprise();
            for (int i = 0; i < dtEP.Rows.Count; i++)
            {
                Js.BLL.Account.UserDal edal = new Js.BLL.Account.UserDal(dtEP.Rows[i]["EnterpriseID"].ToString());
                DataTable dtUser = edal.GetAllUsers().Tables[0];
                for (int j = 0; j < dtUser.Rows.Count; j++)
                {
                    DataRow dr = dtSub.NewRow();
                    dr["AnnounceID"] = this.txtAnnounceID.Text;
                    dr["ReceiverUserName"] = dtUser.Rows[j]["UserName"];
                    dr["ReceiverFlag"] = 1;
                    dr["ReceiveUnitNo"] = dtEP.Rows[i]["EnterpriseID"].ToString();
                    dr["Receiver"] = dtUser.Rows[j]["PersonName"];

                    dtSub.Rows.Add(dr);
                }
            }
        }
        else
        {
            Js.BLL.Account.UserDal edal = new Js.BLL.Account.UserDal(Session["EnterpriseID"].ToString());
            DataTable dtUser = edal.GetAllUsers().Tables[0];
            for (int i = 0; i < dtUser.Rows.Count; i++)
            {
                if (dtUser.Rows[i]["UserName"].ToString() != Session["User"].ToString())
                {
                    DataRow dr = dtSub.NewRow();
                    dr["AnnounceID"] = this.txtAnnounceID.Text;
                    dr["ReceiverUserName"] = dtUser.Rows[i]["UserName"];
                    dr["ReceiverFlag"] = 1;
                    dr["ReceiveUnitNo"] = Session["EnterpriseID"].ToString();
                    dr["Receiver"] = dtUser.Rows[i]["PersonName"];

                    dtSub.Rows.Add(dr);
                }
            }
            //營運管理用戶
            Js.BLL.Enterprise.CheckDal checkdal = new Js.BLL.Enterprise.CheckDal();
            dtUser = checkdal.GetManagerUser(Session["EnterpriseID"].ToString());

            Js.BLL.BusinessUnit.CompanyDal cdal = new Js.BLL.BusinessUnit.CompanyDal();
            Js.Model.BusinessUnit.CompanyInfo model = cdal.GetModel();

            for (int i = 0; i < dtUser.Rows.Count; i++)
            {
                DataRow dr = dtSub.NewRow();
                dr["AnnounceID"] = this.txtAnnounceID.Text;
                dr["ReceiverUserName"] = dtUser.Rows[i]["UserName"];
                dr["ReceiverFlag"] = 0;
                dr["ReceiveUnitNo"] = model.CompanyNo;
                dr["Receiver"] = dtUser.Rows[i]["PersonName"];

                dtSub.Rows.Add(dr);
            }
        }
        this.GridView1.DataSource = dtSub.DefaultView;
        this.GridView1.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ID = Request.QueryString["ID"] + "";
        FormID = Request.QueryString["FormID"] + "";
        if (!IsPostBack)
        {
            ViewState["StrWhere"] = string.Format(" AnnounceID='{0}'", ID);
            if (Session["UserType"].ToString() == "BU")
            {
                this.txtAnnounceFlag.Text = Resources.Resource.AnnounceFlag1;
                Js.BLL.BusinessUnit.CompanyDal cdal = new Js.BLL.BusinessUnit.CompanyDal();
                Js.Model.BusinessUnit.CompanyInfo model = cdal.GetModel();
                this.txtAnnounceUnitNo.Text = model.CompanyNo;
                Js.BLL.Account.UserDal udal = new Js.BLL.Account.UserDal();
                Js.Model.Account.UsersInfo umodel = udal.GetModel(Session["User"].ToString());
                this.txtAnnouncer.Text = umodel.PersonName;
            }
            else
            {
                this.txtAnnounceFlag.Text = Resources.Resource.AnnounceFlag2;
                this.txtAnnounceUnitNo.Text = Session["EnterpriseID"].ToString();

                Js.BLL.Account.UserDal udal = new Js.BLL.Account.UserDal(Session["EnterpriseID"].ToString());
                Js.Model.Account.UsersInfo umodel = udal.GetModel(Session["User"].ToString());
                this.txtAnnouncer.Text = umodel.PersonName;
            }

            Js.BLL.BaseDal dal = new Js.BLL.BaseDal(FormID);
            string strWhere = " AnnounceID like '" + this.txtAnnounceUnitNo.Text + DateTime.Now.ToString("yyyyMMdd") + "%'";
            dal.GetMaxID(strWhere);

            this.txtAnnounceID.Text = dal.GetMaxID(strWhere);
            if(this.txtAnnounceID.Text.Length<=0)
                this.txtAnnounceID.Text =this.txtAnnounceUnitNo.Text + DateTime.Now.ToString("yyyyMMdd") + "0001";
            this.txtAnnouncerUserName.Text = Session["User"].ToString();
            this.txtSource.Text = Resources.Resource.AnnounceSource1;

            BindGrid();
        }
    }
Exemple #3
0
    public static void SystemMessage(string[] ToUserName, int ReceiverFlag, string[] ReceiveUnitNo, string Title, string Content)
    {
        Js.BLL.BaseDal dal = new Js.BLL.BaseDal("Sys_AnnounceMessage");

        string strAnnounceUnitNo = "";
        string strAnnounceID = "";
        string strAnnouncer = "";

        string strWhere = " AnnounceID like '" + strAnnounceUnitNo + DateTime.Now.ToString("yyyyMMdd") + "%'";
        dal.GetMaxID(strWhere);

        strAnnounceID = dal.GetMaxID(strWhere);
        if (strAnnounceID.Length <= 0)
            strAnnounceID = strAnnounceUnitNo + DateTime.Now.ToString("yyyyMMdd") + "0001";

        if (HttpContext.Current.Session["UserType"].ToString() == "BU")
        {
            Js.BLL.BusinessUnit.CompanyDal cdal = new Js.BLL.BusinessUnit.CompanyDal();
            Js.Model.BusinessUnit.CompanyInfo model = cdal.GetModel();
            strAnnounceUnitNo = model.CompanyNo;
            Js.BLL.Account.UserDal udal = new Js.BLL.Account.UserDal();
            Js.Model.Account.UsersInfo umodel = udal.GetModel(HttpContext.Current.Session["User"].ToString());
            strAnnouncer = umodel.PersonName;
        }
        else
        {
            strAnnounceUnitNo = HttpContext.Current.Session["EnterpriseID"].ToString();

            Js.BLL.Account.UserDal udal = new Js.BLL.Account.UserDal(HttpContext.Current.Session["EnterpriseID"].ToString());
            Js.Model.Account.UsersInfo umodel = udal.GetModel(HttpContext.Current.Session["User"].ToString());
            strAnnouncer = umodel.PersonName;
        }

        DataTable dt = dal.GetRecord("1=2");
        DataRow dr = dt.NewRow();
        dr["AnnounceID"] = strAnnounceID;
        dr["Announcer"] = strAnnouncer;
        if (HttpContext.Current.Session["UserType"].ToString() == "BU")
            dr["AnnounceFlag"] = 0;
        else
            dr["AnnounceFlag"] = 1;
        dr["AnnounceUnitNo"] = strAnnounceUnitNo;
        dr["AnnouncerUserName"] = HttpContext.Current.Session["User"].ToString();

        dr["Source"] = 1;
        dr["AnnounceDate"] = DateTime.Now;
        dr["Title"] = Title;
        dr["Contents"] = Content;

        dal.Add(dr);

        DataTable dtSub = dal.GetSubDetail("").Tables[0];

        for (int i = 0; i < ToUserName.Length; i++)
        {

            DataRow subdr = dtSub.NewRow();
            subdr["AnnounceID"] = strAnnounceID;
            subdr["ReceiverUserName"] = ToUserName[i];
            subdr["ReceiverFlag"] = ReceiverFlag;

            subdr["ReceiveUnitNo"] = ReceiveUnitNo[i];
            Js.BLL.Account.UserDal udal = new Js.BLL.Account.UserDal(ReceiveUnitNo[i]);
            Js.Model.Account.UsersInfo umodel = udal.GetModel(ToUserName[i]);
            subdr["Receiver"] = umodel.PersonName;

            dtSub.Rows.Add(subdr);

        }
        dal.SaveDetail(dtSub, "");
    }