 |
|
ASP.Net หาก User กรอกข้อมูลที่เป็น คอมโบ Web page กัน แล้วเผลอปิดไป จะทำยังไง ให้เวลาเราเปิดแล้วใส่รหัสเดิมไป Userจะสามารถทำต่อได้จากของเดิมที่เผลอปิดไปอ่ะครับ |
|
 |
|
|
 |
 |
|
ผมพยายามแล้วครับ แต่มันไม่เห็นผล 
Code (C#)
int strNumRows;
string strSQL;
SqlConnection conn = new SqlConnection();
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["SPersonnelConnectionString"].ConnectionString;
{
SqlCommand cmd = new SqlCommand();
{
cmd.Connection = conn;
conn.Open();
strSQL = "SELECT COUNT(*) FROM Personnel WHERE ID_Pers = '" + this.txtID_Pers.Text + "' ";
cmd = new SqlCommand(strSQL, conn);
//cmd.Parameters.AddWithValue("@ID_Pers", SqlDbType.NVarChar).Value = this.txtID_Pers.Text;
strNumRows = Convert.ToInt32(cmd.ExecuteScalar());
if (txtID_Pers.Text == "")
{
this.lbIDPers.Text = "กรุณากรอกรหัสพนักงาน";
lbIDPers.ForeColor = Color.Red;
return;
}
if (Session["ID_Pers"] == this.txtID_Pers.Text)
{
if (db.ID_Card2 == "")
{
Response.Redirect("Default2.aspx");
}
else if (db.ID_Card3 =="")
{
Response.Redirect("Default3.aspx");
}
else if (db.ID_Card5 =="")
{
Response.Redirect("Default5.aspx");
}
else if (db.ID_Card4 =="")
{
Response.Redirect("Default4.aspx");
}
else
{
Response.Redirect("Default6.aspx");
}
}
else if (strNumRows > 0)
{
this.lbIDPers.Text = "รหัสพนักงานนี้ได้ทำการบันทึกข้อมูลไปแล้ว กรุณาตรวจสอบ";
lbIDPers.ForeColor = Color.Red;
txtName.Enabled = false;
txtID_Card.Enabled = false;
txtdatStart.Enabled = false;
txtID_Pers.Focus();
}
else
{
this.lbIDPers.Text = "รหัสพนักงานนี้ยังไม่ได้ทำการบันทึกข้อมุล";
lbIDPers.ForeColor = Color.Green;
txtName.Enabled = true;
txtID_Card.Enabled = true;
txtdatStart.Enabled = true;
txtName.BackColor = default(Color);
txtID_Card.BackColor = default(Color);
txtdatStart.BackColor = default(Color);
txtName.Focus();
}
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
}
เขียนมั่วไหมอ่ะครับ มันขึ้น เส้นเขียว ตรง Session["ID_Pers"] == this.txtID_Pers.Text ตรงคำว่า session อ่ะครับ
ขึ้นว่า Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
Debug แล้ว แต่มัน run ข้าม session ไปเลยอ่ะครับ ผมต้องทำยังไง แนะนำหน่อยครับ พี่ๆ
ขอขอบคุณมากครับ สำหรับคำตอบและข้อเสนอแนะ ของทุกท่าน 
เครดิต Code ของพี่วิน จาก กระทู้
https://www.thaicreate.com/dotnet/forum/088033.html
ขอบคุณครับ
|
ประวัติการแก้ไข 2013-09-02 00:00:37
 |
 |
 |
 |
Date :
2013-09-01 23:52:36 |
By :
Bill17259 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คงจะต้องใช้พวก Session ในการจัดเก็บพวกค่าตัวแปรครับ
|
 |
 |
 |
 |
Date :
2013-09-02 06:14:40 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมกลับมาใช้ Stored Procedures แทนแล้วครับพี่ คืองี้ 
เขียนสโตก่อน (มีตั้งหมด 6 Table ก็เขียนไป 6 Table เลยนะครับเพื่อนๆ)
USE [SPersonnel]
GO
/****** Object: StoredProcedure [dbo].[sps_GetPersonDetail] Script Date: 09/02/2013 09:48:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[sps_GetPersonDetail]
(
@ID_Pers nvarchar(6)
)
AS
Select * from dbo.Personnel
where ID_Pers=@ID_Pers
Select * from dbo.SP_Work
where ID_Pers=@ID_Pers
Select * from dbo.SP_Sick
Where ID_Pers=@ID_Pers
Select * from dbo.Sick_even
Where ID_Pers=@ID_Pers
Select * from dbo.Family_s
Where ID_Pers=@ID_Pers
Select * from dbo.Cigarette_s
Where ID_Pers=@ID_Pers
แล้วก็มาเขียน GetData โดยใช้คำสั่ง DataSet โดยการ Create Class ขึ้นมา 1 Class
public DataSet GetData()
{
DataSet Ds = new DataSet();
SqlConnection conn = new SqlConnection();
{
conn.ConnectionString = ConfigurationManager
.ConnectionStrings["SPersonnelConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
{
cmd.CommandText = TSql;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
SqlDataAdapter da = new SqlDataAdapter();
{
da.SelectCommand = cmd;
da.Fill(Ds);
}
conn.Close();
conn.Dispose();
}
}
return Ds;
}
แล้วก็มาเขียนใน .aspx.cs ปุ่ม Check นั่นเอง ว่า
DataSet ds = new DataSet();
DataTable dt1, dt2, dt3, dt4, dt5, dt6;
db.TSql = "exec sps_GetPersonDetail '" + txtID_Pers.Text+ "'";
ds = db.GetData();
dt1 = ds.Tables[0];
dt2 = ds.Tables[1];
dt3 = ds.Tables[2];
dt4 = ds.Tables[3];
dt5 = ds.Tables[4];
dt6 = ds.Tables[5];
if (dt1.Rows.Count == 0) //ถ้าไม่มีข้อมูล
{
txtName.Focus();
return;
}
if (dt2.Rows.Count == 0)
{
Response.Redirect("Default2.aspx?Value1=" + txtID_Pers.Text);
return;
}
if (dt3.Rows.Count == 0)
{
Response.Redirect("Default3.aspx?Value2=" + txtID_Pers.Text);
return;
}
if (dt4.Rows.Count == 0)
{
Response.Redirect("Default3.aspx?Value4=" + txtID_Pers.Text);
return;
}
if (dt5.Rows.Count == 0)
{
Response.Redirect("Default3.aspx?Value3=" + txtID_Pers.Text);
return;
}
if (dt6.Rows.Count == 0)
{
Response.Redirect("Default3.aspx?Value5=" + txtID_Pers.Text);
return;
}
ครับ แล้วข้อมูลก็จะเด้งไป หน้าที่เรายังไม่ได้กรอกข้อมูลลงไปอ่ะครับ เพื่อทำต่อได้เลย
หัวหน้าผมเค้าสอนทำอ่ะครับ ใจดีจัง แต่ไม่กล้าถามเค้าบ่อยครับ เค้ามีงานเยอะ อันนี้ เอามาแบ่งปันครับ ถามเว็บนี้มาเยอะแล้ว เลยอยากตอบแทนอะไรบ้างเล็กๆ น้อยๆก็ยังดีครับ 
|
 |
 |
 |
 |
Date :
2013-09-02 09:58:57 |
By :
Bill17259 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าผมจะตำหนิว่า ตรรกะ/วิธีการ ไม่ค่อยจะถูกต้อง หลงทาง (ทั้งหัวหน้า/ลูกน้อง)
1. Store Procedure หลงไปไกลลิบ
2. ขั้นตอนการทำงาน หลงไปไกลลิบลับ
---- 2.1 วิธีการ ป้อน/แก้ไข ข้อมูล
---- 2.2 อะไรควรแยกกลับเอามารวมกัน อะไรควรเอามารวมกันกลับแยกไปซะงั้น
...
...
|
 |
 |
 |
 |
Date :
2013-09-02 16:43:22 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
กำลังคิดว่า ถ้า User เผลอปิด ก็ให้แสดง dialog ถามก่อนจะได้ไหม
|
 |
 |
 |
 |
Date :
2013-09-02 17:13:37 |
By :
watcharop |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
xxx ออกแบบหน้าจอให้เป็น Page เดียว (ข้อมูล Input/Output มันเยอะ)
1, 2, 3, ... ก็เลือกเอาตามสะดวก คล้ายฯ ระบบจองตั๋วเครื่องบิน/รถโดยสาร
--- 1. ใช้ Tab Page แบ่งเป็นหน้าฯ ไป หรือ
--- 2. ใช้ Div แบ่งเป็นหน้าฯ ไป หรือ
--- 3. ใช้ Panel แบ่งเป็นหน้าฯ ไป หรือ
--- 4. ใช้ Multi View แบ่งเป็นหน้าฯ ไป หรือ
--- 5. ใช้ User Control แบ่งเป็นหน้าฯ ไป
แล้วค่อย Set Visible = False/Active
yyy QUERY
Select * From xTable Inner Join yTable Cross Apply zTable Where ID_Pers=@ID_Pers
|
 |
 |
 |
 |
Date :
2013-09-03 16:52:29 |
By :
ผ่านมา |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|