Пример #1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        MSYS.DAL.DbOperator opt = new MSYS.DAL.DbOperator();
        string   Btime          = opt.GetSegValue("select begin_time from ht_sys_shift t where shift_name = '早班'", "begin_time");
        DateTime startdate      = Convert.ToDateTime(txtStartDate.Text + " " + Btime);
        DateTime enddate        = Convert.ToDateTime(txtEndDate.Text + " " + Btime).AddDays(1);

        if (listPrdline.SelectedValue == "" || txtStartDate.Text == "" || txtEndDate.Text == "" || startdate - enddate > new  TimeSpan(0) || enddate - System.DateTime.Now < new  TimeSpan(0))
        {
            ScriptManager.RegisterStartupScript(UpdatePanel1, this.Page.GetType(), "alert", "alert('请选择正确的排班车间与时间段!!')", true);
            return;
        }
        DateTime tempdate = GetMondayDate(startdate).AddDays(7);

        if (GridView1.Rows.Count > 0)
        {
            List <string> commandlist = new List <string>();

            List <TeamSchedula> schedules = getTeamSchedule();
            int h = 0;
            if (startdate - System.DateTime.Now < new TimeSpan(0))
            {
                startdate = System.DateTime.Now;
            }
            while (startdate < enddate)
            {
                if (h == 3)
                {
                    h = 0;
                }
                TeamSchedula schedule = schedules.ToArray()[h];
                while (startdate < tempdate && startdate <= enddate)
                {
                    for (int i = 0; i < GridView1.Rows.Count; i++)
                    {
                        string endtime = startdate.ToString("yyyy-MM-dd") + " " + ((TextBox)GridView1.Rows[i].FindControl("txtEndtime")).Text;
                        if (((CheckBox)GridView1.Rows[i].FindControl("ckInter")).Checked)
                        {
                            endtime = startdate.AddDays(1).ToString("yyyy-MM-dd") + " " + ((TextBox)GridView1.Rows[i].FindControl("txtEndtime")).Text;
                        }
                        string[] seg   = { "WORK_DATE", "WORK_SHOP_CODE", "SHIFT_CODE", "TEAM_CODE", "WORK_STAUS", "CREATE_TIME", "MODIFY_TIME", "DATE_BEGIN", "DATE_END", "is_del" };
                        string[] value = { startdate.ToString("yyyy-MM-dd"), listPrdline.SelectedValue, GridView1.DataKeys[i].Value.ToString(), schedule.team.ToArray()[i], "1", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), startdate.ToString("yyyy-MM-dd") + " " + ((TextBox)GridView1.Rows[i].FindControl("txtStarttime")).Text, endtime, "0" };
                        if (((CheckBox)GridView1.Rows[i].FindControl("ckInter")).Checked)
                        {
                            startdate = startdate.AddDays(1);
                        }
                        commandlist.Add(opt.getMergeStr(seg, value, 3, "HT_PROD_SCHEDULE"));
                    }
                }
                h++;
                tempdate = tempdate.AddDays(7);
            }
            string log_message = opt.TransactionCommand(commandlist) == "Success" ? "排班成功" : "排班失败";
            log_message += ",排班时间:" + txtStartDate.Text + "~" + txtEndDate.Text;
            InsertTlog(log_message);
            ScriptManager.RegisterStartupScript(UpdatePanel1, this.Page.GetType(), "alert", "alert('" + log_message + "')", true);
        }
        bindGrid2();
    }
Пример #2
0
    protected List <TeamSchedula> getTeamSchedule()
    {
        List <TeamSchedula> teams = new List <TeamSchedula>();

        foreach (GridViewRow row in GridView3.Rows)
        {
            TeamSchedula schedule = new TeamSchedula();
            schedule.team = new List <string>();
            schedule.team.Add(((DropDownList)row.FindControl("listTeam1")).SelectedValue);
            schedule.team.Add(((DropDownList)row.FindControl("listTeam2")).SelectedValue);
            schedule.team.Add(((DropDownList)row.FindControl("listTeam3")).SelectedValue);
            teams.Add(schedule);
        }
        return(teams);
    }