0
需要檢查某些標誌在表列中是否處於活動狀態。需要檢查表中的某些標誌是否有效
如果只有標誌處於活動狀態,則應執行更新語句。 (我的標誌是HR_Active和User_Active如果只有那些標誌是「1」更新語句應該執行)如果「0」應該通過web服務的通道。
表名是:HS_HR_EMPLOYEE
下面我有提到我的代碼片段。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
namespace XXX_WebService
{
[WebService(Namespace = "http://XXXXXXX.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class EmployeeService : System.Web.Services.WebService
{
[WebMethod(Description = "Update Employee Email Address")]
public int Update(string USRACC_USER_ID, string EMP_OFFICE_EMAIL)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("UPDATE HS_HR_EMPLOYEE SET EMP_OFFICE_EMAIL = @EMP_OFFICE_EMAIL FROM HS_SM_USER_ACCOUNT WHERE HS_SM_USER_ACCOUNT.EMP_NUMBER = HS_HR_EMPLOYEE.EMP_NUMBER AND USRACC_USER_ID = @USRACC_USER_ID"))
{
cmd.Parameters.AddWithValue("@USRACC_USER_ID", USRACC_USER_ID);
cmd.Parameters.AddWithValue("@EMP_OFFICE_EMAIL", EMP_OFFICE_EMAIL);
cmd.Connection = con;
con.Open();
int row = cmd.ExecuteNonQuery();
con.Close();
//return row;
}
string emp_number ="-1";
using (SqlCommand cmd = new SqlCommand("SELECT EMP_NUMBER FROM HS_SM_USER_ACCOUNT WHERE [email protected]_USER_ID"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Parameters.AddWithValue("@USRACC_USER_ID", USRACC_USER_ID);
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
dt.TableName = "HS_SM_USER_ACCOUNT";
sda.Fill(dt);
if(dt.Rows.Count > 0)
emp_number = dt.Rows[0][0]==DBNull.Value ? "-1" : dt.Rows[0][0].ToString();
}
}
}
using (SqlCommand cmd = new SqlCommand("INSERT INTO HS_EMP_EMAIL_TEMP_LOG (EMP_NUMBER,USRACC_USER_ID,EMP_OFFICE_EMAIL,LOG_DATE_TIME) VALUES(@EMP_NUMBER,@USRACC_USER_ID,@EMP_OFFICE_EMAIL,GETDATE())"))
{
cmd.Parameters.AddWithValue("@EMP_NUMBER", emp_number);
cmd.Parameters.AddWithValue("@USRACC_USER_ID", USRACC_USER_ID);
cmd.Parameters.AddWithValue("@EMP_OFFICE_EMAIL", EMP_OFFICE_EMAIL);
cmd.Connection = con;
con.Open();
int row = cmd.ExecuteNonQuery();
con.Close();
// return row;
}
return 1;
}
}
}
}