using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class userListEdit : System.Web.UI.Page
{
Int32 countRec;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Button8.Visible = false;
Button9.Visible = false;
Label11116.Visible = false;
Button5.Visible = true;
Button6.Visible = true;
Button7.Visible = true;
if (Request["type"]== "E")
{
UserListloaddata();
}
else
{
Label11113.Visible = false;
TBId.Visible = false;
Button7.Visible = false;
Button10.Visible = false;
}
}
}
void UserListloaddata()
{
string strSQL;
SqlConnection myConnection = new SqlConnection(ConnectionString);
strSQL = "select * FROM tblMM_User_List WHERE MM_ID=" + Request["ID"];
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
myConnection.Open();
SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (myReader.Read())
{
TBId.Text = myReader["MM_ID"].ToString();
TBUserId.Text = myReader["MM_UserID"].ToString();
TBUserFnam.Text = myReader["MM_User_First"].ToString();
TBUserLname.Text = myReader["MM_User_Last"].ToString();
TBSecode.Text = myReader["MM_Sec_Code"].ToString();
DDTBSecTyp.SelectedItem.Text = myReader["MM_Type"].ToString();
TBTicNo.Text = myReader["MM_TicketNo"].ToString();
TBTicDT.Text = myReader["MM_TicketDate"].ToString();
TBDtSubmit.Text = myReader["MM_DtSubmtLegal"].ToString();
TBDateLegal.Text = myReader["MM_DtAddLegal"].ToString();
TBComm.Text = myReader["MM_Comment"].ToString();
}
myReader.Close();
myConnection.Close();
}
void updateMemo()
{
//Response.Write(DDTBSecTyp.SelectedItem.Text);
//Response.End();
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
strSQL = "update tblMM_User_List set MM_UserID=@MM_UserID,MM_User_First=@MM_User_First,MM_User_Last=@MM_User_Last,MM_Sec_Code=@MM_Sec_Code,MM_Type=@MM_Type,MM_TicketNo=@MM_TicketNo,"
+ "MM_TicketDate=@MM_TicketDate,MM_DtSubmtLegal=@MM_DtSubmtLegal,MM_DtAddLegal=@MM_DtAddLegal,MM_Comment=@MM_Comment,MM_UpdDate=@MM_UpdDate"
+ " WHERE MM_Id =" + Request["ID"];
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
cmd.Parameters.AddWithValue("@MM_UserID"
, TBUserId.Text);
cmd.Parameters.AddWithValue("@MM_User_First", TBUserFnam.Text);
cmd.Parameters.AddWithValue("@MM_User_Last",TBUserLname.Text);
cmd.Parameters.AddWithValue("@MM_Sec_Code", TBSecode.Text);
cmd.Parameters.AddWithValue("@MM_Type", DDTBSecTyp.SelectedItem.Text);
cmd.Parameters.AddWithValue("@MM_TicketNo",TBTicNo.Text);
cmd.Parameters.AddWithValue("@MM_TicketDate",TBTicDT.Text);
cmd.Parameters.AddWithValue("@MM_DtSubmtLegal",TBDtSubmit.Text)
;
cmd.Parameters.AddWithValue("@MM_DtAddLegal",TBDateLegal.Text);
cmd.Parameters.AddWithValue("@MM_Comment",TBComm.Text);
cmd.Parameters.AddWithValue("@MM_UpdDate", DateTime.Today.ToShortDateString());
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
}
void insertUserlist()
{
//Response.Write(DDTBSecTyp.SelectedItem.Text);
//Response.End();
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
strSQL = "insert into tblMM_User_List(MM_UserID,MM_User_First,MM_User_Last,MM_Sec_Code,MM_Type,MM_TicketNo,MM_TicketDate,MM_DtSubmtLegal,MM_DtAddLegal,MM_Comment,MM_UpdDate)values"
+ "(@MM_UserID,@MM_User_First,@MM_User_Last,@MM_Sec_Code,@MM_Type,@MM_TicketNo,@MM_TicketDate,@MM_DtSubmtLegal,@MM_DtAddLegal,@MM_Comment,@MM_UpdDate)";
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@MM_UserID", TBUserId.Text);
cmd.Parameters.AddWithValue("@MM_User_First", TBUserFnam.Text);
cmd.Parameters.AddWithValue("@MM_User_Last", TBUserLname.Text);
cmd.Parameters.AddWithValue("@MM_Sec_Code", TBSecode.Text);
cmd.Parameters.AddWithValue("@MM_Type", DDTBSecTyp.SelectedItem.Text);
cmd.Parameters.AddWithValue("@MM_TicketNo", TBTicNo.Text);
cmd.Parameters.AddWithValue("@MM_TicketDate", TBTicDT.Text);
cmd.Parameters.AddWithValue("@MM_DtSubmtLegal", TBDtSubmit.Text);
cmd.Parameters.AddWithValue("@MM_DtAddLegal", TBDateLegal.Text);
cmd.Parameters.AddWithValue("@MM_Comment", TBComm.Text);
cmd.Parameters.AddWithValue("@MM_UpdDate", DateTime.Today.ToShortDateString());
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
}
protected void Button5_Click(object sender, EventArgs e)
{
if (Request["type"].ToString() == "E")
{
updateMemo();
updateusersercurity();
Response.Redirect("userListM.aspx");
}
if (Request["type"].ToString() == "A")
{
if (countRec >= 1)
{
Label11117.Visible = true;
}
else
{
Countdupdata();
insertUserlist();
updateusersercurity();
Response.Redirect("userListM.aspx");
}
}
}
void Deletedata()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
strSQL = "delete from tblMM_User_List WHERE MM_ID=" + Request["ID"];
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
cmd.CommandType = CommandType.Text;
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
}
void Countdupdata()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
strSQL = "SELECT COUNT(*) FROM tblMM_User_List where MM_UserID ='" + TBUserId.Text + "' and MM_Sec_Code='" + TBSecode.Text + "'";
myConnection.Open();
SqlCommand comm = new SqlCommand(strSQL, myConnection);
countRec = (Int32)comm.ExecuteScalar();
myConnection.Close();
}
protected void Button6_Click(object sender, EventArgs e)
{
Response.Redirect("userListM.aspx");
}
protected void Button8_Click(object sender, EventArgs e)
{
Deletedata();
updateusersercurity();
Response.Redirect("userListM.aspx");
}
protected void Button9_Click(object sender, EventArgs e)
{
Button8.Visible = false;
Button9.Visible = false;
Button10.Visible = false;
Label11116.Visible = false;
Button5.Visible = true;
Button6.Visible = true;
Button7.Visible = true;
}
protected void Button7_Click(object sender, EventArgs e)
{
Button8.Visible = true;
Button9.Visible = true;
Label11116.Visible = true;
Button10.Visible = false;
Button5.Visible = false;
Button6.Visible = false;
Button7.Visible = false;
}
protected void Button10_Click(object sender, EventArgs e)
{
Countdupdata();
if (countRec >= 1)
{
Label11117.Visible = true;
}
else
{
insertUserlist();
updateusersercurity();
Response.Redirect("userListM.aspx");
}
}
void updateusersercurity()
{
SqlConnection myConnection = new SqlConnection(ConnectionString);
string strSQL;
strSQL = "dbo.SP_MM_SecurityByUser '" + TBUserId.Text.Trim() + "'";
SqlCommand cmd = new SqlCommand(strSQL, myConnection);
cmd.CommandType = CommandType.Text;
myConnection.Open();
cmd.ExecuteNonQuery();
myConnection.Close();
Label11112.Visible = true;
}
private string ConnectionString
{
get
{
string connectionString = ConfigurationManager.ConnectionStrings["MMDB_PDConnectionString"].ConnectionString;
return connectionString;
}
}
}
--------------
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="userListEdit.aspx.cs" Inherits="userListEdit" %>
|
Text="User List Add/Modification ">