예제 #1
0
    protected void logOut_Click(object sender, EventArgs e)
    {
        if (Session["account"] != null || Session["player"] != null)
        {
            string userName = string.Empty;
            if (Session["account"] == null)
            {
                userName = ((Lib.Player)(Session["player"])).ID;
                SysSetting.AddLog("登入", userName, "一般受測人員登出成功", DateTime.Now);
            }
            else
            {
                userName = ((Lib.Account)(Session["account"])).ID;
                SysSetting.AddLog("登入", userName, "進階使用者登出成功", DateTime.Now);
            }

            Session.Clear();
            Response.Redirect("~/Login.aspx");
        }
        else
        {
            Response.Redirect("~/Login.aspx");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Image1.ImageUrl = "~/images/106_Seal_Sample.JPG";
        Acc             = Request.QueryString["Acc"].ToString();
        if (Page.IsPostBack == false)
        {
            hf_StartTime.Value = Label8.Text;
            hf_EndTime.Value   = Label9.Text;
            //hf_start.Value = "2015/01/01";

            Dictionary <string, object> d  = new Dictionary <string, object>();
            Lib.DataUtility             du = new Lib.DataUtility();
            d.Add("sid", Request.QueryString["sid"].ToString());
            d.Add("center_code", Request.QueryString["centercode"].ToString());
            //DataTable dt = du.getDataTableByText("SELECT P.PrevSID,P.start1_date,P.end1_date,T.ThisSID,T.start2_date,T.end2_date, N.NextSID,N.start3_date,N.end3_date FROM ( SELECT MAX(A.sid) PrevSID, (select start_date FROM Center_Seal where sid = MAX(A.sid)) start1_date,(select end_date FROM Center_Seal where sid = MAX(A.sid)) end1_date from Center_Seal A where A.sid < @sid and A.center_code = @center_code and A.rank_code=(select rank_code from Center_Seal where sid=@sid)) P CROSS JOIN ( SELECT MAX(A.sid) ThisSID, (select start_date FROM Center_Seal where sid = MAX(A.sid)) start2_date,(select end_date FROM Center_Seal where sid = MAX(A.sid)) end2_date from Center_Seal A where A.sid = @sid and A.center_code = @center_code and A.rank_code=(select rank_code from Center_Seal where sid=@sid)) T CROSS JOIN( SELECT MIN(A.sid) NextSID, (select start_date FROM Center_Seal where sid = MIN(A.sid)) start3_date,(select end_date FROM Center_Seal where sid = MAX(A.sid)) end3_date from Center_Seal A where A.sid > @sid and A.center_code = @center_code and A.rank_code=(select rank_code from Center_Seal where sid=@sid)) N ",d);
            //2016-8-16改用sp
            DataTable dt = du.getDataTableBysp("Ex106_Update_Seal", d);
            //前一筆:PrevSID、start1_date、end1_date
            //當筆:ThisSID、start2_date、end2_date
            //後一筆:NextSID、start3_date、end3_date
            //d.Add("start_date", dt.Rows[0]["start_date"]);

            //沒前面一筆,有當筆,沒有後一筆(010)(最前面一筆,只有一筆)
            if (string.IsNullOrEmpty(dt.Rows[0]["PrevSID"].ToString()) & !string.IsNullOrEmpty(dt.Rows[0]["ThisSID"].ToString()) & string.IsNullOrEmpty(dt.Rows[0]["NextSID"].ToString()))
            {
                //設定時間
                PrevSID = dt.Rows[0]["PrevSID"].ToString();
                ThisSID = dt.Rows[0]["ThisSID"].ToString();
                NextSID = dt.Rows[0]["NextSID"].ToString();

                DateTime Now_startTime = (DateTime)dt.Rows[0]["start2_date"];
                Label6.Text   = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox1.Text = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox2.Text = dt.Rows[0]["sing_unit"].ToString();
                TextBox3.Text = dt.Rows[0]["sing_rank"].ToString();
                TextBox4.Text = dt.Rows[0]["sing_name"].ToString();
                old_time      = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                old_unit      = dt.Rows[0]["sing_unit"].ToString();
                old_rank      = dt.Rows[0]["sing_rank"].ToString();
                old_name      = dt.Rows[0]["sing_name"].ToString();
                DateTime Today = DateTime.Now;
                Label8.Text = "106/01/01";
                Label9.Text = Lib.SysSetting.ToRocDateFormat(Today.ToString("yyyy/MM/dd"));
            }

            //沒前面一筆,有當筆,也有後一筆(011)(最前面一筆,有多筆)
            else if (string.IsNullOrEmpty(dt.Rows[0]["PrevSID"].ToString()) & !string.IsNullOrEmpty(dt.Rows[0]["ThisSID"].ToString()) & !string.IsNullOrEmpty(dt.Rows[0]["NextSID"].ToString()))
            {
                //設定時間
                PrevSID = dt.Rows[0]["PrevSID"].ToString();
                ThisSID = dt.Rows[0]["ThisSID"].ToString();
                NextSID = dt.Rows[0]["NextSID"].ToString();

                DateTime Now_startTime    = (DateTime)dt.Rows[0]["start2_date"];
                DateTime Next_start_date  = (DateTime)dt.Rows[0]["start3_date"];
                DateTime Next2_start_date = Next_start_date.AddDays(-2);
                Label6.Text   = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox1.Text = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox2.Text = dt.Rows[0]["sing_unit"].ToString();
                TextBox3.Text = dt.Rows[0]["sing_rank"].ToString();
                TextBox4.Text = dt.Rows[0]["sing_name"].ToString();
                old_time      = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                old_unit      = dt.Rows[0]["sing_unit"].ToString();
                old_rank      = dt.Rows[0]["sing_rank"].ToString();
                old_name      = dt.Rows[0]["sing_name"].ToString();
                Label8.Text   = "106/01/01";
                Label9.Text   = Lib.SysSetting.ToRocDateFormat(Next2_start_date.ToString("yyyy/MM/dd"));
            }
            //有前面一筆,有當筆,沒後面一筆(110)(最後一筆)
            else if (!string.IsNullOrEmpty(dt.Rows[0]["PrevSID"].ToString()) & !string.IsNullOrEmpty(dt.Rows[0]["ThisSID"].ToString()) & string.IsNullOrEmpty(dt.Rows[0]["NextSID"].ToString()))
            {
                //設定時間
                PrevSID = dt.Rows[0]["PrevSID"].ToString();
                ThisSID = dt.Rows[0]["ThisSID"].ToString();
                NextSID = dt.Rows[0]["NextSID"].ToString();

                DateTime Now_startTime    = (DateTime)dt.Rows[0]["start2_date"];
                DateTime Prev_start_date  = (DateTime)dt.Rows[0]["start1_date"];
                DateTime Prev2_start_date = Prev_start_date.AddDays(+2);
                DateTime Today            = DateTime.Now;
                Label6.Text   = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox1.Text = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox2.Text = dt.Rows[0]["sing_unit"].ToString();
                TextBox3.Text = dt.Rows[0]["sing_rank"].ToString();
                TextBox4.Text = dt.Rows[0]["sing_name"].ToString();
                old_time      = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                old_unit      = dt.Rows[0]["sing_unit"].ToString();
                old_rank      = dt.Rows[0]["sing_rank"].ToString();
                old_name      = dt.Rows[0]["sing_name"].ToString();
                Label8.Text   = Lib.SysSetting.ToRocDateFormat(Prev2_start_date.ToString("yyyy/MM/dd"));
                //Label9.Text = Lib.SysSetting.ToRocDateFormat(Today.ToString("yyyy/MM/dd"));
                Label9.Text = "";
            }

            //有三筆,前中後都要改(111)(多筆,剛好在中間)
            else if (!string.IsNullOrEmpty(dt.Rows[0]["PrevSID"].ToString()) & !string.IsNullOrEmpty(dt.Rows[0]["ThisSID"].ToString()) & !string.IsNullOrEmpty(dt.Rows[0]["NextSID"].ToString()))//有三筆,前中後都要改
            {
                //設定時間
                PrevSID = dt.Rows[0]["PrevSID"].ToString();
                ThisSID = dt.Rows[0]["ThisSID"].ToString();
                NextSID = dt.Rows[0]["NextSID"].ToString();

                DateTime Now_startTime    = (DateTime)dt.Rows[0]["start2_date"];
                DateTime Prev_start_date  = (DateTime)dt.Rows[0]["start1_date"];
                DateTime Next_start_date  = (DateTime)dt.Rows[0]["start3_date"];
                DateTime Prev2_start_date = Prev_start_date.AddDays(+2);
                DateTime Next2_start_date = Next_start_date.AddDays(-2);
                Label6.Text   = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox1.Text = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                TextBox2.Text = dt.Rows[0]["sing_unit"].ToString();
                TextBox3.Text = dt.Rows[0]["sing_rank"].ToString();
                TextBox4.Text = dt.Rows[0]["sing_name"].ToString();
                old_time      = Lib.SysSetting.ToRocDateFormat(Now_startTime.ToString("yyyy/MM/dd"));
                old_unit      = dt.Rows[0]["sing_unit"].ToString();
                old_rank      = dt.Rows[0]["sing_rank"].ToString();
                old_name      = dt.Rows[0]["sing_name"].ToString();
                Label8.Text   = Lib.SysSetting.ToRocDateFormat(Prev2_start_date.ToString("yyyy/MM/dd"));
                Label9.Text   = Lib.SysSetting.ToRocDateFormat(Next2_start_date.ToString("yyyy/MM/dd"));
            }
            else
            {
                //查無資料
            }
        }

        if (Page.IsPostBack == true)
        {
            string new_time = string.Empty;
            if (CheckDateTimeType(TextBox1.Text) == true & !string.IsNullOrEmpty(TextBox1.Text) & !string.IsNullOrEmpty(TextBox2.Text) & !string.IsNullOrEmpty(TextBox3.Text) & !string.IsNullOrEmpty(TextBox4.Text))
            {
                Label3.Text = null;

                DateTime EndTime;//結束時間

                //2.判斷日期是否在合理範圍
                //轉回西元年
                try
                {
                    DateTime ChangeTime = Lib.SysSetting.ToWorldDate(TextBox1.Text);              //更改的時間
                    DateTime StartTime  = Lib.SysSetting.ToWorldDate(Label8.Text);                //起始時間
                    new_time = Lib.SysSetting.ToRocDateFormat(ChangeTime.ToString("yyyy/MM/dd")); //更改的時間轉為民國作比較
                    if (Label9.Text == "")
                    {
                        EndTime = Lib.SysSetting.ToWorldDate("999/12/31");//結束時間
                    }
                    else
                    {
                        EndTime = Lib.SysSetting.ToWorldDate(Label9.Text);//結束時間
                    }
                    //EndTime = Lib.SysSetting.ToWorldDate(Label9.Text);//結束時間
                    //2016-8-16新增更新簽章單位、級職、姓名
                    string sing_unit = TextBox2.Text;
                    string sing_rank = TextBox3.Text;
                    string sing_name = TextBox4.Text;

                    if (ChangeTime >= StartTime & ChangeTime <= EndTime)
                    {
                        Dictionary <string, object> dd  = new Dictionary <string, object>();
                        Lib.DataUtility             duu = new Lib.DataUtility();
                        dd.Add("PrevSID", PrevSID);
                        dd.Add("ThisSID", ThisSID);
                        dd.Add("NextSID", NextSID);
                        dd.Add("start_date", ChangeTime);              //當筆啟始時間
                        dd.Add("prev_date", (ChangeTime.AddDays(-1))); //上一筆結束時間
                        dd.Add("next_date", (ChangeTime.AddDays(+1))); //下一筆啟始時間
                        //2016-8-16新增更新簽章單位、級職、姓名
                        dd.Add("sing_unit", sing_unit);
                        dd.Add("sing_rank", sing_rank);
                        dd.Add("sing_name", sing_name);

                        //更新圖檔
                        //2016-8-16開始畫印章
                        string sing1_unit = string.Empty;
                        string sing1_rank = string.Empty;
                        string sing1_name = string.Empty;
                        //string jpg_Name = string.Empty;

                        sing1_unit = sing_unit;
                        sing1_rank = sing_rank;
                        sing1_name = sing_name;

                        Font s1_unit = null;                                       //鑑測官-單位
                        Font s1_rank = null;                                       //鑑測官-級職

                        Font seal_font_name = new Font("標楷體", 48, FontStyle.Bold); //姓名
                        if (sing1_unit.Length <= 6)
                        {
                            s1_unit = new Font("標楷體", 34, FontStyle.Bold);//6個字
                        }
                        else if (sing1_unit.Length == 7)
                        {
                            s1_unit = new Font("標楷體", 30, FontStyle.Bold);//7個字
                        }
                        else if (sing1_unit.Length == 8)
                        {
                            s1_unit = new Font("標楷體", 26, FontStyle.Bold);//8個字
                        }
                        else if (sing1_unit.Length == 9)
                        {
                            s1_unit = new Font("標楷體", 24, FontStyle.Bold);//9個字
                        }
                        else if (sing1_unit.Length == 10)
                        {
                            s1_unit = new Font("標楷體", 22, FontStyle.Bold);//10個字
                        }
                        else if (sing1_unit.Length == 11)
                        {
                            s1_unit = new Font("標楷體", 20, FontStyle.Bold);//11個字
                        }
                        else if (sing1_unit.Length == 12)
                        {
                            s1_unit = new Font("標楷體", 18, FontStyle.Bold);//12個字
                        }
                        else
                        {
                            s1_unit = new Font("標楷體", 16, FontStyle.Bold);//超過12個字
                        }
                        //判斷鑑測官-級職 字長度
                        if (sing1_rank.Length <= 6)
                        {
                            s1_rank = new Font("標楷體", 34, FontStyle.Bold);//6個字
                        }
                        else if (sing1_rank.Length == 7)
                        {
                            s1_rank = new Font("標楷體", 30, FontStyle.Bold);//7個字
                        }
                        else if (sing1_rank.Length == 8)
                        {
                            s1_rank = new Font("標楷體", 26, FontStyle.Bold);//8個字
                        }
                        else if (sing1_rank.Length == 9)
                        {
                            s1_rank = new Font("標楷體", 24, FontStyle.Bold);//9個字
                        }
                        else if (sing1_rank.Length == 10)
                        {
                            s1_rank = new Font("標楷體", 22, FontStyle.Bold);//10個字
                        }
                        else if (sing1_rank.Length == 11)
                        {
                            s1_rank = new Font("標楷體", 20, FontStyle.Bold);//11個字
                        }
                        else if (sing1_rank.Length == 12)
                        {
                            s1_rank = new Font("標楷體", 18, FontStyle.Bold);//12個字
                        }
                        else
                        {
                            s1_rank = new Font("標楷體", 16, FontStyle.Bold);//超過12個字
                        }

                        int height = 180;
                        int width  = 480;

                        Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);

                        Graphics g = Graphics.FromImage(bmp);
                        g.SmoothingMode = SmoothingMode.AntiAlias;
                        g.Clear(Color.White);

                        StringFormat stringFormat = new StringFormat();
                        stringFormat.Alignment     = StringAlignment.Center;
                        stringFormat.LineAlignment = StringAlignment.Center;

                        Pen seal_pen = new Pen(Color.Red, 15);

                        g.DrawRectangle(seal_pen, 0, 0, 480, 180);           //鑑測官外框
                        //鑑測章內容
                        SolidBrush   redSB      = new SolidBrush(Color.Red); //字設成紅色
                        Pen          seal_pen2  = new Pen(Color.Red, 5);
                        StringFormat sealFormat = new StringFormat();
                        sealFormat.Alignment     = StringAlignment.Center;
                        sealFormat.LineAlignment = StringAlignment.Center;

                        DrawSpacedText(g, s1_unit, redSB, new Point(3, 30), sing1_unit, 260);
                        DrawSpacedText(g, s1_rank, redSB, new Point(3, 100), sing1_rank, 260);
                        DrawSpacedText(g, seal_font_name, redSB, new Point(245, 60), sing1_name, 240);

                        byte[] bytedata = (byte[])ImageToByte(bmp);
                        dd.Add("img_byte", bytedata);//加入圖檔索引

                        //開始更新,判斷要更新的欄位
                        //只有當筆(010)
                        if (string.IsNullOrEmpty(PrevSID) & !string.IsNullOrEmpty(ThisSID) & string.IsNullOrEmpty(NextSID))
                        {
                            duu.executeNonQueryByText("update Center_Seal set start_date=@start_date,sing_unit=@sing_unit,sing_rank=@sing_rank,sing_name=@sing_name,img_byte=@img_byte where sid=@ThisSID", dd);//更新當筆
                            //2016-9-7更新資料寫入log
                            if (old_time == new_time & old_unit == sing1_unit & old_rank == sing1_rank & old_name == sing1_name)
                            {
                                //都一樣沒更改,不產生log
                            }
                            else
                            {
                                //資料有異動,產生log
                                string event_log = string.Empty;
                                event_log += "[SID:" + ThisSID + "] ";
                                if (old_time != new_time)
                                {
                                    event_log += "啟用時間:" + old_time + "->" + new_time + "。";
                                }
                                if (old_unit != sing1_unit)
                                {
                                    event_log += "單位:" + old_unit + "->" + sing1_unit + "。";
                                }
                                if (old_rank != sing1_rank)
                                {
                                    event_log += "級職:" + old_rank + "->" + sing1_rank + "。";
                                }
                                if (old_name != sing1_name)
                                {
                                    event_log += "姓名:" + old_name + "->" + sing1_name + "。";
                                }

                                SysSetting.AddLog("簽章維護", Acc, event_log, DateTime.Now);
                            }


                            Label3.Text = "簽章更新成功!!";
                            PrevSID     = string.Empty;
                            ThisSID     = string.Empty;
                            NextSID     = string.Empty;
                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.close();window.opener.location.reload()", true);
                            //2016-9-12測試成功,先把方法傳回母視窗(刷新列表),再關掉子視窗
                            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside();window.close()", true);
                        }
                        //沒前面一筆,有當筆,也有後一筆(011)(最前面一筆,有多筆)
                        else if (string.IsNullOrEmpty(PrevSID) & !string.IsNullOrEmpty(ThisSID) & !string.IsNullOrEmpty(NextSID))
                        {
                            duu.executeNonQueryByText("update Center_Seal set start_date=@start_date,sing_unit=@sing_unit,sing_rank=@sing_rank,sing_name=@sing_name,img_byte=@img_byte where sid=@ThisSID", dd);//更新當筆
                            //duu.executeNonQueryByText("update Center_Seal set start_date=@next_date where sid=@NextSID", dd);//更新下一筆啟始時間
                            //Response.Redirect(Request.Url.ToString());

                            //2016-9-7更新資料寫入log
                            if (old_time == new_time & old_unit == sing1_unit & old_rank == sing1_rank & old_name == sing1_name)
                            {
                                //都一樣沒更改,不產生log
                            }
                            else
                            {
                                //資料有異動,產生log
                                string event_log = string.Empty;
                                event_log += "[SID:" + ThisSID + "] ";
                                if (old_time != new_time)
                                {
                                    event_log += "啟用時間:" + old_time + "->" + new_time + "。";
                                }
                                if (old_unit != sing1_unit)
                                {
                                    event_log += "單位:" + old_unit + "->" + sing1_unit + "。";
                                }
                                if (old_rank != sing1_rank)
                                {
                                    event_log += "級職:" + old_rank + "->" + sing1_rank + "。";
                                }
                                if (old_name != sing1_name)
                                {
                                    event_log += "姓名:" + old_name + "->" + sing1_name + "。";
                                }

                                SysSetting.AddLog("簽章維護", Acc, event_log, DateTime.Now);
                            }

                            Label3.Text = "簽章更新成功!!";
                            PrevSID     = string.Empty;
                            ThisSID     = string.Empty;
                            NextSID     = string.Empty;
                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.close();window.opener.location.reload()", true);
                            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside();window.close()", true);
                        }
                        ////有前面一筆,有當筆,沒後面一筆(110)(最後一筆)//TEST
                        else if (!string.IsNullOrEmpty(PrevSID) & !string.IsNullOrEmpty(ThisSID) & string.IsNullOrEmpty(NextSID))
                        {
                            duu.executeNonQueryByText("update Center_Seal set start_date=@start_date,sing_unit=@sing_unit,sing_rank=@sing_rank,sing_name=@sing_name,img_byte=@img_byte where sid=@ThisSID", dd); //更新當筆
                            duu.executeNonQueryByText("update Center_Seal set end_date=@prev_date where sid=@PrevSID", dd);                                                                                      //更新上一筆結束時間
                            //Response.Redirect(Request.Url.ToString());

                            //2016-9-7更新資料寫入log
                            if (old_time == new_time & old_unit == sing1_unit & old_rank == sing1_rank & old_name == sing1_name)
                            {
                                //都一樣沒更改,不產生log
                            }
                            else
                            {
                                //資料有異動,產生log
                                string event_log = string.Empty;
                                event_log += "[SID:" + ThisSID + "] ";
                                if (old_time != new_time)
                                {
                                    event_log += "啟用時間:" + old_time + "->" + new_time + "。";
                                }
                                if (old_unit != sing1_unit)
                                {
                                    event_log += "單位:" + old_unit + "->" + sing1_unit + "。";
                                }
                                if (old_rank != sing1_rank)
                                {
                                    event_log += "級職:" + old_rank + "->" + sing1_rank + "。";
                                }
                                if (old_name != sing1_name)
                                {
                                    event_log += "姓名:" + old_name + "->" + sing1_name + "。";
                                }

                                SysSetting.AddLog("簽章維護", Acc, event_log, DateTime.Now);
                            }

                            Label3.Text = "簽章更新成功!!";
                            PrevSID     = string.Empty;
                            ThisSID     = string.Empty;
                            NextSID     = string.Empty;
                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.close();window.opener.location.reload()", true);
                            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside();window.close()", true);
                        }
                        //有三筆,前中後都要改(111)(多筆,剛好在中間)
                        else if (!string.IsNullOrEmpty(PrevSID) & !string.IsNullOrEmpty(ThisSID) & !string.IsNullOrEmpty(NextSID))
                        {
                            duu.executeNonQueryByText("update Center_Seal set start_date=@start_date,sing_unit=@sing_unit,sing_rank=@sing_rank,sing_name=@sing_name,img_byte=@img_byte where sid=@ThisSID", dd); //更新當筆
                            //duu.executeNonQueryByText("update Center_Seal set start_date=@next_date where sid=@NextSID", dd);//更新下一筆啟始時間
                            duu.executeNonQueryByText("update Center_Seal set end_date=@prev_date where sid=@PrevSID", dd);                                                                                      //更新上一筆結束時間
                            //Response.Redirect(Request.Url.ToString());

                            //2016-9-7更新資料寫入log
                            if (old_time == new_time & old_unit == sing1_unit & old_rank == sing1_rank & old_name == sing1_name)
                            {
                                //都一樣沒更改,不產生log
                            }
                            else
                            {
                                //資料有異動,產生log
                                string event_log = string.Empty;
                                event_log += "[SID:" + ThisSID + "] ";
                                if (old_time != new_time)
                                {
                                    event_log += "啟用時間:" + old_time + "->" + new_time + "。";
                                }
                                if (old_unit != sing1_unit)
                                {
                                    event_log += "單位:" + old_unit + "->" + sing1_unit + "。";
                                }
                                if (old_rank != sing1_rank)
                                {
                                    event_log += "級職:" + old_rank + "->" + sing1_rank + "。";
                                }
                                if (old_name != sing1_name)
                                {
                                    event_log += "姓名:" + old_name + "->" + sing1_name + "。";
                                }

                                SysSetting.AddLog("簽章維護", Acc, event_log, DateTime.Now);
                            }

                            Label3.Text = "簽章更新成功!!";
                            PrevSID     = string.Empty;
                            ThisSID     = string.Empty;
                            NextSID     = string.Empty;
                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.close();window.opener.location.reload()", true);
                            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside();window.close()", true);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        Label3.Text = "日期輸入範圍值錯誤,請查新檢查!!";
                    }
                }
                catch (Exception ex)
                {
                    Label3.Text = "日期格式錯誤";
                }
            }
            else
            {
                Label3.Text = "日期格式錯誤或欄位空白";
            }
        }
    }
예제 #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["account"] != null)
        {
            Account a = (Account)Session["account"];
            if (a.Role != ((int)SysSetting.Role.admin_hq).ToString())
            {
                Response.Redirect("~/index.aspx");
            }
            else
            {
                Check_memo = false;
                Sid        = Request.QueryString["sid"].ToString();
                if (Page.IsPostBack == false)//剛開始載入頁面
                {
                    Dictionary <string, object> d  = new Dictionary <string, object>();
                    Lib.DataUtility             du = new Lib.DataUtility();
                    d.Add("sid", Sid);
                    DataTable dt = du.getDataTableBysp("Ex108_GetResultDataBySid", d);
                    if (dt.Rows.Count > 0)
                    {
                        //個人基本資料
                        if (!string.IsNullOrEmpty(dt.Rows[0]["id"].ToString()))
                        {
                            Id = dt.Rows[0]["id"].ToString();
                        }
                        if (!string.IsNullOrEmpty(dt.Rows[0]["name"].ToString()))
                        {
                            Name             = dt.Rows[0]["name"].ToString();
                            txb_Name.Text    = Name;
                            Old_Name         = Name;
                            lab_OldName.Text = "(" + Old_Name + ")";
                        }
                        if (!string.IsNullOrEmpty(dt.Rows[0]["birth"].ToString()))
                        {
                            Birth             = dt.Rows[0]["birth"].ToString();
                            txb_Birth.Text    = Birth;
                            Old_Birth         = Birth;
                            lab_OldBirth.Text = "(" + Old_Birth + ")";
                        }
                        if (!string.IsNullOrEmpty(dt.Rows[0]["age"].ToString()))
                        {
                            Age             = dt.Rows[0]["age"].ToString();
                            txb_Age.Text    = Age;
                            Old_Age         = Age;
                            lab_OldAge.Text = "(" + Age + ")";
                        }
                        //檢查項次欄位
                        if (!string.IsNullOrEmpty(dt.Rows[0]["memo"].ToString()))
                        {
                            Check_memo = true;
                            Memo       = dt.Rows[0]["memo"].ToString();
                        }

                        //項次名稱
                        //項次1
                        if (!string.IsNullOrEmpty(dt.Rows[0]["sit_ups_name"].ToString()))
                        {
                            ItemName1           = dt.Rows[0]["sit_ups_name"].ToString();
                            lab_ItemScore1.Text = "(5)" + ItemName1 + "(成績)";
                            if (Check_memo == true)
                            {
                                if (Memo.Substring(0, 1) == "F" || Memo.Substring(0, 1) == "G" || Memo.Substring(0, 1) == "J")
                                {
                                    lab_Item1.Text = "(4)" + ItemName1 + Sec;
                                }
                                else
                                {
                                    lab_Item1.Text = "(4)" + ItemName1 + Count;
                                }
                            }
                            else
                            {
                                lab_Item1.Text = "(4)" + ItemName1 + "(次/秒數)";
                            }
                        }
                        //項次2
                        if (!string.IsNullOrEmpty(dt.Rows[0]["push_ups_name"].ToString()))
                        {
                            ItemName2           = dt.Rows[0]["push_ups_name"].ToString();
                            lab_ItemScore2.Text = "(7)" + ItemName2 + "(成績)";
                            if (Check_memo == true)
                            {
                                if (Memo.Substring(1, 1) == "F" || Memo.Substring(1, 1) == "G" || Memo.Substring(1, 1) == "J")
                                {
                                    lab_Item2.Text = "(6)" + ItemName2 + Sec;
                                }
                                else
                                {
                                    lab_Item2.Text = "(6)" + ItemName2 + Count;
                                }
                            }
                            else
                            {
                                lab_Item2.Text = "(6)" + ItemName2 + "(次/秒數)";
                            }
                        }
                        //項次3
                        if (!string.IsNullOrEmpty(dt.Rows[0]["run_name"].ToString()))
                        {
                            ItemName3           = dt.Rows[0]["run_name"].ToString();
                            lab_ItemScore3.Text = "(9)" + ItemName3 + "(成績)";
                            if (Check_memo == true)
                            {
                                if (Memo.Substring(2, 1) == "0" || Memo.Substring(2, 1) == "F" || Memo.Substring(2, 1) == "G" || Memo.Substring(2, 1) == "J")
                                {
                                    lab_Item3.Text = "(8)" + ItemName3 + Sec;
                                }
                                else
                                {
                                    lab_Item3.Text = "(8)" + ItemName3 + Count;
                                }
                            }
                            else
                            {
                                lab_Item3.Text = "(8)" + ItemName3 + "(次/秒數)";
                            }
                        }
                        //項次次數及成績
                        //項次1
                        if (!string.IsNullOrEmpty(dt.Rows[0]["sit_ups_score"].ToString()))
                        {
                            ItemScore1     = dt.Rows[0]["sit_ups_score"].ToString();
                            Old_ItemScore1 = ItemScore1;
                            if (ItemScore1 == "999")
                            {
                                lab_OldItem1.Text      = "(未完測)";
                                lab_OldItemScore1.Text = "(未完測)";
                            }
                            else
                            {
                                Old_ItemScore1         = ItemScore1;
                                txb_ItemScore1.Text    = ItemScore1;
                                lab_OldItemScore1.Text = "(" + Old_ItemScore1 + ")";
                            }
                            //項次1次/秒數
                            if (!string.IsNullOrEmpty(dt.Rows[0]["sit_ups"].ToString()))
                            {
                                Item1             = dt.Rows[0]["sit_ups"].ToString();
                                Old_Item1         = Item1;
                                txb_Item1.Text    = Item1;
                                lab_OldItem1.Text = "(" + Old_Item1 + ")";
                            }
                            else
                            {
                                Item1     = string.Empty;
                                Old_Item1 = string.Empty;
                            }
                        }
                        else
                        {
                            ItemScore1             = string.Empty;
                            Old_ItemScore1         = string.Empty;
                            Item1                  = string.Empty;
                            Old_Item1              = string.Empty;
                            lab_OldItem1.Text      = "(未測驗)";
                            lab_OldItemScore1.Text = "(未測驗)";
                        }

                        //項次2
                        if (!string.IsNullOrEmpty(dt.Rows[0]["push_ups_score"].ToString()))
                        {
                            ItemScore2     = dt.Rows[0]["push_ups_score"].ToString();
                            Old_ItemScore2 = ItemScore2;
                            if (ItemScore2 == "999")
                            {
                                lab_OldItem2.Text      = "(未完測)";
                                lab_OldItemScore2.Text = "(未完測)";
                            }
                            else
                            {
                                Old_ItemScore2         = ItemScore2;
                                txb_ItemScore2.Text    = ItemScore2;
                                lab_OldItemScore2.Text = "(" + Old_ItemScore2 + ")";
                            }
                            //項次2次/秒數
                            if (!string.IsNullOrEmpty(dt.Rows[0]["push_ups"].ToString()))
                            {
                                Item2             = dt.Rows[0]["push_ups"].ToString();
                                Old_Item2         = Item2;
                                txb_Item2.Text    = Item2;
                                lab_OldItem2.Text = "(" + Old_Item2 + ")";
                            }
                            else
                            {
                                Item2     = string.Empty;
                                Old_Item2 = string.Empty;
                            }
                        }
                        else
                        {
                            ItemScore2             = string.Empty;
                            Old_ItemScore2         = string.Empty;
                            Item2                  = string.Empty;
                            Old_Item2              = string.Empty;
                            lab_OldItem2.Text      = "(未測驗)";
                            lab_OldItemScore2.Text = "(未測驗)";
                        }
                        //項次3
                        if (!string.IsNullOrEmpty(dt.Rows[0]["run_score"].ToString()))
                        {
                            ItemScore3     = dt.Rows[0]["run_score"].ToString();
                            Old_ItemScore3 = ItemScore3;
                            if (ItemScore3 == "9999")
                            {
                                lab_OldItem3.Text      = "(未完測)";
                                lab_OldItemScore3.Text = "(未完測)";
                            }
                            else
                            {
                                Old_ItemScore3         = ItemScore3;
                                txb_ItemScore3.Text    = ItemScore3;
                                lab_OldItemScore3.Text = "(" + Old_ItemScore3 + ")";
                            }
                            //項次3次/秒數
                            if (!string.IsNullOrEmpty(dt.Rows[0]["run"].ToString()))
                            {
                                Item3             = dt.Rows[0]["run"].ToString();
                                Old_Item3         = Item3;
                                txb_Item3.Text    = Item3;
                                lab_OldItem3.Text = "(" + Old_Item3 + ")";
                            }
                            else
                            {
                                Item3     = string.Empty;
                                Old_Item3 = string.Empty;
                            }
                        }
                        else
                        {
                            ItemScore3             = string.Empty;
                            Old_ItemScore3         = string.Empty;
                            Item3                  = string.Empty;
                            Old_Item3              = string.Empty;
                            lab_OldItem3.Text      = "(未測驗)";
                            lab_OldItemScore3.Text = "(未測驗)";
                        }

                        //總評
                        if (!string.IsNullOrEmpty(dt.Rows[0]["status"].ToString()))
                        {
                            Status = dt.Rows[0]["status"].ToString();
                            if (Status == "202")
                            {
                                ddl_Status.SelectedIndex = 0;
                            }
                            else
                            {
                                ddl_Status.SelectedIndex = 1;
                            }
                            Old_Status         = Status;
                            lab_OldStatus.Text = (Status == "202") ? "(合格)" : "(不合格)";
                        }
                    }
                }
                else//提交資料後回傳
                {
                    Dictionary <string, object> d  = new Dictionary <string, object>();
                    Lib.DataUtility             du = new Lib.DataUtility();
                    Name  = txb_Name.Text.Trim();
                    Birth = txb_Birth.Text.Trim();
                    Age   = txb_Age.Text.Trim();
                    d.Add("sid", Sid);
                    d.Add("name", Name);
                    d.Add("birth", Birth);
                    d.Add("age", Age);
                    //項次1次/秒數
                    if (!string.IsNullOrEmpty(txb_Item1.Text))
                    {
                        Item1 = txb_Item1.Text.Trim();
                        d.Add("sit_ups", Item1);
                    }
                    else
                    {
                        Item1 = string.Empty;
                        d.Add("sit_ups", DBNull.Value);
                    }
                    //項次1成績
                    if (!string.IsNullOrEmpty(txb_ItemScore1.Text))
                    {
                        ItemScore1 = txb_ItemScore1.Text.Trim();
                        d.Add("sit_ups_score", ItemScore1);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Old_ItemScore1) && Old_ItemScore3 == "999")
                        {
                            ItemScore1 = Old_ItemScore1;
                            d.Add("sit_ups_score", ItemScore1);
                        }
                        else
                        {
                            ItemScore1 = string.Empty;
                            d.Add("sit_ups_score", DBNull.Value);
                        }
                    }
                    //項次2次/秒數
                    if (!string.IsNullOrEmpty(txb_Item2.Text))
                    {
                        Item2 = txb_Item2.Text.Trim();
                        d.Add("push_ups", Item2);
                    }
                    else
                    {
                        Item2 = string.Empty;
                        d.Add("push_ups", DBNull.Value);
                    }
                    //項次2成績
                    if (!string.IsNullOrEmpty(txb_ItemScore2.Text))
                    {
                        ItemScore2 = txb_ItemScore2.Text.Trim();
                        d.Add("push_ups_score", ItemScore2);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Old_ItemScore2) && Old_ItemScore2 == "999")
                        {
                            ItemScore2 = Old_ItemScore2;
                            d.Add("push_ups_score", ItemScore2);
                        }
                        else
                        {
                            ItemScore2 = string.Empty;
                            d.Add("push_ups_score", DBNull.Value);
                        }
                    }
                    //項次3次/秒數
                    if (!string.IsNullOrEmpty(txb_Item3.Text))
                    {
                        Item3 = txb_Item3.Text.Trim();
                        d.Add("run", Item3);
                    }
                    else
                    {
                        Item3 = string.Empty;
                        d.Add("run", DBNull.Value);
                    }
                    //項次3成績
                    if (!string.IsNullOrEmpty(txb_ItemScore3.Text))
                    {
                        ItemScore3 = txb_ItemScore3.Text.Trim();
                        d.Add("run_score", ItemScore3);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(Old_ItemScore3) && Old_ItemScore3 == "9999")
                        {
                            ItemScore3 = Old_ItemScore3;
                            d.Add("run_score", ItemScore3);
                        }
                        else
                        {
                            ItemScore3 = string.Empty;
                            d.Add("run_score", DBNull.Value);
                        }
                    }
                    //總評
                    if (ddl_Status.SelectedIndex == 0)
                    {
                        Status = "202";
                    }
                    else if (ddl_Status.SelectedIndex == 1)
                    {
                        Status = "203";
                    }
                    else
                    {
                        Status = Old_Status;
                    }
                    d.Add("status", Status);

                    try
                    {
                        //更新資料
                        du.executeNonQueryBysp("Ex108_UpdateResultData", d);
                        //寫入log
                        UpdateLog = string.Empty;
                        if (!string.IsNullOrEmpty(Sid))
                        {
                            UpdateLog += "sid-" + Sid + ',';
                        }
                        if (!string.IsNullOrEmpty(Id))
                        {
                            UpdateLog += "id-" + Id + ',';
                        }
                        if (Old_Name != Name)
                        {
                            UpdateLog += "名[" + Old_Name + "," + Name + "]";
                        }
                        if (Old_Birth != Birth)
                        {
                            UpdateLog += "生[" + Old_Birth + "," + Birth + "]";
                        }
                        if (Old_Age != Age)
                        {
                            UpdateLog += "歲[" + Old_Age + "," + Age + "]";
                        }
                        UpdateLog += "項1[" + Old_ItemScore1 + "," + ItemScore1 + "]項2[" + Old_ItemScore2 + "," + ItemScore2 + "]項3[" + Old_ItemScore3 + "," + ItemScore3 + "]總[" + ((Old_Status == "202") ? "合格" : "不合格") + "," + ((Status == "202") ? "合格" : "不合格") + "]";
                        SysSetting.AddLog("成績補正", a.AccountName, UpdateLog, DateTime.Now);
                        //回傳成功
                        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside_r('ok');window.close()", true);
                    }
                    catch (Exception ex)
                    {
                        //記錄錯誤訊息
                        SysSetting.ExceptionLog(ex.GetType().ToString(), ex.Message, this.ToString());
                        //回傳失敗
                        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside_r('Err');window.close()", true);
                    }
                }
            }
        }
        if (Session["account"] == null && Session["player"] == null)
        {
            Response.Redirect("~/Login.aspx");
        }
    }
예제 #4
0
    protected void submit_Click(object sender, EventArgs e)
    {
        try
        {
            if (loginType.SelectedValue == "advance")
            {
                Account a = new Account(txtName.Text.Trim(), txtPwd.Text.Trim(), Request.UserHostAddress.ToString());

                // 2010/01/19 edit by angus
                if (a.IsValid)
                {
                    if (a.IsIPLock)
                    {
                        Session["account"] = a;
                        SysSetting.AddLog("登入", a.AccountName, "進階使用者登入成功,登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
                        Response.Redirect("~/Index.aspx", false);
                    }
                    else
                    {
                        SysSetting.AddLog("登入", txtName.Text, "進階使用者登入IP錯誤,登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('登入之電腦IP錯誤 !!!')", true);
                    }
                }
                else
                {
                    txtPwd.Text = "";
                    SysSetting.AddLog("登入", txtName.Text, "進階使用者登入密碼驗證失敗,登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('帳號密碼驗證失敗 !!!')", true);
                }
            }
            else if (loginType.SelectedValue == "user")
            {
                Lib.Player player = new Player(txtName.Text.Trim(), txtPwd.Text.Trim(), "password");
                if (player.IsExist)
                {
                    if (player.IsValid)
                    {
                        Session["player"] = player;
                        Lib.SysSetting.AddLog("登入", player.ID, "一般受測人員登入成功,登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
                        //Response.Redirect("~/Index.aspx",false);
                        if (player.IsMustReSetPassword == false)
                        {
                            Response.Redirect("~/Index.aspx", false);
                        }
                        else
                        {
                            Response.Redirect("~/NewPassword.aspx", false);
                        }
                    }
                    if (!player.IsValid)
                    {
                        txtPwd.Text = "";
                        Lib.SysSetting.AddLog("登入", txtName.Text, "一般受測人員登入失敗,帳號密碼錯誤,登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('身分證字號或生日錯誤');", true);
                    }
                }
                if (!player.IsExist)
                {
                    txtName.Text = "";
                    txtPwd.Text  = "";
                    Lib.SysSetting.AddLog("登入", txtName.Text, "一般受測人員登入失敗,帳號不存在,登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('您輸入的帳號不存在');", true);
                }
            }
        }
        catch (Exception ex)
        {
            Lib.SysSetting.ExceptionLog(ex.GetType().ToString(), ex.Message, this.ToString());
            Lib.SysSetting.AddLog("登入", "system", ex.Message + "登入IP : " + Request.UserHostAddress.ToString(), DateTime.Now);
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('資料輸入錯誤');", true);
        }
    }
예제 #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["account"] != null)
     {
         Account a = (Account)Session["account"];
         if (a.Role != ((int)SysSetting.Role.admin_hq).ToString())
         {
             Response.Redirect("~/index.aspx");
         }
         else
         {
             Sid = Request.QueryString["sid"].ToString();
             if (Page.IsPostBack == false)//剛開始載入頁面
             {
                 Dictionary <string, object> d  = new Dictionary <string, object>();
                 Lib.DataUtility             du = new Lib.DataUtility();
                 d.Add("value", Sid);
                 d.Add("type", "sid");
                 DataTable dt = du.getDataTableBysp("Ex108_GetPlayerData", d);
                 if (dt.Rows.Count > 0)
                 {
                     if (!string.IsNullOrEmpty(dt.Rows[0]["name"].ToString()))
                     {
                         Name             = dt.Rows[0]["name"].ToString();
                         txb_Name.Text    = Name;
                         Old_Name         = Name;
                         lab_OldName.Text = "(" + Old_Name + ")";
                     }
                     if (!string.IsNullOrEmpty(dt.Rows[0]["id"].ToString()))
                     {
                         Id             = dt.Rows[0]["id"].ToString();
                         txb_Id.Text    = Id;
                         Old_Id         = Id;
                         lab_OldId.Text = "(" + Old_Id + ")";
                     }
                     if (!string.IsNullOrEmpty(dt.Rows[0]["birth"].ToString()))
                     {
                         Birth             = dt.Rows[0]["birth"].ToString();
                         txb_Birth.Text    = Birth;
                         Old_Birth         = Birth;
                         lab_OldBirth.Text = "(" + Old_Birth + ")";
                     }
                     if (!string.IsNullOrEmpty(dt.Rows[0]["mail"].ToString()))
                     {
                         Mail             = dt.Rows[0]["mail"].ToString();
                         txb_Mail.Text    = Mail;
                         Old_Mail         = Mail;
                         lab_OldMail.Text = "(" + Old_Mail + ")";
                     }
                     if (!string.IsNullOrEmpty(dt.Rows[0]["password"].ToString()))
                     {
                         Password             = dt.Rows[0]["password"].ToString();
                         txb_Password.Text    = Password;
                         Old_Password         = Password;
                         lab_OldPassword.Text = "(" + Old_Password + ")";
                     }
                 }
             }
             else//提交資料後回傳
             {
                 Dictionary <string, object> d  = new Dictionary <string, object>();
                 Lib.DataUtility             du = new Lib.DataUtility();
                 Name  = txb_Name.Text;
                 Id    = txb_Id.Text.Trim();
                 Birth = txb_Birth.Text.Trim();
                 Mail  = txb_Mail.Text.Trim();
                 d.Add("sid", Sid);
                 d.Add("name", Name);
                 d.Add("id", Id);
                 d.Add("birth", Birth);
                 d.Add("mail", Mail);
                 d.Add("password", Password);
                 try
                 {
                     //更新資料
                     du.executeNonQueryBysp("Ex108_UpdatePlayerData", d);
                     //寫入log
                     UpdateLog = string.Empty;
                     if (!string.IsNullOrEmpty(Sid))
                     {
                         UpdateLog += "sid-" + Sid + ",";
                     }
                     if (Old_Name != Name)
                     {
                         UpdateLog += "名[" + Old_Name + "," + Name + "]";
                     }
                     if (Old_Id != Id)
                     {
                         UpdateLog += "證[" + Old_Id + "," + Id + "]";
                     }
                     if (Old_Birth != Birth)
                     {
                         UpdateLog += "生[" + Old_Birth + "," + Birth + "]";
                     }
                     if (Old_Mail != Mail)
                     {
                         UpdateLog += "郵[" + Old_Mail + "," + Mail + "]";
                     }
                     if (Old_Password != Password)
                     {
                         UpdateLog += "密[" + Old_Password + "," + Password + "]";
                     }
                     if (!string.IsNullOrEmpty(UpdateLog))
                     {
                         SysSetting.AddLog("基本資料異動", a.AccountName, UpdateLog, DateTime.Now);
                     }
                     //回傳成功
                     ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside('" + Id + "');window.close()", true);
                 }
                 catch (Exception ex)
                 {
                     //記錄錯誤訊息
                     SysSetting.ExceptionLog(ex.GetType().ToString(), ex.Message, this.ToString());
                     //回傳失敗
                     ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "", "window.opener.outside('Err');window.close()", true);
                 }
             }
         }
     }
     if (Session["account"] == null && Session["player"] == null)
     {
         Response.Redirect("~/Login.aspx");
     }
 }