protected void AddTask()
    {
        DateTime        dt               = DateTime.Now;
        string          sqlcheck         = "Select * from InformTask where nextdate='" + dt.ToString("yyyy/MM/dd") + "'";
        string          ConnectionString = ConfigurationManager.ConnectionStrings["mdbcon"].ConnectionString;
        OleDbConnection conn             = new OleDbConnection(ConnectionString);
        OleDbCommand    cmd              = new OleDbCommand(sqlcheck, conn);

        conn.Open();
        OleDbDataReader rd = cmd.ExecuteReader();

        while (rd.Read())
        {
            string sqlinsert = "Insert INTO DailyInform (jitai,[lindex],banci,content,eng,shortdate,status,[fabiaodate]) values ('"
                               + rd["item"].ToString() + "','20','系统提醒','" + rd["content"].ToString() + "','" + rd["eng"].ToString()
                               + "','" + dt.ToString("yyyy/MM/dd") + "','" + rd["status"].ToString() + "',#" + DateTime.Now.ToLocalTime() + "#)";
            string nextdate = "";
            switch (rd["zhouqi"].ToString())
            {
            case "每天":
            {
                nextdate = DateTime.Now.AddDays(1).ToString("yyyy/MM/dd");
                break;
            }

            case "每星期":
            {
                int dateindex = Convert.ToInt32(rd["dateindex"].ToString());
                nextdate = DateManage.GetWeekUpOfDate(dt, dateindex, 1).ToString("yyyy/MM/dd");
                break;
            }

            case "每月":
            {
                int dateindex = Convert.ToInt32(rd["dateindex"].ToString());
                nextdate = DateManage.GetDayUpOfDate(dt, dateindex, 1).ToString("yyyy/MM/dd");
                break;
            }

            case "指定日期":
            {
                nextdate = "";
                break;
            }

            default:
            {
                nextdate = "";
                break;
            }
            }
            string sqlupdate = "Update InformTask Set lastdate='" + dt.ToString("yyyy/MM/dd") + "',nextdate='" + nextdate + "' where ID in (" + rd["ID"].ToString() + ")";
            DbManager.ExecuteNonQuery(sqlinsert);
            DbManager.ExecuteNonQuery(sqlupdate);
        }

        //int mouth = DateTime.Today.Day;
        //string week = DateTime.Today.ToString("每dddd", new System.Globalization.CultureInfo("zh-CN"));
        //string today = DateTime.Today.ToString("yyyy/MM/dd");
        //string sqlcheck = "Select * from InformTask where (zhouqi='"+week+"' or zhouqi='每天') And (lastdate is null or lastdate<>'" + today + "')";
        //string ConnectionString = ConfigurationManager.ConnectionStrings["mdbcon"].ConnectionString;
        //OleDbConnection conn = new OleDbConnection(ConnectionString);
        //OleDbCommand cmd = new OleDbCommand(sqlcheck, conn);
        //conn.Open();
        //OleDbDataReader rd = cmd.ExecuteReader();
        //while (rd.Read())
        //{
        //    string sqlinsert = "Insert INTO DailyInform (jitai,[lindex],banci,content,eng,shortdate,status,[fabiaodate]) values ('"
        //        + rd["item"].ToString() + "','20','系统提醒','" + rd["content"].ToString() + "','" + rd["eng"].ToString()
        //        + "','" + today + "','" + rd["status"].ToString() + "',#" + DateTime.Now.ToLocalTime() + "#)";
        //    string sqlupdate = "Update InformTask Set lastdate='" + today + "' where ID in (" + rd["ID"].ToString() + ")";
        //    DbManager.ExecuteNonQuery(sqlinsert);
        //    DbManager.ExecuteNonQuery(sqlupdate);
        //}
        //rd.Close();
        //conn.Close();

        //if (mouth == 1)
        //{
        //    sqlcheck = "Select * from InformTask where zhouqi='每月1号' And (lastdate is null or lastdate<>'" + today + "')";
        //    ConnectionString = ConfigurationManager.ConnectionStrings["mdbcon"].ConnectionString;
        //    conn = new OleDbConnection(ConnectionString);
        //    cmd = new OleDbCommand(sqlcheck, conn);
        //    conn.Open();
        //    rd = cmd.ExecuteReader();
        //    while (rd.Read())
        //    {
        //        string sqlinsert = "Insert INTO DailyInform (jitai,[lindex],banci,content,eng,shortdate,status,[fabiaodate]) values ('"
        //            + rd["item"].ToString() + "','20','系统提醒','" + rd["content"].ToString() + "','" + rd["eng"].ToString()
        //            + "','" + today + "','" + rd["status"].ToString() + "',#" + DateTime.Now.ToLocalTime() + "#)";
        //        string sqlupdate = "Update InformTask Set lastdate='" + today + "' where ID in (" + rd["ID"].ToString() + ")";
        //        DbManager.ExecuteNonQuery(sqlinsert);
        //        DbManager.ExecuteNonQuery(sqlupdate);
        //    }
        //    rd.Close();
        //    conn.Close();
        //}
        //if (mouth == 15)
        //{
        //    sqlcheck = "Select * from InformTask where zhouqi='每月15号' And (lastdate is null or lastdate<>'" + today + "')";
        //    ConnectionString = ConfigurationManager.ConnectionStrings["mdbcon"].ConnectionString;
        //    conn = new OleDbConnection(ConnectionString);
        //    cmd = new OleDbCommand(sqlcheck, conn);
        //    conn.Open();
        //    rd = cmd.ExecuteReader();
        //    while (rd.Read())
        //    {
        //        string sqlinsert = "Insert INTO DailyInform (jitai,[lindex],banci,content,eng,shortdate,status,[fabiaodate]) values ('"
        //            + rd["item"].ToString() + "','20','系统提醒','" + rd["content"].ToString() + "','" + rd["eng"].ToString()
        //            + "','" + today + "','" + rd["status"].ToString() + "',#" + DateTime.Now.ToLocalTime() + "#)";
        //        string sqlupdate = "Update InformTask Set lastdate='" + today + "' where ID in (" + rd["ID"].ToString() + ")";
        //        DbManager.ExecuteNonQuery(sqlinsert);
        //        DbManager.ExecuteNonQuery(sqlupdate);
        //    }
        //    rd.Close();
        //    conn.Close();
        //}
    }
Beispiel #2
0
    protected void Add_OK_Click(object sender, EventArgs e)
    {
        if (DD_Add_Item.SelectedIndex == 0)
        {
            ToolTips.Text    = "请选择项目/机台";
            ToolTips.Visible = true;
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script> ShowDialog('Add_Dialog');</script>");
        }
        else if (TB_Add_Content.Text == "")
        {
            ToolTips.Text    = "交接内容不能为空";
            ToolTips.Visible = true;
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script> ShowDialog('Add_Dialog');</script>");
        }
        else
        {
            string status = "Close";
            if (Open.Visible)
            {
                status = "Open";
            }
            string   fullzhouqi = "每天";
            string   nextdate   = "";
            DateTime dt         = new DateTime();
            switch (DD_Add_Time.SelectedIndex)
            {
            case 0:
            {
                dt       = DateTime.Now.AddDays(1);
                nextdate = dt.ToString("yyyy/MM/dd");
                break;
            }

            case 1:
            {
                dt         = DateManage.GetWeekUpOfDate(DateTime.Now, DD_Add_SubTime.SelectedIndex + 1, 1);
                nextdate   = dt.ToString("yyyy/MM/dd");
                fullzhouqi = "每" + DD_Add_SubTime.SelectedItem.Text;
                break;
            }

            case 2:
            {
                dt         = DateManage.GetDayUpOfDate(DateTime.Now, DD_Add_SubTime.SelectedIndex + 1, 1);
                nextdate   = dt.ToString("yyyy/MM/dd");
                fullzhouqi = "每" + DD_Add_SubTime.SelectedItem.Text;
                break;
            }

            case 3:
            {
                nextdate   = TB_Add_SubTime.Text;
                fullzhouqi = DD_Add_Time.SelectedValue;
                break;
            }
            }
            string sql = "Insert into InformTask (item,content,zhouqi,dateindex,fullzhouqi,nextdate,status,eng,longdate) Values ('" +
                         DD_Add_Item.SelectedValue + "','" + Input.Inputadd(TB_Add_Content.Text) + "','" + DD_Add_Time.SelectedValue + "','" + DD_Add_SubTime.SelectedValue + "','" + fullzhouqi + "','" + nextdate + "','" +
                         status + "','" + Session["name"] + "',#" + DateTime.Now.ToLocalTime() + "#)";
            if ((bool)ViewState["isedit"])
            {
                sql = "Update InformTask Set item='" + DD_Add_Item.SelectedValue + "',content='" + Input.Inputadd(TB_Add_Content.Text)
                      + "',zhouqi='" + DD_Add_Time.SelectedValue + "',dateindex='" + DD_Add_SubTime.SelectedValue + "',fullzhouqi='" + fullzhouqi + "',nextdate='" + nextdate
                      + "',status='" + status + "',eng='" + Session["name"].ToString() + "',longdate=#" + DateTime.Now.ToLocalTime()
                      + "# where ID in (" + ViewState["sqlid"].ToString() + ")";
                ;
            }
            try
            {
                DbManager.ExecuteNonQuery(sql);
                string myscript = @"alert('发布成功!');window.location.href='InformTask.aspx';";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", myscript, true);
            }
            catch
            {
                ToolTips.Text    = "发布失败,请检查交接内容重试或与管理员联系!";
                ToolTips.Visible = true;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script> ShowDialog('Add_Dialog');</script>");
            }
        }
    }