Example #1
0
        private void getSUMhour(string sqlstr, string sqlstr_1)
        {
            NDcommon dbobj = new NDcommon();

            using (SqlConnection comconn = dbobj.get_conn("Aitag_DBContext"))
            {
                ViewBag.otloghour = dbobj.get_dbvalue(comconn, sqlstr_1);
                using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                {
                    string txtosno = "", sqlstr_2 = "";
                    using (SqlCommand cmd = new SqlCommand(sqlstr, conn))
                    {
                        SqlDataReader dr = cmd.ExecuteReader();
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                txtosno += "'" + dbobj.get_dbnull2(dr["osno"]) + "',";
                            }
                            sqlstr_2 = "select isnull(sum(resthour),0) as resthour,isnull(sum(moneyhour),0) as moneyhour from resthourlog where osno in (" + txtosno.Substring(0, txtosno.Length - 1) + ") and comid='" + (string)Session["comid"] + "'";
                        }
                        else
                        {
                            sqlstr_2 = "select isnull(sum(resthour),0) as resthour,isnull(sum(moneyhour),0) as moneyhour from resthourlog where 1<>1";
                        }
                        dr.Close();
                    }
                    using (SqlCommand cmd = new SqlCommand(sqlstr_2, conn))
                    {
                        SqlDataReader dr = cmd.ExecuteReader();
                        if (dr.HasRows)
                        {
                            dr.Read();
                            ViewBag.sumresthour  = dbobj.get_dbnull2(dr["resthour"]);
                            ViewBag.summoneyhour = dbobj.get_dbnull2(dr["moneyhour"]);
                        }
                        else
                        {
                            ViewBag.sumresthour  = "0";
                            ViewBag.summoneyhour = "0";
                        }
                    }
                }
            }
        }
        private void logcheckEditMail(delholidaylog col, string tmprole)
        {
            NDcommon dbobj = new NDcommon();

            #region 寄給下一個承辦人
            string mailtitle = "", MailContext = "";
            mailtitle   = "【" + col.empname + "】出差單資料要求審核通知";
            MailContext = "<HTML><HEAD><meta http-equiv='Content-Type' content='text/html; charset=BIG5'></HEAD><body>";
            MailContext = MailContext + "以下為明細資料:<BR>";
            MailContext = MailContext + "<table cellpadding=3 cellspacing=0 bordercolorlight=#000000 bordercolordark=ffffff border=1 width=400 bgcolor=ffffff style='FONT-SIZE: 11pt;FONT-FAMILY:Tahoma,Arial'>";
            MailContext = MailContext + "<tr><td align=right width=130>請假單號:</td><td>" + col.hsno + "</td></tr>";
            MailContext = MailContext + "<tr><td align=right width=130>申請人:</td><td>" + col.empname + "</td></tr>";
            MailContext = MailContext + "<tr><td align=right width=130>假別:</td><td>" + Request["hdaytitle"] + "</td></tr>";

            string hlogsdate = dbobj.get_dbDate(col.hlogsdate, "yyyy/MM/dd");
            string hlogedate = dbobj.get_dbDate(col.hlogedate, "yyyy/MM/dd");
            string SEDate    = "自{0} ({1})<br>至{2} ({3})";
            SEDate      = string.Format(SEDate, hlogsdate, col.hlogstime, hlogedate, col.hlogetime);
            MailContext = MailContext + "<tr><td align=right width=130>日期起訖:</td><td>" + SEDate + "</td></tr>";
            MailContext = MailContext + "<tr><td align=right width=130>共計時數:</td><td>" + col.hloghour + "</td></tr>";

            if (dbobj.get_dbnull2(col.hlogcomment) != "")
            {
                MailContext = MailContext + "<tr><td align=right width=130>備註:</td><td>" + col.hlogcomment.ToString().Trim().Replace(Environment.NewLine, "<br>") + "</td></tr>";
            }
            else
            {
                MailContext = MailContext + "<tr><td align=right width=130>備註:</td><td>&nbsp;</td></tr>";
            }


            MailContext = MailContext + "</table>";
            MailContext = MailContext + "</body></HTML>";

            using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
            {
                tmprole = tmprole.Replace("'", "");
                string sql = "select enemail from viewemprole where rid = '" + tmprole + "' and empstatus <> '4' and enemail<>''";
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    SqlDataReader dr     = cmd.ExecuteReader();
                    string        tomail = "";
                    while (dr.Read())
                    {
                        tomail += dr["enemail"] + ",";
                    }
                    dbobj.send_mailfile("", tomail, mailtitle, MailContext, null, null);

                    dr.Close();
                }
            }
            #endregion
        }
        private void logcheckEditMailBack(delholidaylog col)
        {
            NDcommon dbobj = new NDcommon();

            #region 寄送mail給申請人
            using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
            {
                string fromadd = "", fromaddname = "", toadd = "";
                fromadd     = dbobj.get_dbvalue(conn, "select enemail from employee where empid='" + Request["empid"] + "'");
                fromaddname = dbobj.get_dbvalue(conn, "select empname from employee where empid='" + Request["empid"] + "'");
                toadd       = dbobj.get_dbvalue(conn, "select enemail from employee where empid='" + col.empid + "'");
                string mailtitle = "", MailContext = "";
                mailtitle   = "銷假單資料退回";
                MailContext = "<HTML><HEAD><meta http-equiv='Content-Type' content='text/html; charset=BIG5'></HEAD><body>";
                MailContext = MailContext + "以下為明細資料:<BR>";
                MailContext = MailContext + "<table cellpadding=3 cellspacing=0 bordercolorlight=#000000 bordercolordark=ffffff border=1 width=400 bgcolor=ffffff style='FONT-SIZE: 11pt;FONT-FAMILY:Tahoma,Arial'>";
                MailContext = MailContext + "<tr><td align=right width=130>請假單號:</td><td>" + col.hsno + "</td></tr>";
                MailContext = MailContext + "<tr><td align=right width=130>申請人:</td><td>" + col.empname + "</td></tr>";
                MailContext = MailContext + "<tr><td align=right width=130>假別:</td><td>" + Request["hdaytitle"] + "</td></tr>";

                string hlogsdate = dbobj.get_dbDate(col.hlogsdate, "yyyy/MM/dd");
                string hlogedate = dbobj.get_dbDate(col.hlogedate, "yyyy/MM/dd");
                string SEDate    = "自{0} ({1})<br>至{2} ({3})";
                SEDate      = string.Format(SEDate, hlogsdate, col.hlogstime, hlogedate, col.hlogetime);
                MailContext = MailContext + "<tr><td align=right width=130>日期起訖:</td><td>" + SEDate + "</td></tr>";
                MailContext = MailContext + "<tr><td align=right width=130>共計時數:</td><td>" + col.hloghour + "</td></tr>";

                if (dbobj.get_dbnull2(col.hlogcomment) != "")
                {
                    MailContext = MailContext + "<tr><td align=right width=130>備註:</td><td>" + col.hlogcomment.ToString().Trim().Replace(Environment.NewLine, "<br>") + "</td></tr>";
                }
                else
                {
                    MailContext = MailContext + "<tr><td align=right width=130>備註:</td><td>&nbsp;</td></tr>";
                }


                MailContext = MailContext + "</table>";
                MailContext = MailContext + "</body></HTML>";

                dbobj.send_mailfile("", toadd, mailtitle, MailContext, null, null);
            }
            #endregion
        }
Example #4
0
        public ActionResult otworklogrpt(int?page, string orderdata, string orderdata1)
        {
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "otlogsdate";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qotstatus = "", qempname = "", qdptid = "", otlogsdate = "", otlogedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qotstatus"]))
            {
                qotstatus         = Request["qotstatus"].Trim();
                ViewBag.qotstatus = qotstatus;
            }
            else
            {
                qotstatus         = "1";
                ViewBag.qotstatus = qotstatus;
            }
            if (!string.IsNullOrWhiteSpace(Request["qempname"]))
            {
                qempname         = Request["qempname"].Trim();
                ViewBag.qempname = qempname;
            }
            if (!string.IsNullOrWhiteSpace(Request["qdptid"]))
            {
                qdptid         = Request["qdptid"].Trim();
                ViewBag.qdptid = qdptid;
            }
            otlogsdate         = NullStDate(Request["otlogsdate"]);
            ViewBag.otlogsdate = otlogsdate;
            otlogedate         = NullTeDate(Request["otlogedate"]);
            ViewBag.otlogedate = otlogedate;
            //NullStDate 跟 NullTeDate 會判斷格式,有錯誤就 修改全域的DateEx
            if (DateEx != "")
            {
                ViewBag.DateEx = @"<script>alert(""" + DateEx + @""");</script>";
            }
            NDcommon dbobj = new NDcommon();
            string   Excel = "", Excel2 = "";
            string   sqlstr = "", sqlstr_1 = "";

            using (Aitag_DBContext con = new Aitag_DBContext())
            {
                string   viewid = "";
                string[] mpriv  = (string[])Session["priv"];
                //viewid = get_viewpriv(int.Parse(funcpriv(2)), int.Parse(mpriv(realsid, 2)));
                string tmpall = "";
                //tmpall = dbobj.get_allempid((string)Session["rid"]);
                tmpall = "%";


                if (tmpall == "%")
                {
                    sqlstr   = "SELECT * FROM otworklog where comid='" + (string)Session["comid"] + "'  and";
                    sqlstr_1 = "SELECT isnull(sum(otloghour),0) as otloghour FROM otworklog where comid='" + (string)Session["comid"] + "'  and";
                }
                else
                {
                    sqlstr   = "SELECT * FROM otworklog where empid in(" + tmpall + ") and comid='" + (string)Session["comid"] + "'  and";
                    sqlstr_1 = "SELECT isnull(sum(otloghour),0) as otloghour FROM otworklog where empid in(" + tmpall + ") and comid='" + (string)Session["comid"] + "'  and";
                }

                if (qotstatus != "all")
                {
                    string sql_otstatus = " otstatus like '" + qotstatus + "'  and";
                    sqlstr   = sqlstr + sql_otstatus;
                    sqlstr_1 = sqlstr_1 + sql_otstatus;
                }
                if (otlogsdate != "" && otlogedate != "")
                {
                    string sql_date = " (( '" + otlogsdate + "' <= otlogsdate and otlogsdate <= '" + otlogedate + "' ) or " +
                                      "( '" + otlogsdate + "' <= otlogedate and otlogedate <= '" + otlogedate + "'  ))  and";
                    sqlstr   = sqlstr + sql_date;
                    sqlstr_1 = sqlstr_1 + sql_date;
                }
                if (qempname != "")
                {
                    string sql_empname = " empname like N'%" + qempname + "%'  and";
                    sqlstr   = sqlstr + sql_empname;
                    sqlstr_1 = sqlstr_1 + sql_empname;
                }
                if (qdptid != "")
                {
                    string sql_dptid = " dptid='" + qdptid + "'  and";
                    sqlstr   = sqlstr + sql_dptid;
                    sqlstr_1 = sqlstr_1 + sql_dptid;
                }


                sqlstr   = sqlstr.Substring(0, sqlstr.Length - 5);
                sqlstr_1 = sqlstr_1.Substring(0, sqlstr_1.Length - 5);
                getSUMhour(sqlstr, sqlstr_1);
                sqlstr += " order by " + orderdata + " " + orderdata1;
            }
            #region 組 Excel 格式
            Excel += "<HTML>";
            Excel += "<HEAD>";
            Excel += @"<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">";
            Excel += "</HEAD>";
            Excel += "<body>";
            Excel += "<table  border=1  cellpadding=0 cellspacing=0 bordercolor=#000000 bordercolordark=#ffffff width=900 >";
            Excel += "<tr align=center>";
            Excel += @"<td colspan=""9"" style=""font-size:14pt"">加班明細表";
            Excel += "</td>";
            Excel += "</tr>";
            Excel += "<tr align=center>";
            int count = 8;
            Excel += "<td colspan='" + count + "' ></td><td>列印日期:" + DateTime.Now.ToString("yyyy/MM/dd") + "</td>";
            Excel += "</tr>";
            Excel += "<tr align=center>";
            Excel += "<td>狀態</td>";
            Excel += "<td>核銷</td>";
            Excel += "<td>員工編號</td>";
            Excel += "<td>姓名</td>";
            Excel += "<td>部門</td>";
            Excel += "<td>加班起迄日期</td>";
            Excel += "<td>加班時數</td>";
            Excel += "<td>補休時數</td>";
            Excel += "<td>請款時數</td>";
            Excel += "</tr>";
            using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
            {
                using (SqlCommand cmd = new SqlCommand(sqlstr, conn))
                {
                    SqlDataReader dr = cmd.ExecuteReader();

                    string blogstatus = "", ifhdell = "", empno = "", dpttitle = "";
                    string SEtime = "自{0}({1}時)<br>至{2}({3}時)";
                    string blogsdate = "", blogstime = "", blogedate = "", blogetime = "";
                    string resthour = "", moneyhour = "", sql = "";

                    while (dr.Read())
                    {
                        blogstatus = dbobj.get_dbnull2(dr["otstatus"]);
                        switch (blogstatus)
                        {
                        case "0":
                            blogstatus = "簽核中";
                            break;

                        case "1":
                            blogstatus = "已核准";
                            break;

                        case "2":
                            blogstatus = "退回";
                            break;

                        case "D":
                            blogstatus = "撤回";
                            break;

                        default:
                            break;
                        }
                        ifhdell = dbobj.get_dbnull2(dr["ifotdell"]);
                        if (ifhdell == "y")
                        {
                            ifhdell = "是";
                        }
                        else if (ifhdell == "n")
                        {
                            ifhdell = "否";
                        }
                        blogsdate = Convert.ToDateTime(dbobj.get_dbnull2(dr["otlogsdate"])).ToString("yyyy/MM/dd");
                        blogstime = int.Parse(dbobj.get_dbnull2(dr["otlogstime"])).ToString("00");
                        blogedate = Convert.ToDateTime(dbobj.get_dbnull2(dr["otlogedate"])).ToString("yyyy/MM/dd");
                        blogetime = int.Parse(dbobj.get_dbnull2(dr["otlogetime"])).ToString("00");

                        using (SqlConnection comconn = dbobj.get_conn("Aitag_DBContext"))
                        {
                            empno    = "select empno from employee where empid='" + dbobj.get_dbnull2(dr["empid"]) + "'"; empno = dbobj.get_dbvalue(comconn, empno);
                            dpttitle = "select dpttitle from Department where dptid='" + dbobj.get_dbnull2(dr["dptid"]) + "' and comid='" + (string)Session["comid"] + "'"; dpttitle = dbobj.get_dbvalue(comconn, dpttitle);
                            sql      = "select * from resthourlog where osno = '" + dbobj.get_dbnull2(dbobj.get_dbnull2(dr["osno"])) + "' and comid='" + (string)Session["comid"] + "'";
                            using (SqlCommand cmd1 = new SqlCommand(sql, comconn))
                            {
                                SqlDataReader dr1 = cmd1.ExecuteReader();
                                if (dr1.HasRows)
                                {
                                    dr1.Read();
                                    resthour  = dbobj.get_dbnull2(dr1["resthour"]);
                                    moneyhour = dbobj.get_dbnull2(dr1["moneyhour"]);
                                }
                                else
                                {
                                    resthour  = "0";
                                    moneyhour = "0";
                                }
                                dr1.Close();
                            }
                        }


                        Excel2 += "<tr>";
                        Excel2 += "<td>" + blogstatus + "</td>";
                        Excel2 += "<td>" + ifhdell + "</td>";
                        Excel2 += "<td>" + empno + "</td>";
                        Excel2 += "<td>" + dbobj.get_dbnull2(dr["empname"]) + "</td>";
                        Excel2 += "<td>" + dpttitle + "</td>";
                        Excel2 += "<td>" + String.Format(SEtime, blogsdate, blogstime, blogedate, blogetime) + "</td>";
                        Excel2 += "<td>" + dbobj.get_dbnull2(dr["otloghour"]) + "</td>";
                        Excel2 += "<td>" + resthour + "</td>";
                        Excel2 += "<td>" + moneyhour + "</td>";
                        Excel2 += "</tr>";
                    }
                    if (Excel2 == "")
                    {
                        Excel += "<tr align=left><td colspan=6>目前沒有資料</td></tr>";
                    }
                    else
                    {
                        Excel2 += "<tr>";
                        Excel2 += "<td>總計</td>";
                        Excel2 += "<td>&nbsp;</td>";
                        Excel2 += "<td>&nbsp;</td>";
                        Excel2 += "<td>&nbsp;</td>";
                        Excel2 += "<td>&nbsp;</td>";
                        Excel2 += "<td>&nbsp;</td>";
                        Excel2 += "<td>" + ViewBag.otloghour + "</td>";
                        Excel2 += "<td>" + ViewBag.sumresthour + "</td>";
                        Excel2 += "<td>" + ViewBag.summoneyhour + "</td>";
                        Excel2 += "</tr>";
                        Excel  += Excel2;
                    }
                    dr.Close();
                }
            }
            Excel        += "</table>";
            Excel        += "</body>";
            Excel        += "</HTML>";
            ViewBag.Excel = Excel;
            #endregion

            return(View());
        }
        public ActionResult DeleteConfirmed(string id, int?page)
        {
            page = ((!page.HasValue || page < 1) ? 1 : page);
            string orderdata = "", orderdata1 = "";

            if (!string.IsNullOrWhiteSpace(Request["orderdata"]))
            {
                orderdata = Request["orderdata"].Trim();
            }
            if (!string.IsNullOrWhiteSpace(Request["orderdata1"]))
            {
                orderdata1 = Request["orderdata1"].Trim();
            }

            string qotstatus = "", qempname = "", qdptid = "", otlogsdate = "", otlogedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qotstatus"]))
            {
                qotstatus         = Request["qotstatus"].Trim();
                ViewBag.qotstatus = qotstatus;
            }
            if (!string.IsNullOrWhiteSpace(Request["qempname"]))
            {
                qempname         = Request["qempname"].Trim();
                ViewBag.qempname = qempname;
            }
            if (!string.IsNullOrWhiteSpace(Request["qdptid"]))
            {
                qdptid         = Request["qdptid"].Trim();
                ViewBag.qdptid = qdptid;
            }
            if (!string.IsNullOrWhiteSpace(Request["otlogsdate"]))
            {
                otlogsdate         = Request["otlogsdate"].Trim();
                ViewBag.otlogsdate = otlogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["otlogedate"]))
            {
                otlogedate         = Request["otlogedate"].Trim();
                ViewBag.otlogedate = otlogedate;
            }


            string tmpform = "";

            tmpform  = "<body onload=qfr1.submit();>";
            tmpform += "<form name='qfr1' action='/otworklog/List' method='post'>";
            tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
            tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
            tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";


            tmpform += "<input type=hidden id='qotstatus' name='qotstatus' value='" + qotstatus + "'>";
            tmpform += "<input type=hidden id='qempname' name='qempname' value='" + qempname + "'>";
            tmpform += "<input type=hidden id='qdptid' name='qdptid' value='" + qdptid + "'>";
            tmpform += "<input type=hidden id='otlogsdate' name='otlogsdate' value='" + otlogsdate + "'>";
            tmpform += "<input type=hidden id='otlogedate' name='otlogedate' value='" + otlogedate + "'>";

            tmpform += "</form>";
            tmpform += "</body>";

            string cdel = Request["cdel"];

            if (string.IsNullOrWhiteSpace(cdel))
            {
                return(new ContentResult()
                {
                    Content = @"<script>alert('請勾選要刪除的資料!!');</script>" + tmpform
                });
            }
            else
            {
                Int16  tmpcount   = 0;
                string tmpcomment = "";
                string sql        = "select * from otworklog";
                string sqlwhere   = " where otlogid in (" + cdel + ") and comid='" + (string)Session["comid"] + "'";
                sql += sqlwhere;
                NDcommon dbobj = new NDcommon();
                using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                {
                    using (SqlConnection comconn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            string xotlogstime = "", xotlogetime = "";
                            string otcomment = "", mailtitle = "", MailContext = "";
                            string fromadd = "", fromaddname = "", toadd = "";
                            string rolestampid = "", sql_m = "";
                            int    bloghour = 0;


                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.HasRows)
                            {
                                while (dr.Read())
                                {
                                    xotlogstime = "(" + dr["otlogstime"] + ")";
                                    xotlogetime = "(" + dr["otlogetime"] + ")";

                                    #region  寄信(通知給目前簽核角色)
                                    if (dbobj.get_dbnull2(dr["otcomment"]) != "")
                                    {
                                        otcomment = dbobj.get_dbnull2(dr["otcomment"]).Replace(Environment.NewLine, "<br>");
                                    }
                                    else
                                    {
                                        otcomment = "&nbsp;";
                                    }
                                    mailtitle = "加班確認單撤回通知";

                                    MailContext = "<HTML><HEAD><meta http-equiv='Content-Type' content='text/html; charset=BIG5'></HEAD><body>";
                                    MailContext = MailContext + "以下為明細資料:<BR>";
                                    MailContext = MailContext + "<table cellpadding=3 cellspacing=0 bordercolorlight=#000000 bordercolordark=ffffff border=1 width=400 bgcolor=ffffff style='FONT-SIZE: 11pt;FONT-FAMILY:Tahoma,Arial'>";
                                    MailContext = MailContext + "<tr><td align=right width=130>申請人:</td><td>" + dbobj.get_dbnull2(dr["empname"]) + "</td></tr>";
                                    MailContext = MailContext + "<tr><td align=right>起迄日期:</td><td>自 " + dbobj.get_dbnull2(dr["otlogsdate"]) + xotlogstime + "<BR>至 " + dbobj.get_dbnull2(dr["otlogedate"]) + xotlogetime + "</td></tr>";
                                    MailContext = MailContext + "<tr><td align=right>共計小時:</td><td>" + dbobj.get_dbnull2(dr["otloghour"]) + "時</td></tr>";
                                    MailContext = MailContext + "<tr><td align=right>事由:</td><td>" + otcomment + "+nbsp;</td></tr>";
                                    MailContext = MailContext + "</table>";
                                    MailContext = MailContext + "</body></HTML>";

                                    //寄件者
                                    fromadd     = dbobj.get_dbvalue(comconn, "select enemail from employee where empid='" + (string)Session["empid"] + "'");
                                    fromaddname = (string)Session["empname"];

                                    //'寄給申請人
                                    toadd = dbobj.get_dbvalue(comconn, "select enemail from employee where empid='" + dbobj.get_dbnull2(dr["empid"]) + "'");

                                    if (toadd != "")
                                    {
                                        //#include file=../inc/mail.asp
                                        dbobj.send_mail(mfrom, toadd, mailtitle, MailContext);
                                    }
                                    //收件者
                                    if (dbobj.get_dbnull2(dr["rolestampid"]) != "")
                                    {
                                        rolestampid = dbobj.get_dbnull2(dr["rolestampid"]);
                                        sql_m       = "select enemail from viewemprole where rid in (" + rolestampid + ") and empstatus <> '4' and enemail<>'' and comid='" + (string)Session["comid"] + "'";
                                        using (SqlCommand cmd2 = new SqlCommand(sql, conn))
                                        {
                                            SqlDataReader dr2 = cmd2.ExecuteReader();
                                            while (dr.Read())
                                            {
                                                toadd = dbobj.get_dbnull2(dr2["enemail"]);
                                                //#include file=../inc/mail.asp
                                                dbobj.send_mail(mfrom, toadd, mailtitle, MailContext);
                                            }
                                            dr.Close();
                                        }
                                    }
                                    #endregion

                                    sql  = "UPDATE otworklog SET otstatus = 'D'";
                                    sql += sqlwhere;
                                    sql += ";delete from resthourlog";
                                    sql += sqlwhere;
                                    dbobj.dbexecute("Aitag_DBContext", sql);


                                    tmpcount++;
                                    tmpcomment += "姓名:" + dbobj.get_dbnull2(dr["empname"]) + "申請單號:" + dbobj.get_dbnull2(dr["osno"]) + ",";
                                }
                                tmpcomment = tmpcomment.Substring(0, tmpcomment.Length - 1);
                            }


                            //系統LOG檔
                            string sysnote = tmpcomment + "的資料" + tmpcount + "筆";
                            if (sysnote.Length > 4000)
                            {
                                sysnote = sysnote.Substring(0, 4000);
                            }
                            //================================================= //
                            string        sysrealsid = Request["sysrealsid"].ToString();
                            SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                            string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2") + "(撤回)";
                            string        sysflag    = "D";
                            dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                            sysconn.Close();
                            sysconn.Dispose();
                            //======================================================
                            dr.Close();
                        }
                    }
                }

                return(new ContentResult()
                {
                    Content = @"<script>alert('刪除成功!!');</script>" + tmpform
                });
            }
        }
        public ActionResult logqryList(int?page, string orderdata, string orderdata1)
        {
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "hdellogid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;

            string qhdellogstatus = "", qhlogsdate = "", qhlogedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qhdellogstatus"]))
            {
                qhdellogstatus         = Request["qhdellogstatus"].Trim();
                ViewBag.qhdellogstatus = qhdellogstatus;
            }
            if (!string.IsNullOrWhiteSpace(Request["qhlogsdate"]))
            {
                qhlogsdate         = Request["qhlogsdate"].Trim();
                ViewBag.qhlogsdate = qhlogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qhlogedate"]))
            {
                qhlogedate         = Request["qhlogedate"].Trim();
                ViewBag.qhlogedate = qhlogedate;
            }

            NDcommon dbobj = new NDcommon();

            string DateEx = "", DateEx1 = "";

            if (dbobj.get_dbnull2(Request["qhlogsdate"]) != "")
            {
                dbobj.get_dateRang(Request["qhlogsdate"], "m", "min", @"出差日期起格式錯誤!!\n", out qhlogsdate, out DateEx);
                ViewBag.qhlogsdate = qhlogsdate;
            }
            if (dbobj.get_dbnull2(Request["qhlogedate"]) != "")
            {
                dbobj.get_dateRang(Request["qhlogedate"], "m", "max", @"出差日期訖格式錯誤!!\n", out qhlogedate, out DateEx1);
                ViewBag.qhlogedate = qhlogedate;
            }
            DateEx += DateEx1;

            if (DateEx != "")
            {
                ViewBag.DateEx = @"<script>alert(""" + DateEx + @""");</script>";
            }


            IPagedList <delholidaylog> result;

            using (Aitag_DBContext con = new Aitag_DBContext())
            {
                string sqlstr = "SELECT * FROM delholidaylog where 1=1 "
//                    + " and empid='" + (string)Session["empid"] + "'"
                                + " and comid='" + (string)Session["comid"] + "'";

                if (qhdellogstatus != "")
                {
                    sqlstr += " and hdellogstatus = '" + qhdellogstatus + "'";
                }
                if (qhlogsdate != "")
                {
                    sqlstr += " and hlogsdate >= '" + qhlogsdate + "'";
                }
                if (qhlogedate != "")
                {
                    sqlstr += " and hlogedate <= '" + qhlogedate + "'";
                }

                sqlstr += " order by " + orderdata + " " + orderdata1;

                var query = con.delholidaylog.SqlQuery(sqlstr).AsQueryable();

                result = query.ToPagedList <delholidaylog>(page.Value - 1, (int)Session["pagesize"]);
            }
            ViewBag.SetOrder_ch = SetOrder_ch1(orderdata, orderdata1);
            return(View(result));
        }
        public ActionResult logcheckList(int?page, string orderdata, string orderdata1)
        {
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "hdellogid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;

            string qhlogsdate = "", qhlogedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qhlogsdate"]))
            {
                qhlogsdate         = Request["qhlogsdate"].Trim();
                ViewBag.qhlogsdate = qhlogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qhlogedate"]))
            {
                qhlogedate         = Request["qhlogedate"].Trim();
                ViewBag.qhlogedate = qhlogedate;
            }

            NDcommon dbobj = new NDcommon();

            string DateEx = "", DateEx1 = "";

            if (dbobj.get_dbnull2(Request["qhlogsdate"]) != "")
            {
                dbobj.get_dateRang(Request["qhlogsdate"], "m", "min", @"出差日期起格式錯誤!!\n", out qhlogsdate, out DateEx);
                ViewBag.qhlogsdate = qhlogsdate;
            }
            if (dbobj.get_dbnull2(Request["qhlogedate"]) != "")
            {
                dbobj.get_dateRang(Request["qhlogedate"], "m", "max", @"出差日期訖格式錯誤!!\n", out qhlogedate, out DateEx1);
                ViewBag.qhlogedate = qhlogedate;
            }
            DateEx += DateEx1;

            if (DateEx != "")
            {
                ViewBag.DateEx = @"<script>alert(""" + DateEx + @""");</script>";
            }


            IPagedList <delholidaylog> result;

            using (Aitag_DBContext con = new Aitag_DBContext())
            {
                //多個角色時
                string tmpplay = (string)Session["mplayrole"];
                tmpplay = tmpplay.Replace("'", "");
                string[] tmpa  = tmpplay.Split(',');
                string   sql_1 = "";
                foreach (string s in tmpa)
                {
                    sql_1 += "'''" + s + "''',";
                }
                sql_1 = sql_1.Substring(0, sql_1.Length - 1);
                //====

                string sqlstr = "SELECT * FROM delholidaylog where hdellogstatus = '0'";

                if (sql_1 != "")
                {
                    sqlstr += " and rolestampid in (" + sql_1 + ")";
                }
                if (qhlogsdate != "")
                {
                    sqlstr += " and hlogsdate >= '" + qhlogsdate + "'";
                }
                if (qhlogedate != "")
                {
                    sqlstr += " and hlogedate <= '" + qhlogedate + "'";
                }

                sqlstr += " order by " + orderdata + " " + orderdata1;

                var query = con.delholidaylog.SqlQuery(sqlstr).AsQueryable();

                result = query.ToPagedList <delholidaylog>(page.Value - 1, (int)Session["pagesize"]);
            }
            ViewBag.SetOrder_ch = SetOrder_ch(orderdata, orderdata1);
            return(View(result));
        }
        public ActionResult logadd(delholidaylog col, string sysflag, int?page, string orderdata, string orderdata1, HttpPostedFileBase logopic1)
        {
            ModelState.Clear();
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "hdellogid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;


            if (sysflag != "A")
            {
                delholidaylog newcol = new delholidaylog();
                return(View(newcol));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(col));
                }
                else
                {
                    NDcommon dbobj = new NDcommon();
                    //簽核
                    string tmparolestampid = "";
                    if (dbobj.get_dbnull2(Request["arolestampid"]) != "")
                    {
                        tmparolestampid = "'" + Request["arolestampid"].ToString() + "'";
                    }
                    else
                    {
                        tmparolestampid = "'" + Request["arolestampid1"].ToString() + "'";
                    }

                    string tmpmoney = "0", tmprole = "", tmpbillid = "";
                    //找出下一個角色是誰
                    string impallstring = dbobj.getnewcheck1("H", tmparolestampid, tmparolestampid, Request["hloghour"], "", "");
                    tmprole   = impallstring.Split(';')[0].ToString();
                    tmpbillid = impallstring.Split(';')[1].ToString();
                    string errmsg = "";
                    if (tmprole == "")
                    {
                        errmsg         = "請先至表單流程設定中設定首長信箱的呈核流程!";
                        ViewBag.errmsg = "<script>alert('" + errmsg + "');</script>";
                        return(View(col));
                    }
                    //簽核
                    //if ((string)Session["mplayrole"] == "")
                    //{
                    //    errmsg = "您並未設定呈核角色!";
                    //    ViewBag.errmsg = "<script>alert('" + errmsg + "');</script>";
                    //    return View(col);
                    //}


                    //'找單據編號(自動產生編號)
                    string tmpbsno = "select hdno from delholidaylog where year(cdate) = " + DateTime.Now.Year + " and month(cdate) = " + DateTime.Now.Month + "  and hdno is not null order by hdno desc";
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        tmpbsno = dbobj.get_dbvalue(conn, tmpbsno);
                    }

                    if (tmpbsno != "")
                    {
                        tmpbsno = tmpbsno.Substring(tmpbsno.Length - 3, 3);
                        tmpbsno = (int.Parse(tmpbsno) + 1).ToString("000");
                    }
                    else
                    {
                        tmpbsno = "001";
                    }
                    string tmpyear  = (DateTime.Now.Year - 1911).ToString();
                    string tmpmonth = DateTime.Now.Month.ToString("00");
                    tmpbsno = "A" + tmpyear + tmpmonth + tmpbsno;
                    //======


                    col.hdellogstatus = "0";
                    col.hdno          = tmpbsno;


                    //呈核人員
                    //======
                    if (dbobj.get_dbnull2(col.arolestampid) == "")
                    {
                        col.arolestampid = Request["arolestampid1"];
                    }
                    col.rolestampid    = tmprole;                      //'下個呈核角色
                    col.rolestampidall = tmparolestampid;              //'所有呈核角色
                    col.empstampidall  = "'" + Request["empid"] + "'"; //'所有人員帳號
                    col.billflowid     = int.Parse(tmpbillid);
                    //======

                    col.comid    = (string)Session["comid"];
                    col.bmodid   = (string)Session["empid"];
                    col.bmoddate = DateTime.Now;
                    col.deldate  = DateTime.Now;
                    col.billtime = DateTime.Now.ToString();

                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        con.delholidaylog.Add(col);
                        con.SaveChanges();
                    }



                    //    '寄信
                    //'======================
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        string fromadd = "", fromaddname = "", mailtitle = "", MailContext = "";
                        fromadd     = dbobj.get_dbvalue(conn, "select enemail from employee where empid='" + Request["empid"] + "'");
                        fromaddname = dbobj.get_dbvalue(conn, "select empname from employee where empid='" + Request["empid"] + "'");

                        //'寄送mail給下一個審核角色
                        #region 寄送mail給下一個審核角
                        mailtitle   = "銷假單資料要求簽核通知";
                        MailContext = "<HTML><HEAD><meta http-equiv='Content-Type' content='text/html; charset=BIG5'></HEAD><body>";
                        MailContext = MailContext + "以下為明細資料:<BR>";
                        MailContext = MailContext + "<table cellpadding=3 cellspacing=0 bordercolorlight=#000000 bordercolordark=ffffff border=1 width=400 bgcolor=ffffff style='FONT-SIZE: 11pt;FONT-FAMILY:Tahoma,Arial'>";
                        MailContext = MailContext + "<tr><td align=right width=130>申請單號:</td><td>" + tmpbsno + "</td></tr>";
                        MailContext = MailContext + "<tr><td align=right width=130>請假單號:</td><td>" + col.hsno + "</td></tr>";
                        MailContext = MailContext + "<tr><td align=right width=130>申請人:</td><td>" + col.empname + "</td></tr>";
                        MailContext = MailContext + "<tr><td align=right width=130>假別:</td><td>" + Request["hdaytitle"] + "</td></tr>";

                        string hlogsdate = dbobj.get_dbDate(col.hlogsdate, "yyyy/MM/dd");
                        string hlogedate = dbobj.get_dbDate(col.hlogedate, "yyyy/MM/dd");
                        string SEDate    = "自{0} ({1})<br>至{2} ({3})";
                        SEDate      = string.Format(SEDate, hlogsdate, col.hlogstime, hlogedate, col.hlogetime);
                        MailContext = MailContext + "<tr><td align=right width=130>日期起訖:</td><td>" + SEDate + "</td></tr>";

                        if (dbobj.get_dbnull2(col.hlogcomment) != "")
                        {
                            MailContext = MailContext + "<tr><td align=right width=130>備註:</td><td>" + col.hlogcomment.ToString().Trim().Replace(Environment.NewLine, "<br>") + "</td></tr>";
                        }
                        else
                        {
                            MailContext = MailContext + "<tr><td align=right width=130>備註:</td><td>&nbsp;</td></tr>";
                        }


                        MailContext = MailContext + "</table>";
                        MailContext = MailContext + "</body></HTML>";

                        string tmproleid = tmprole.Replace("'", "");
                        string sql       = "select enemail from viewemprole where rid = '" + tmproleid + "' and empstatus <> '4' and enemail<>''";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr     = cmd.ExecuteReader();
                            string        tomail = "";
                            while (dr.Read())
                            {
                                tomail += dr["enemail"] + ",";
                            }
                            dbobj.send_mailfile("", tomail, mailtitle, MailContext, null, null);

                            dr.Close();
                        }
                        #endregion
                    }


                    //系統LOG檔
                    string sysnote = "申請人:{0}<br>申請單號:{1}的資料";
                    sysnote = string.Format(sysnote, Request["empid"], tmpbsno);
                    if (sysnote.Length > 4000)
                    {
                        sysnote = sysnote.Substring(0, 4000);
                    }
                    //================================================= //
                    SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                    string        sysrealsid = Request["sysrealsid"].ToString();
                    string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                    dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                    sysconn.Close();
                    sysconn.Dispose();
                    //=================================================

                    string tmpform = "";
                    tmpform  = "<body onload=qfr1.submit();>";
                    tmpform += "<form name='qfr1' action='/delholiday/logcheckList' method='post'>";
                    //tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
                    //tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
                    //tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
                    //tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";
                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                }
            }
        }
        public ActionResult logcheckEdit(delholidaylog chks, string sysflag, int?page, string orderdata, string orderdata1, HttpPostedFileBase logopic1)
        {
            ModelState.Clear();
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "hdellogid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;

            string qhlogsdate = "", qhlogedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qhlogsdate"]))
            {
                qhlogsdate         = Request["qhlogsdate"].Trim();
                ViewBag.qhlogsdate = qhlogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qhlogedate"]))
            {
                qhlogedate         = Request["qhlogedate"].Trim();
                ViewBag.qhlogedate = qhlogedate;
            }

            if (sysflag != "E")
            {
                using (Aitag_DBContext con = new Aitag_DBContext())
                {
                    //var data = con.delholidaylog.Where(r => r.hdellogid == chks.hdellogid).FirstOrDefault();
                    delholidaylog edelholidaylogs = con.delholidaylog.Find(chks.hdellogid);
                    if (edelholidaylogs == null)
                    {
                        return(HttpNotFound());
                    }
                    return(View(edelholidaylogs));
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(chks));
                }
                else
                {
                    NDcommon      dbobj   = new NDcommon();
                    delholidaylog col     = new delholidaylog();
                    string        sysnote = "";
                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        col = con.delholidaylog.Find(chks.hdellogid);
                    }

                    string hdellogstatus = "";
                    if (dbobj.get_dbnull2(Request["hdellogstatus"]) == "1")
                    {
                        string tmprolestampid = col.rolestampid;
                        string rolea_1        = col.rolestampidall;
                        string roleall        = rolea_1 + "," + tmprolestampid; //'簽核過角色(多個)
                        string billflowid     = col.billflowid.ToString();

                        //找出下一個角色是誰
                        string tmprole = dbobj.getnewcheck1("H", tmprolestampid, roleall, "0", "", billflowid);

                        if (tmprole == "'topman'")
                        {
                            tmprole = "";
                        }
                        if (tmprole == "")
                        {
                            hdellogstatus = "1";// '己簽核
                        }
                        else
                        {
                            hdellogstatus = "0";
                            //'找往上呈核長管級數
                            //'==========================
                            string tmpflowlevel = "";
                            using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                            {
                                tmpflowlevel = dbobj.get_dbvalue(conn, "select billflow from flowlevel where bid=" + billflowid);
                            }
                            if (tmpflowlevel == "")
                            {
                                tmpflowlevel = "0";
                            }
                            string[] tmpa      = rolea_1.Split(',');
                            int      tmpacount = tmpa.Length;
                            if (int.Parse(tmpflowlevel) == (tmpacount + 1))
                            {
                                tmprole       = "";
                                hdellogstatus = "1"; // '己簽核
                            }
                            //'==========================
                        }

                        col.hdellogstatus  = hdellogstatus;
                        col.rolestampid    = tmprole;
                        col.rolestampidall = roleall;
                        col.empstampidall  = col.empstampidall + ",'" + (string)Session["empid"] + "'"; //'所有人員帳號
                        col.bmodid         = (string)Session["empid"];
                        col.bmoddate       = DateTime.Now;
                        col.billtime       = col.billtime + "," + DateTime.Now.ToString();

                        if (tmprole != "")
                        {
                            //寄信
                            logcheckEditMail(col, tmprole);
                        }
                        else
                        {
                            //(己通過)  寄信
                            logcheckEditMailPass(col);
                        }
                    }
                    else
                    {
                        col.hdellogstatus = "2";
                        col.delback       = chks.delback;
                        col.bmodid        = (string)Session["empid"];
                        col.bmoddate      = DateTime.Now;
                        //  col.billtime = col.billtime + "," + DateTime.Now.ToString();

                        //(己通過)  寄信
                        logcheckEditMailBack(col);
                    }

                    using (Aitag_DBContext con = new Aitag_DBContext())
                    {
                        con.Entry(col).State = EntityState.Modified;
                        con.SaveChanges();
                    }


                    if (hdellogstatus == "1")
                    {
                        //銷假時數補回
                        delholidayMode(col, hdellogstatus);
                    }



                    //系統LOG檔

                    if (sysnote.Length > 4000)
                    {
                        sysnote = sysnote.Substring(0, 4000);
                    }
                    ////================================================= //

                    SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                    string        sysrealsid = Request["sysrealsid"].ToString();
                    string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                    dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                    sysconn.Close();
                    sysconn.Dispose();
                    //=================================================

                    string tmpform = "";
                    tmpform  = "<body onload=qfr1.submit();>";
                    tmpform += "<form name='qfr1' action='/delholiday/logcheckList' method='post'>";
                    tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
                    tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
                    tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
                    tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";

                    tmpform += "<input type=hidden id='qhlogsdate' name='qhlogsdate' value='" + qhlogsdate + "'>";
                    tmpform += "<input type=hidden id='qhlogedate' name='qhlogedate' value='" + qhlogedate + "'>";

                    tmpform += "</form>";
                    tmpform += "</body>";

                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                }
            }
        }
Example #10
0
        public ActionResult cardbatch(string sysflag)
        {
            ModelState.Clear();

            string sid = "", realsid = "", yhid = "", carddate = "", ctype = "";

            if (!string.IsNullOrWhiteSpace(Request["sid"]))
            {
                sid         = Request["sid"].Trim();
                ViewBag.sid = sid;
            }
            if (!string.IsNullOrWhiteSpace(Request["realsid"]))
            {
                realsid         = Request["realsid"].Trim();
                ViewBag.realsid = realsid;
            }
            if (!string.IsNullOrWhiteSpace(Request["yhid"]))
            {
                yhid         = Request["yhid"].Trim();
                ViewBag.yhid = yhid;
            }
            if (!string.IsNullOrWhiteSpace(Request["carddate"]))
            {
                carddate         = Request["carddate"].Trim();
                ViewBag.carddate = DateTime.Parse(carddate);
            }
            if (!string.IsNullOrWhiteSpace(Request["ctype"]))
            {
                ctype         = Request["ctype"].Trim();
                ViewBag.ctype = ctype;
            }
            if (sysflag != "A")
            {
                return(View());
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                else
                {
                    NDcommon dbobj = new NDcommon();
                    //'取得這類人員的上下班時間
                    string ytstime = "", ydetime = "";
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        string sql = "select * from yearholiday where yhid = '" + yhid + "'";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.HasRows)
                            {
                                dr.Read();
                                ytstime = dbobj.get_dbnull2(dr["ytstime"]);
                                ydetime = dbobj.get_dbnull2(dr["ydetime"]);
                            }
                            dr.Close();
                        }
                    }
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        string sql = "select * from employee where empstatus in ('1','2') and yhid = '" + yhid + "'";
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr = cmd.ExecuteReader();

                            string clogtime = "";
                            if (ctype == "1")
                            {
                                clogtime = ytstime;
                            }
                            else
                            {
                                clogtime = ydetime;
                            }
                            var bmoddate = DateTime.Now;
                            while (dr.Read())
                            {
                                cardreallog col = new cardreallog();

                                col.empid    = dbobj.get_dbnull2(dr["empid"]);
                                col.empname  = dbobj.get_dbnull2(dr["empname"]);
                                col.dptid    = dbobj.get_dbnull2(dr["empworkdepid"]);
                                col.clogdate = ViewBag.carddate;
                                col.clogtime = clogtime;

                                col.comid    = Session["comid"].ToString();
                                col.bmodid   = Session["tempid"].ToString();
                                col.bmoddate = bmoddate;

                                using (Aitag_DBContext con = new Aitag_DBContext())
                                {
                                    con.cardreallog.Add(col);
                                    con.SaveChanges();
                                }
                            }
                            dr.Close();
                        }
                    }

                    //系統LOG檔 //================================================= //
                    SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                    string        sysrealsid = Request["sysrealsid"].ToString();
                    string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                    string        sysnote    = "班別代碼:" + yhid + "<br>產生日期:" + carddate + "的資料";
                    dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                    sysconn.Close();
                    sysconn.Dispose();
                    //=================================================

                    string tmpform = "";
                    tmpform += "<script>";
                    tmpform += "function SetParentOpener() {";
                    tmpform += "alert('刷卡資料批次產生成功!!');";
                    tmpform += "parent.opener.location.href='/cardreallog/List';";
                    tmpform += "window.close();";
                    tmpform += "}";
                    tmpform += "</script>";

                    tmpform += "<body onload=SetParentOpener();>";
                    tmpform += "</body>";
                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                }
            }
        }
Example #11
0
        public ActionResult chkEdit(sales_competition chks, string sysflag, int?page, string orderdata, string orderdata1)
        {
            ModelState.Clear();
            page         = ((!page.HasValue || page < 1) ? 1 : page);
            ViewBag.page = page;
            if (string.IsNullOrWhiteSpace(orderdata))
            {
                orderdata = "ccid";
            }

            if (string.IsNullOrWhiteSpace(orderdata1))
            {
                orderdata1 = "desc";
            }
            ViewBag.orderdata  = orderdata;
            ViewBag.orderdata1 = orderdata1;
            string qprodtitle = "", qcusttitlename = "";

            if (!string.IsNullOrWhiteSpace(Request["qprodtitle"]))
            {
                qprodtitle         = Request["qprodtitle"].Trim();
                ViewBag.qprodtitle = qprodtitle;
            }
            if (!string.IsNullOrWhiteSpace(Request["qcusttitlename"]))
            {
                qcusttitlename     = Request["qcusttitlename"].Trim();
                ViewBag.qprodtitle = qcusttitlename;
            }

            if (sysflag != "E")
            {
                using (AitagBill_DBContext con = new AitagBill_DBContext())
                {
                    var data = con.sales_competition.Where(r => r.ccid == chks.ccid).FirstOrDefault();

                    sales_competition competitionlogs = con.sales_competition.Find(chks.ccid);
                    if (competitionlogs == null)
                    {
                        return(HttpNotFound());
                    }
                    return(View(competitionlogs));
                }
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(chks));
                }
                else
                {
                    //string oldmsid = Request["oldmsid"];



                    NDcommon          dbobj = new NDcommon();
                    sales_competition col   = new sales_competition();
                    using (AitagBill_DBContext con = new AitagBill_DBContext())
                    {
                        col = con.sales_competition.Find(chks.ccid);
                    }

                    string sysnote = "";
                    if (dbobj.get_dbnull2(Request["slogstatus"]) == "1")
                    {
                        string tmprolestampid = col.rolestampid;
                        string rolea_1        = col.rolestampidall;
                        string roleall        = rolea_1 + "," + tmprolestampid; //'簽核過角色(多個)
                        string billflowid     = col.billflowid.ToString();

                        //找出下一個角色是誰
                        string tmprole = dbobj.getnewcheck1("G", tmprolestampid, roleall, "", "", billflowid);

                        if (tmprole == "'topman'")
                        {
                            tmprole = "";
                        }
                        string slogstatus = "";
                        if (tmprole == "")
                        {
                            slogstatus = "1";// '己簽核
                        }
                        else
                        {
                            slogstatus = "0";
                            //'找往上呈核長管級數
                            //'==========================
                            string tmpflowlevel = "";
                            using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                            {
                                tmpflowlevel = dbobj.get_dbvalue(conn, "select billflow from flowlevel where bid=" + billflowid);
                            }
                            if (tmpflowlevel == "")
                            {
                                tmpflowlevel = "0";
                            }
                            string[] tmpa      = rolea_1.Split(',');
                            int      tmpacount = tmpa.Length;
                            if (int.Parse(tmpflowlevel) == (tmpacount + 1))
                            {
                                tmprole    = "";
                                slogstatus = "1"; // '己簽核
                            }
                            //'==========================
                        }

                        col.slogstatus     = slogstatus;
                        col.rolestampid    = tmprole;
                        col.rolestampidall = roleall;
                        col.empstampidall  = col.empstampidall + ",'" + (string)Session["empid"] + "'"; //'所有人員帳號
                        col.bmodid         = (string)Session["empid"];
                        col.bmoddate       = DateTime.Now;
                        col.billtime       = col.billtime + "," + DateTime.Now.ToString();
                        col.lawcomment     = Request["lawcomment"].ToString();
                        col.fincomment     = Request["fincomment"].ToString();
                        if (tmprole != "")
                        {
                            //寄信
                            //holidaycheckmainEditMail(col, tmprole);
                        }
                        else
                        {
                            //沒有下一個承辦人  (己通過)
                            ////資料通過後 搬移到cardreallog
                            //battacheckmainEditMove(col);

                            //(己通過)  寄信
                            //holidaycheckmainEditMailPass(col);
                        }
                        sysnote = "請假單審核通過作業";
                    }
                    else
                    {
                        col.slogstatus = "2";
                        col.rback      = Request["hback1"].ToString();
                        col.bmodid     = (string)Session["empid"];
                        col.bmoddate   = DateTime.Now;
                        col.billtime   = col.billtime + "," + DateTime.Now.ToString();

                        ////資料通過後 搬移到cardreallog
                        //battacheckmainEditMove(col);

                        //(己通過)  寄信
                        //holidaycheckmainEditMailBack(col);
                        sysnote = "新業務及競業退回作業";
                    }

                    col.bmodid   = Session["tempid"].ToString();
                    col.bmoddate = DateTime.Now;

                    using (AitagBill_DBContext con = new AitagBill_DBContext())
                    {
                        con.Entry(col).State = EntityState.Modified;
                        con.SaveChanges();
                    }



                    //系統LOG檔
                    //================================================= //
                    SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                    string        sysrealsid = Request["sysrealsid"].ToString();
                    string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2");
                    //string sysnote = "承辦人:" + chks.empid + "產品名稱:" + chks.prodtitle;
                    dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                    sysconn.Close();
                    sysconn.Dispose();
                    //=================================================

                    string tmpform = "";
                    tmpform  = "<body onload=qfr1.submit();>";
                    tmpform += "<form name='qfr1' action='/sales_competition/chk' method='post'>";
                    tmpform += "<input type=hidden name='sysflag' id='sysflag' value='" + sysflag + "'>";
                    tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
                    tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
                    tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";
                    tmpform += "<input type=hidden id='qprodtitle' name='qprodtitle' value='" + qprodtitle + "'>";
                    tmpform += "<input type=hidden id='qcusttitlename' name='qcusttitlename' value='" + qcusttitlename + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";


                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                    //return RedirectToAction("List");
                }
            }
        }
Example #12
0
        public ActionResult battadatdo(string id, int?page)
        {
            page = ((!page.HasValue || page < 1) ? 1 : page);
            string orderdata = "", orderdata1 = "";

            if (!string.IsNullOrWhiteSpace(Request["orderdata"]))
            {
                orderdata = Request["orderdata"].Trim();
            }
            if (!string.IsNullOrWhiteSpace(Request["orderdata1"]))
            {
                orderdata1 = Request["orderdata1"].Trim();
            }

            string qblogstatus = "", qempname = "", qdptid = "", qblogsdate = "", qblogedate = "";

            if (!string.IsNullOrWhiteSpace(Request["qblogstatus"]))
            {
                qblogstatus         = Request["qblogstatus"].Trim();
                ViewBag.qblogstatus = qblogstatus;
            }
            if (!string.IsNullOrWhiteSpace(Request["qempname"]))
            {
                qempname         = Request["qempname"].Trim();
                ViewBag.qempname = qempname;
            }
            if (!string.IsNullOrWhiteSpace(Request["qdptid"]))
            {
                qdptid         = Request["qdptid"].Trim();
                ViewBag.qdptid = qdptid;
            }
            if (!string.IsNullOrWhiteSpace(Request["qblogsdate"]))
            {
                qblogsdate         = Request["qblogsdate"].Trim();
                ViewBag.qblogsdate = qblogsdate;
            }
            if (!string.IsNullOrWhiteSpace(Request["qblogedate"]))
            {
                qblogedate         = Request["qblogedate"].Trim();
                ViewBag.qblogedate = qblogedate;
            }


            string tmpform = "";

            tmpform  = "<body onload=qfr1.submit();>";
            tmpform += "<form name='qfr1' action='/battadata/List' method='post'>";
            tmpform += "<input type=hidden name='page' id='page' value='" + page + "'>";
            tmpform += "<input type=hidden name='orderdata' id='orderdata' value='" + orderdata + "'>";
            tmpform += "<input type=hidden name='orderdata1' id='orderdata1' value='" + orderdata1 + "'>";

            tmpform += "<input type=hidden id='qblogstatus' name='qblogstatus' value='" + qblogstatus + "'>";
            tmpform += "<input type=hidden id='qempname' name='qempname' value='" + qempname + "'>";
            tmpform += "<input type=hidden id='qdptid' name='qdptid' value='" + qdptid + "'>";
            tmpform += "<input type=hidden id='qblogsdate' name='qblogsdate' value='" + qblogsdate + "'>";
            tmpform += "<input type=hidden id='qblogedate' name='qblogedate' value='" + qblogedate + "'>";

            tmpform += "</form>";
            tmpform += "</body>";
            NDcommon dbobj = new NDcommon();

            string cdel = Request["cdel"];

            string sql = "", sqlwhere = "", tmpcomment = "";

            if (string.IsNullOrWhiteSpace(cdel))
            {
                if (dbobj.get_dbnull2(Request["blogid"]) != "")
                {
                    sql      = "select * from battalog";
                    sqlwhere = " where blogid=" + dbobj.get_dbnull2(Request["blogid"]) + " and comid='" + (string)Session["comid"] + "'";
                    sql     += sqlwhere;
                    dbobj.dbexecute("Aitag_DBContext", "UPDATE battalog ifhdell='y' " + sqlwhere);
                    using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.HasRows)
                            {
                                dr.Read();
                                //找是否己全部核銷了
                                sql = "select * from battalog where pbsno='" + dbobj.get_dbnull2(dr["pbsno"]) + "' and comid='" + (string)Session["comid"] + "' and ifhdell='n'";
                                using (SqlConnection conn1 = dbobj.get_conn("Aitag_DBContext"))
                                {
                                    using (SqlCommand cmd1 = new SqlCommand(sql, conn1))
                                    {
                                        SqlDataReader dr1 = cmd1.ExecuteReader();
                                        if (dr1.HasRows)
                                        {
                                            while (dr1.Read())
                                            {
                                                sql = "UPDATE battalog SET ifhdell='y' where bsno='" + dbobj.get_dbnull2(dr["pbsno"]) + "' and comid='" + (string)Session["comid"] + "'";
                                                dbobj.dbexecute("Aitag_DBContext", sql);
                                            }
                                        }
                                        dr1.Close();
                                    }
                                }

                                tmpcomment = "申請人:" + dbobj.get_dbnull2(dr["empname"]) + "<br>申請單號:" + dbobj.get_dbnull2(dr["bsno"]) + "的資料";
                            }
                            dr.Close();
                        }
                    }



                    return(new ContentResult()
                    {
                        Content = @"<script>alert('核銷成功!!');</script>" + tmpform
                    });
                }
                else
                {
                    return(new ContentResult()
                    {
                        Content = @"<script>alert('請選擇要核銷的資料。');</script>" + tmpform
                    });
                }
            }
            else
            {
                string chkdel  = cdel;
                Int16  mpcount = 0;
                tmpcomment = "";
                sql        = "select * from battalog";
                sqlwhere   = " where blogid in (" + chkdel + ") and comid='" + (string)Session["comid"] + "'";
                sql       += sqlwhere;
                using (SqlConnection conn = dbobj.get_conn("Aitag_DBContext"))
                {
                    using (SqlConnection comconn = dbobj.get_conn("Aitag_DBContext"))
                    {
                        using (SqlCommand cmd = new SqlCommand(sql, conn))
                        {
                            SqlDataReader dr = cmd.ExecuteReader();
                            if (dr.HasRows)
                            {
                                while (dr.Read())
                                {
                                    sql = "UPDATE battalog SET ifhdell='y' where blogid=" + dbobj.get_dbnull2(dr["blogid"]) + " and comid='" + (string)Session["comid"] + "'";
                                    dbobj.dbexecute("Aitag_DBContext", sql);

                                    //找是否己全部核銷了
                                    sql = "select * from battalog where pbsno='" + dbobj.get_dbnull2(dr["pbsno"]) + "' and comid='" + (string)Session["comid"] + "' and ifhdell='n'";
                                    using (SqlConnection conn1 = dbobj.get_conn("Aitag_DBContext"))
                                    {
                                        using (SqlCommand cmd1 = new SqlCommand(sql, conn1))
                                        {
                                            SqlDataReader dr1 = cmd1.ExecuteReader();
                                            if (dr1.HasRows)
                                            {
                                                while (dr1.Read())
                                                {
                                                    sql = "UPDATE battalog SET ifhdell='y' where bsno='" + dbobj.get_dbnull2(dr["pbsno"]) + "' and comid='" + (string)Session["comid"] + "'";
                                                    dbobj.dbexecute("Aitag_DBContext", sql);
                                                }
                                            }
                                            dr1.Close();
                                        }
                                    }



                                    mpcount++;
                                    tmpcomment += "姓名:" + dbobj.get_dbnull2(dr["empname"]) + ",申請單號:" + dbobj.get_dbnull2(dr["bsno"]) + "<br>";
                                }
                                tmpcomment  = tmpcomment.Substring(0, tmpcomment.Length - 4);
                                tmpcomment += "的資料" + mpcount + "筆";
                            }


                            //系統LOG檔
                            string sysnote = tmpcomment;
                            if (sysnote.Length > 4000)
                            {
                                sysnote.Substring(0, 4000);
                            }
                            //================================================= //
                            string        sysrealsid = Request["sysrealsid"].ToString();
                            SqlConnection sysconn    = dbobj.get_conn("Aitag_DBContext");
                            string        syssubname = dbobj.get_sysmenuname(sysconn, sysrealsid, "2") + "(核銷)";
                            string        sysflag    = "M";
                            dbobj.systemlog(sysconn, syssubname, sysnote, Session["tempid"].ToString(), Session["sldate"].ToString(), Session["sfip"].ToString(), sysflag);
                            sysconn.Close();
                            sysconn.Dispose();
                            //======================================================
                            dr.Close();
                        }
                    }
                }

                return(new ContentResult()
                {
                    Content = @"<script>alert('核銷成功!!');</script>" + tmpform
                });
            }
        }