Beispiel #1
0
 public void WriteErrorLog(string FunctionName, string errMsg, string errStatus)
 {
     ACMS.DAO.BaseDAO dao1 = new ACMS.DAO.BaseDAO();
     dao1.ErrorLog(this.Request.Url.AbsolutePath, errMsg, FunctionName, clsAuth.WORK_ID + clsAuth.NATIVE_NAME, errStatus);
     clsMyObj.ShowMessage(errMsg.Replace ("'",""));
 }
    //更新
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (ViewState["activity_id"] == null)
        {
            return;
        }

        ACMS.DAO.BaseDAO myBaseDAO = new ACMS.DAO.BaseDAO();
        SqlCommand cmd = new SqlCommand(); ;
        using (SqlConnection myConn = myBaseDAO.MyConn())
        {
            myConn.Open();

            using (SqlTransaction trans = myConn.BeginTransaction())
            {
                try
                {

                    cmd.Connection = myConn;
                    cmd.Transaction = trans;

                    foreach (GridViewRow gvr in GridView1.Rows)
                    {

                        if (gvr.RowType == DataControlRowType.DataRow && (gvr.FindControl("CheckBox1") as CheckBox).Checked)
                        {
                            string emp_id = GridView1.DataKeys[gvr.RowIndex].Values[0].ToString();
                            string activity_type = GridView1.DataKeys[gvr.RowIndex].Values[1].ToString();

                            string status = ddlcheck_status.SelectedValue;

                            SqlParameter[] sqlParams = new SqlParameter[3];

                            sqlParams[0] = new SqlParameter("@activity_id", SqlDbType.UniqueIdentifier);
                            sqlParams[0].Value = new Guid(ViewState["activity_id"].ToString());
                            sqlParams[1] = new SqlParameter("@emp_id", SqlDbType.NVarChar, 100);
                            sqlParams[1].Value = emp_id;
                            sqlParams[2] = new SqlParameter("@check_status", SqlDbType.Int);
                            sqlParams[2].Value = status;

                            StringBuilder sb = new StringBuilder();

                            if (activity_type == "1")
                            {
                                sb.AppendLine("UPDATE ActivityRegist ");
                            }
                            else
                            {
                                sb.AppendLine("UPDATE ActivityTeamMember ");
                            }

                            sb.AppendLine("set check_status=@check_status ");
                            sb.AppendLine("WHERE activity_id=@activity_id and emp_id=@emp_id; ");

                            cmd.CommandText = sb.ToString();
                            cmd.Parameters.Clear();
                            cmd.Parameters.AddRange(sqlParams);
                            cmd.ExecuteNonQuery();

                        }

                    }

                    trans.Commit();

                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    clsMyObj.ShowMessage("更新失敗!");
                    WriteErrorLog("Update", ex.Message, "0");
                }
                finally
                {
                if (cmd !=null ) cmd.Dispose();
                }

            }

        }

        GridView1.DataBind();
    }
Beispiel #3
0
 public void WriteErrorLog(string FunctionName, string errMsg, string errStatus)
 {
     ACMS.DAO.BaseDAO dao1 = new ACMS.DAO.BaseDAO();
     dao1.ErrorLog(this.Request.Url.AbsolutePath, errMsg, FunctionName, clsAuth.WORK_ID + clsAuth.NATIVE_NAME, errStatus);
     clsMyObj.ShowMessage(errMsg.Replace("'", ""));
 }
Beispiel #4
0
    //更新
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (ViewState["activity_id"] == null)
        {
            return;
        }

        ACMS.DAO.BaseDAO myBaseDAO = new ACMS.DAO.BaseDAO();
        SqlCommand       cmd       = new SqlCommand();;

        using (SqlConnection myConn = myBaseDAO.MyConn())
        {
            myConn.Open();

            using (SqlTransaction trans = myConn.BeginTransaction())
            {
                try
                {
                    cmd.Connection  = myConn;
                    cmd.Transaction = trans;

                    foreach (GridViewRow gvr in GridView1.Rows)
                    {
                        if (gvr.RowType == DataControlRowType.DataRow && (gvr.FindControl("CheckBox1") as CheckBox).Checked)
                        {
                            string emp_id        = GridView1.DataKeys[gvr.RowIndex].Values[0].ToString();
                            string activity_type = GridView1.DataKeys[gvr.RowIndex].Values[1].ToString();

                            string status = ddlcheck_status.SelectedValue;

                            SqlParameter[] sqlParams = new SqlParameter[3];

                            sqlParams[0]       = new SqlParameter("@activity_id", SqlDbType.UniqueIdentifier);
                            sqlParams[0].Value = new Guid(ViewState["activity_id"].ToString());
                            sqlParams[1]       = new SqlParameter("@emp_id", SqlDbType.NVarChar, 100);
                            sqlParams[1].Value = emp_id;
                            sqlParams[2]       = new SqlParameter("@check_status", SqlDbType.Int);
                            sqlParams[2].Value = status;

                            StringBuilder sb = new StringBuilder();

                            if (activity_type == "1")
                            {
                                sb.AppendLine("UPDATE ActivityRegist ");
                            }
                            else
                            {
                                sb.AppendLine("UPDATE ActivityTeamMember ");
                            }

                            sb.AppendLine("set check_status=@check_status ");
                            sb.AppendLine("WHERE activity_id=@activity_id and emp_id=@emp_id; ");

                            cmd.CommandText = sb.ToString();
                            cmd.Parameters.Clear();
                            cmd.Parameters.AddRange(sqlParams);
                            cmd.ExecuteNonQuery();
                        }
                    }

                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    clsMyObj.ShowMessage("更新失敗!");
                    WriteErrorLog("Update", ex.Message, "0");
                }
                finally
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
            }
        }

        GridView1.DataBind();
    }