Example #1
0
        //[HttpGet]
        //public ActionResult Add()
        //{
        //    ViewBag.Ifboss = Session["Ifboss"].ToString();
        //    ViewBag.Msid = Session["Msid"].ToString();
        //    sales_competition col = new sales_competition();
        //    return View(col);
        //}

        //[HttpPost]
        public ActionResult add(sales_competition col, 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 = "", qcusttitle = "";

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

            if (sysflag != "A")
            {
                sales_competition newcol = new sales_competition();
                return(View(newcol));
            }
            else
            {
                if (!ModelState.IsValid)
                {
                    return(View(col));
                }
                else
                {
                    Aitag.Models.NDcommon dbobj = new Aitag.Models.NDcommon();
                    SqlConnection         conn  = dbobj.get_conn("AitagBill_DBContext");
                    SqlDataReader         dr;
                    SqlCommand            sqlsmd = new SqlCommand();
                    sqlsmd.Connection = conn;
                    string sqlstr = "select * from sales_competition where 1<>1";
                    sqlsmd.CommandText = sqlstr;
                    dr = sqlsmd.ExecuteReader();

                    if (dr.Read())
                    {
                        ModelState.AddModelError("", "簡易代碼重複!");
                        return(View(col));
                    }
                    dr.Close();
                    dr.Dispose();
                    sqlsmd.Dispose();
                    conn.Close();
                    conn.Dispose();

                    //找出下一個呈核角色
                    #region 找出下一個呈核角色
                    string tmparolestampid = "";
                    string tmprole         = "";
                    string tmpbillid       = "";
                    if (Request["arolestampid"].ToString() != "")
                    {
                        tmparolestampid = "'" + Request["arolestampid"].ToString() + "'";
                    }

                    string impallstring = dbobj.getnewcheck1("G", tmparolestampid, tmparolestampid, "1", "1", "");
                    tmprole   = impallstring.Split(';')[0].ToString();
                    tmpbillid = impallstring.Split(';')[1].ToString();
                    if (tmprole == "")
                    {
                        ViewBag.ErrMsg = @"<script>alert(""請先至表單流程設定中設定新業務及競業呈核流程!"");</script>";
                        return(View(col));
                    }
                    #endregion

                    col.custlevel1 = Request["custlevel1"];
                    col.custlevel2 = Request["custlevel2"];
                    col.custlevel3 = Request["custlevel3"];
                    col.iflaw      = "";
                    col.iffin      = "";
                    col.corpitem   = Request["corpitem"];
                    if (!string.IsNullOrWhiteSpace(Request["arolestampid"]))
                    {
                        col.arolestampid = Request["arolestampid"];
                    }
                    else
                    {
                        col.arolestampid = Request["arolestampid1"];
                    }

                    col.slogtype       = "1";
                    col.slogstatus     = "0"; // 己簽核:1  :0
                    col.rolestampid    = tmprole;
                    col.rolestampidall = tmparolestampid;
                    col.empstampidall  = "'" + col.empid + "'";
                    col.billflowid     = int.Parse(tmpbillid);
                    col.billtime       = DateTime.Now.ToString();
                    col.ccid           = Decimal.Parse(DateTime.Now.ToString("yyyyMMddhhmmssff"));
                    col.bmodid         = Session["tempid"].ToString();
                    col.bmoddate       = DateTime.Now;
                    using (AitagBill_DBContext con = new AitagBill_DBContext())
                    {
                        con.sales_competition.Add(col);
                        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    = "承辦人:" + col.empid + "產品名稱:" + col.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/List' 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='qcusttitle' name='qcusttitle' value='" + qcusttitle + "'>";
                    tmpform += "<input type=hidden id='qprodtitle' name='qprodtitle' value='" + qprodtitle + "'>";
                    tmpform += "</form>";
                    tmpform += "</body>";


                    return(new ContentResult()
                    {
                        Content = @"" + tmpform
                    });
                    // return RedirectToAction("List");
                }
            }
        }