public static int AddTask(SqlConnection con, SqlTransaction sqt, ref TTaskInfo ti)
        {
            string sql    = String.Empty;
            Int32  TaskID = 0;

            try
            {
                sql = "insert into tTaskHead(CarID,BeginDate,OprtUserCode) values (@CarID,@BeginDate,@OprtUserCode)";
                SqlParameter[] pms = new SqlParameter[]
                {
                    new SqlParameter("@CarID", ti.CarID),
                    new SqlParameter("@BeginDate", ti.BeginDate),
                    new SqlParameter("@OprtUserCode", ti.OprtUserCode)
                };

                if (MsSqlHelper.ExecSqlUControl(con, sqt, sql, pms) == 1)
                {
                    TaskID    = Convert.ToInt32(MsSqlHelper.GetSingle(con, sqt, "select max(TaskID) as TaskID from tTaskHead where OprtUserCode=@OprtUserCode", new SqlParameter("@OprtUserCode", ti.OprtUserCode)));
                    ti.TaskID = TaskID;
                    foreach (var taskItem in ti.ListItems)
                    {
                        taskItem.TaskID = TaskID;
                        TTaskItemDAL.AddTaskItem(con, sqt, taskItem);
                    }
                    return(1);
                }
                else
                {
                    return(0);
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog("TTaskInfoDAL.AddTask  1", e);
                throw e;
            }
        }
        public static int AddTask(ref TTaskInfo ti, ref TCarInfo ci)
        {
            SqlConnection con = new SqlConnection(MsSqlHelper.connectionString);

            con.Open();
            SqlTransaction st = con.BeginTransaction();

            try
            {
                if (TCarInfoDAL.AddCarInfo(con, st, ref ci) == 1)
                {
                    ti.CarID = ci.CarID;
                    if (TTaskInfoDAL.AddTask(con, st, ref ti) == 1)
                    {
                        st.Commit();
                        return(1);
                    }
                    else
                    {
                        throw new Exception("添加任务信息出错");
                    }
                }
                else
                {
                    throw new Exception("添加车辆信息出错");
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog("TTaskInfoDAL.AddTask  2", e);
                st.Rollback();
                con.Close();
                con.Dispose();
                return(0);
            }
        }
Пример #3
0
 /// <summary>
 /// Create a new instance.
 /// </summary>
 /// <param name="taskInfo">Task information including an ID that uniquely identifies the task.</param>
 /// <param name="cancellation">The Cancellation token that can be used to cancel the work.</param>
 /// <param name="disposableCancellation">A value that indicates whether the cancel token can be disposed after the task is completed.</param>
 internal TaskContext(TTaskInfo taskInfo, CancellationTokenSource?cancellation, bool disposableCancellation)
 {
     TaskInfo               = taskInfo;
     Cancellation           = cancellation;
     DisposableCancellation = disposableCancellation;
 }
        public static int AddTask(string carNo, string MaintainTypes, string technicians, string carName,
                                  string carOwner, string carOwnerTel1, string carOwnerTel2, string carTrevalDistance, string OprtUserCode
                                  )
        {
            try
            {
                DateTime dt = DateTime.Now;

                TCarInfo tCi = new TCarInfo();
                tCi.CarID        = 0;
                tCi.CarNumber    = carNo;
                tCi.CarName      = carName;
                tCi.CarOwner     = carOwner;
                tCi.CarOwnerTel1 = carOwnerTel1;
                tCi.CarOwnerTel2 = carOwnerTel2;
                if (carTrevalDistance != null && carTrevalDistance != String.Empty)
                {
                    tCi.CarTrevalDistance = int.Parse(carTrevalDistance);
                }
                tCi.CarComeTime  = dt;
                tCi.OprtUserCode = OprtUserCode;

                TTaskInfo tTi = new TTaskInfo();
                tTi.TaskID       = 0;
                tTi.CarID        = 0;
                tTi.BeginDate    = dt;
                tTi.OprtUserCode = OprtUserCode;
                tTi.ListItems    = new List <TTaskItem>();
                if (MaintainTypes != String.Empty)
                {
                    String[] mtTypes = MaintainTypes.Split(',');
                    for (int i = 0; i < mtTypes.Length; i++)
                    {
                        //分配维修师傅
                        List <TTaskItemWorkers> listTw = new List <TTaskItemWorkers>();
                        if (technicians != String.Empty)
                        {
                            //获取可进行该维修类别的所有维修师傅ID列表
                            List <int> listmt = TUserInfoBLL.UGetMaintainUsers(int.Parse(mtTypes[i]));
                            String[]   tns    = technicians.Split(',');
                            foreach (var item in tns)
                            {
                                //判断循环中当前维修师傅,是否在上面的列表中
                                if (listmt.Contains(int.Parse(item)))
                                {
                                    listTw.Add(new TTaskItemWorkers()
                                    {
                                        TaskID     = 0,
                                        TaskItemID = 0,
                                        UID        = int.Parse(item)
                                    });
                                }
                            }
                        }

                        tTi.ListItems.Add(new TTaskItem()
                        {
                            TaskID     = 0,
                            MID        = int.Parse(mtTypes[i]),
                            TaskItemID = i,
                            BeginTime  = dt,
                            ListWorks  = listTw
                        }
                                          );
                    }
                }

                return(TTaskInfoBLL.AddTask(ref tTi, ref tCi));
            }
            catch (Exception e)
            {
                LogHelper.WriteLog("AddTask", e);
                return(0);
            }
        }
 public static int AddTask(ref TTaskInfo ti, ref TCarInfo ci)
 {
     return(TTaskInfoDAL.AddTask(ref ti, ref ci));
 }