public int Save(TaskDeviceData taskDeviceData) { StringBuilder sql = new StringBuilder(); if (taskDeviceData.Id > 0) { throw new NotImplementedException(); } else { sql.Append("INSERT INTO bu_task_device (bu_task_device.bu_device_id,bu_task_device.bu_task_id) VALUES ('"); sql.Append(taskDeviceData.Bu_device_id + ","); sql.Append(taskDeviceData.Bu_task_id); sql.Append(") SET @id = SCOPE_IDENTITY();"); } MySqlParameterCollection sqlCollection = new MySqlDa().ExecuteNonQuery(sql.ToString()); return (int)sqlCollection["@id"].Value; }
protected void btnAddDate_OnClick(object sender, EventArgs e) { if (EnumBackupTask.Procedure.immediately==(EnumBackupTask.Procedure)Session["BackupTask"]) { BackupServerClient serverClient = GlobalVariables.serverClient; if (serverClient != null) { //Check the selected devices List<TaskData> lstTaskData = new List<TaskData>(); DateTime taskDate = DateTime.Now; for (int i = 0; i < grdDevices.Rows.Count; i++) { CheckBox chkSelectDevice = (CheckBox)grdDevices.Rows[i].Cells[0].FindControl("ChbSelect"); if (chkSelectDevice.Checked) { TaskData taskData = new TaskData(); taskData.Id = -1; taskData.Date = taskDate; taskData.Repeat = (int)EnumSchedule.Task.Once; taskData.RepeatDay = -1; taskData.RepeatDayOftheWeek = -1; taskData.RepeatMonth = -1; lstTaskData.Add(taskData); } } if (lstTaskData.Count > 0) { SocketBackupTransportData socketTransportData = new SocketBackupTransportData(); socketTransportData.Date = taskDate; socketTransportData.Command = EnumSocketCommands.Command.FAST_BACKUP.ToString(); string sValue = ObjectSerializer.SerializeToString(socketTransportData); bool sended = serverClient.send(sValue); //List<SocketBackupTransportData> lstBackup = ObjectSerializer.SerializeFromString<List<SocketBackupTransportData>>(sValue); if (sended) { for (int i = 0; i < lstTaskData.Count; i++) { TaskDa taskDa = new TaskDa(); taskDa.Save(lstTaskData[i]); } } else { Page.RegisterClientScriptBlock("Alert Task", "<script language='javascript'>alert('Server Error: Task not executed!')</script>"); } } loadData(DateTime.Now); } else { Page.RegisterClientScriptBlock("Alert Task", "<script language='javascript'>alert('Error: Task not executed!')</script>"); } } else { TaskData taskData = new TaskData(); DateTime date = DateTime.Parse(txtDate.Text, new CultureInfo("en-US", false)); string[] time = txtHour.Text.Split(':'); taskData.Date = new DateTime(date.Year, date.Month, date.Day, int.Parse(time[0]), int.Parse(time[1]), 0); switch (drpSchedule.SelectedIndex) { case (int)EnumSchedule.Task.Once: taskData.Repeat = (int)EnumSchedule.Task.Once; taskData.RepeatDayOftheWeek = -1; taskData.RepeatDay = -1; taskData.RepeatMonth = -1; break; case (int)EnumSchedule.Task.Dailey: taskData.Repeat = (int)EnumSchedule.Task.Dailey; taskData.RepeatDayOftheWeek = -1; taskData.RepeatDay = -1; taskData.RepeatMonth = -1; break; case (int)EnumSchedule.Task.Weekley: taskData.Repeat = (int)EnumSchedule.Task.Weekley; taskData.RepeatDayOftheWeek = (int)date.DayOfWeek; taskData.RepeatDay = -1; taskData.RepeatMonth = -1; break; case (int)EnumSchedule.Task.Monthly: taskData.Repeat = (int)EnumSchedule.Task.Monthly; taskData.RepeatDayOftheWeek = (int)date.DayOfWeek; taskData.RepeatDay = -1; taskData.RepeatMonth = -1; break; case (int)EnumSchedule.Task.Annually: taskData.Repeat = (int)EnumSchedule.Task.Annually; break; } TaskDa taskDa = new TaskDa(); taskDa.Save(taskData); //Check the selected devices for (int i = 0; i < grdDevices.Rows.Count; i++) { CheckBox chkSelectDevice = (CheckBox)grdDevices.Rows[i].Cells[0].FindControl("ChbSelect"); if (chkSelectDevice.Checked) { TaskDeviceData taskDeviceData = new TaskDeviceData(); taskDeviceData.Bu_device_id = int.Parse(grdDevices.DataKeys[i].Value.ToString()); taskDeviceData.Bu_task_id = taskData.Id; } } loadData(taskData.Date); } }