protected void btnAdd_Click(object sender, EventArgs e)
    {
        MBusinessFunctionData model = new MBusinessFunctionData();
        MBusinessFunctionBB businessFunctionBB = new MBusinessFunctionBB();
        try
        {
            if (this.State == "1")
            {
                this.SetModel(ref model);
                businessFunctionBB.AddRecord(model);
            }
            else if (this.State == "2")
            {
                model = businessFunctionBB.GetModel(this.IdValue);
                this.SetModel(ref model);
                businessFunctionBB.ModifyRecord(model);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",4);", true);
            return;
        }
        finally
        {
            businessFunctionBB.Dispose();
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "CloseSubmit", "CloseSubmit()", true);
    }
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public int AddRecord(MBusinessFunctionData model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("set nocount on; ");
            strSql.Append("insert into MBusinessFunction(");
            strSql.Append("functionNo,functionNm,functionUrl,acceptEmp,isUseEmpAccept,isUseEmpLeaderAccept,useEmpField,windowheight,windowwidth,isDraw,remark)");
            strSql.Append(" values (");
            strSql.Append("@functionNo,@functionNm,@functionUrl,@acceptEmp,@isUseEmpAccept,@isUseEmpLeaderAccept,@useEmpField,@windowheight,@windowwidth,@isDraw,@remark)");
            strSql.Append("; select @@identity; set nocount off; ");
            SqlParameter[] parameters = {
                    new SqlParameter("@functionNo", SqlDbType.NVarChar,20),
                    new SqlParameter("@functionNm", SqlDbType.NVarChar,50),
                    new SqlParameter("@functionUrl", SqlDbType.NVarChar,200),
                    new SqlParameter("@acceptEmp", SqlDbType.NVarChar,20),
                    new SqlParameter("@isUseEmpAccept", SqlDbType.Bit),
                    new SqlParameter("@isUseEmpLeaderAccept", SqlDbType.Bit),
                    new SqlParameter("@useEmpField", SqlDbType.NVarChar,50),
                    new SqlParameter("@windowheight", SqlDbType.Int),
                    new SqlParameter("@windowwidth", SqlDbType.Int),
                    new SqlParameter("@isDraw", SqlDbType.Bit),
                    new SqlParameter("@remark", SqlDbType.NVarChar,200)
                };
            parameters[0].Value = model.functionNo;
            parameters[1].Value = model.functionNm;
            parameters[2].Value = model.functionUrl;
            parameters[3].Value = model.acceptEmp;
            parameters[4].Value = model.isUseEmpAccept;
            parameters[5].Value = model.isUseEmpLeaderAccept;
            parameters[6].Value = model.useEmpField;
            parameters[7].Value = model.windowheight;
            parameters[8].Value = model.windowwidth;
            parameters[9].Value = model.isDraw;
            parameters[10].Value = model.remark;

            int id = 0;
            try
            {
                object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

                if (ret != null && ret != DBNull.Value)
                {
                    id = Convert.ToInt32(ret);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return id;
        }
 private void ShowInfo(string functionNo)
 {
     MBusinessFunctionData businessFunctionData = new MBusinessFunctionData();
     MBusinessFunctionBB businessFunctionBB = new MBusinessFunctionBB();
     try
     {
         businessFunctionData = businessFunctionBB.GetModel(functionNo);
         this.acceptEmp.Text = businessFunctionData.acceptEmp;
     }
     finally
     {
         businessFunctionBB.Dispose();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
         {
             this.IdValue = Request.Params["id"];
         }
         if (Request.Params["state"] != null && Request.Params["state"].Trim() != string.Empty)
         {
             this.State = Request.Params["state"].ToString();
             switch (this.State)
             {
                 case "1":   //add
                     break;
                 case "2":   //update
                     //���ؿؼ�
                     MBusinessFunctionBB businessFunctionBB = new MBusinessFunctionBB();
                     MBusinessFunctionData businessFunctionData = new MBusinessFunctionData();
                     try
                     {
                         businessFunctionData = businessFunctionBB.GetModel(this.IdValue);
                         //����й��������˴�Ҫ��֤�Ƿ������޸�
                         this.ShowInfo(this.IdValue);
                     }
                     finally
                     {
                         businessFunctionBB.Dispose();
                     }
                     break;
                 default:
                     break;
             }
         }
     }
 }
 private void SetModel(ref MBusinessFunctionData model)
 {
     model.functionNo = this.functionNo.Text;
     model.functionNm = this.functionNm.Text;
     model.functionUrl = this.functionUrl.Text;
     model.acceptEmp = this.acceptEmp.Text;
     model.isUseEmpAccept = this.isUseEmpAccept.Checked;
     model.isUseEmpLeaderAccept = this.isUseEmpLeaderAccept.Checked;
     model.useEmpField = this.useEmpField.Text;
     if (this.windowheight.Text != "")
     {
         model.windowheight = Convert.ToInt32(this.windowheight.Text);
     }
     else
     {
         model.windowheight = 0;
     }
     if (this.windowwidth.Text != "")
     {
         model.windowwidth = Convert.ToInt32(this.windowwidth.Text);
     }
     else
     {
         model.windowwidth = 0;
     }
     model.isDraw = this.isDraw.Checked;
     model.remark = this.remark.Text;
 }
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public bool ModifyRecord(MBusinessFunctionData model)
 {
     return this.businessFunctionDB.ModifyRecord(model);
 }
 /// <summary>
 /// ����һ������
 /// </summary>
 /// <param name="model">model</param>
 public int AddRecord(MBusinessFunctionData model)
 {
     return this.businessFunctionDB.AddRecord(model);
 }
Beispiel #8
0
        /// <summary>
        /// ������Ϣ��
        /// </summary>
        /// <param name="functionNo">��Ϣ���</param>
        /// <param name="recordValue">����ֵ</param>
        /// <param name="recordTitle">����</param>
        /// <param name="useEmpId">������id</param>
        /// <param name="acceptEmpId">������id</param>
        public void Send(string functionNo, string recordValue, string recordTitle, int empId, int acceptEmpId)
        {
            //д����Ϣ���б�����
            MBusinessFunctionBB businessFunctionBB = new MBusinessFunctionBB();
            HEemployeeBB userBB = new HEemployeeBB();
            MBusinessData businessData = new MBusinessData();
            MBusinessFunctionData businessFunctionData = new MBusinessFunctionData();

            try
            {
                businessData.functionNo = functionNo;
                businessData.recordValue = recordValue;
                businessData.messageTitle = recordTitle;
                businessData.empId = empId;
                businessData.sendTime = DateTime.Now.ToString();
                businessData.isRead = false;

                //�ж���Ϣ��ִ����
                if (acceptEmpId != 0)
                {
                    businessData.acceptEmp = "p___" + acceptEmpId.ToString();
                }
                else
                {
                    businessFunctionData = businessFunctionBB.GetModel(functionNo);
                    string useEmpId = "";
                    if (businessFunctionData.isUseEmpAccept || businessFunctionData.isUseEmpLeaderAccept)
                    {
                        //ȡ��ԭʼ����������
                        string workTableNm;
                        string recordKeyField;
                        bool keyIsInt = false;
                        DataSet ds = new DataSet();

                        ds = businessFunctionBB.GetVList("functionNo='" + functionNo + "'");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            throw new Exception("�Ҳ�����Ϣ��������¼���޷�������Ϣ��");
                        }
                        DataRow row = ds.Tables[0].Rows[0];

                        workTableNm = Convert.ToString(row["tableNm"]);
                        recordKeyField = Convert.ToString(row["recordKeyField"]);
                        if (row["keyIsInt"] != DBNull.Value)
                        {
                            keyIsInt = Convert.ToBoolean(row["keyIsInt"]);
                        }

                        string strSql = "select " + businessFunctionData.useEmpField + " from " + workTableNm;
                        if (keyIsInt)
                        {
                            strSql += " where " + recordKeyField + "=" + recordValue;
                        }
                        else
                        {
                            strSql += " where " + recordKeyField + "='" + recordValue + "'";
                        }

                        ds.Reset();
                        ds = this.commBB.Query(strSql);
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            throw new Exception("��Ϣ���������ò���ȷ���޷�������Ϣ��");
                        }
                        row = ds.Tables[0].Rows[0];
                        useEmpId = Convert.ToString(row[0]);
                    }

                    if (businessFunctionData.isUseEmpAccept)
                    {
                        businessData.acceptEmp = "p___" + useEmpId;
                    }
                    else if (businessFunctionData.isUseEmpLeaderAccept)
                    {
                        //ȡ��ԭʼ���������˵IJ��Ÿ�����
                        DataSet ds = new DataSet();
                        ds = userBB.GetList("empId=" + useEmpId);
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            throw new Exception("��Ա�����쵼û�����ã��޷�������Ϣ��");
                        }
                        DataRow row = ds.Tables[0].Rows[0];

                        //����н�ɫ���壬���ɾ��иý�ɫ�IJ��Ÿ����˽���
                        if (businessFunctionData.acceptEmp != "")
                        {
                            businessData.acceptEmp = businessFunctionData.acceptEmp.Replace("R_", "R_" + row["nowDepartId"].ToString());
                        }
                        else
                        {
                            businessData.acceptEmp = "p___" + row["departLeader"].ToString();
                        }
                    }
                    else
                    {
                        businessData.acceptEmp = businessFunctionData.acceptEmp;
                    }
                }

                this.businessBB.AddRecord(businessData);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                businessFunctionBB.Dispose();
                userBB.Dispose();
            }
        }
        /// <summary>
        /// ����һ������
        /// </summary>
        /// <param name="model">model</param>
        public bool ModifyRecord(MBusinessFunctionData model)
        {
            bool ret = false;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update MBusinessFunction set ");
            strSql.Append("functionNm=@functionNm,");
            strSql.Append("functionUrl=@functionUrl,");
            strSql.Append("acceptEmp=@acceptEmp,");
            strSql.Append("isUseEmpAccept=@isUseEmpAccept,");
            strSql.Append("isUseEmpLeaderAccept=@isUseEmpLeaderAccept,");
            strSql.Append("useEmpField=@useEmpField,");
            strSql.Append("windowheight=@windowheight,");
            strSql.Append("windowwidth=@windowwidth,");
            strSql.Append("isDraw=@isDraw,");
            strSql.Append("remark=@remark");
            strSql.Append(" where functionNo = @functionNo ");
            SqlParameter[] parameters = {
                    new SqlParameter("@functionNo", SqlDbType.NVarChar,20),
                    new SqlParameter("@functionNm", SqlDbType.NVarChar,50),
                    new SqlParameter("@functionUrl", SqlDbType.NVarChar,200),
                    new SqlParameter("@acceptEmp", SqlDbType.NVarChar,20),
                    new SqlParameter("@isUseEmpAccept", SqlDbType.Bit),
                    new SqlParameter("@isUseEmpLeaderAccept", SqlDbType.Bit),
                    new SqlParameter("@useEmpField", SqlDbType.NVarChar,50),
                    new SqlParameter("@windowheight", SqlDbType.Int),
                    new SqlParameter("@windowwidth", SqlDbType.Int),
                    new SqlParameter("@isDraw", SqlDbType.Bit),
                    new SqlParameter("@remark", SqlDbType.NVarChar,200)
                };
            parameters[0].Value = model.functionNo;
            parameters[1].Value = model.functionNm;
            parameters[2].Value = model.functionUrl;
            parameters[3].Value = model.acceptEmp;
            parameters[4].Value = model.isUseEmpAccept;
            parameters[5].Value = model.isUseEmpLeaderAccept;
            parameters[6].Value = model.useEmpField;
            parameters[7].Value = model.windowheight;
            parameters[8].Value = model.windowwidth;
            parameters[9].Value = model.isDraw;
            parameters[10].Value = model.remark;

            try
            {
                SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);
                ret = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ret;
        }
        /// <summary>
        /// �õ�һ��model
        /// </summary>
        /// <param name="functionNo">����ֵ</param>
        /// <returns>model</returns>
        public MBusinessFunctionData GetModel(string functionNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from MBusinessFunction");
            strSql.Append(" where functionNo = @functionNo ");
            SqlParameter[] parameters = {
                    new SqlParameter("@functionNo", SqlDbType.NVarChar,20)
                };
            parameters[0].Value = functionNo;

            MBusinessFunctionData model = new MBusinessFunctionData();
            DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow row = ds.Tables[0].Rows[0];
                if (row["functionNo"] != DBNull.Value)
                {
                    model.functionNo = Convert.ToString(row["functionNo"]);
                }
                if (row["functionNm"] != DBNull.Value)
                {
                    model.functionNm = Convert.ToString(row["functionNm"]);
                }
                if (row["functionUrl"] != DBNull.Value)
                {
                    model.functionUrl = Convert.ToString(row["functionUrl"]);
                }
                if (row["acceptEmp"] != DBNull.Value)
                {
                    model.acceptEmp = Convert.ToString(row["acceptEmp"]);
                }
                if (row["isUseEmpAccept"] != DBNull.Value)
                {
                    model.isUseEmpAccept = Convert.ToBoolean(row["isUseEmpAccept"]);
                }
                if (row["isUseEmpLeaderAccept"] != DBNull.Value)
                {
                    model.isUseEmpLeaderAccept = Convert.ToBoolean(row["isUseEmpLeaderAccept"]);
                }
                if (row["useEmpField"] != DBNull.Value)
                {
                    model.useEmpField = Convert.ToString(row["useEmpField"]);
                }
                if (row["windowheight"] != DBNull.Value)
                {
                    model.windowheight = Convert.ToInt32(row["windowheight"]);
                }
                if (row["windowwidth"] != DBNull.Value)
                {
                    model.windowwidth = Convert.ToInt32(row["windowwidth"]);
                }
                if (row["isDraw"] != DBNull.Value)
                {
                    model.isDraw = Convert.ToBoolean(row["isDraw"]);
                }
                if (row["remark"] != DBNull.Value)
                {
                    model.remark = Convert.ToString(row["remark"]);
                }
                return model;
            }
            else
            {
                return null;
            }
        }