Exemple #1
0
        public int GetStartEndID(MachineStartEnd info)
        {
            int    rest   = 0;
            string strSql = @"select Top 1 ID from MachineStartEnds where MachineId=@MachineId and SchueduleNumber=@SchueduleNumber
                                and [Status]=@Status ORDER BY ID desc";

            using (SqlCommand cmd = new SqlCommand(strSql, conn))
            {
                cmd.Parameters.AddWithValue("@MachineId", info.MachineId);
                cmd.Parameters.AddWithValue("@SchueduleNumber", info.SchueduleNumber);
                //cmd.Parameters.AddWithValue("@UserNumber", info.UserNumber);
                cmd.Parameters.AddWithValue("@Status", info.Status);

                rest = Convert.ToInt32(cmd.ExecuteScalar());
            }
            return(rest);
        }
Exemple #2
0
        public void InsertMachineStartEnd(MachineStartEnd info)
        {
            string formatSql = @"INSERT INTO MachineStartEnds ({0},MachineId,MachineNumber,MachineName,RoomId,RoomNumber,
                                    OrderId,OrderNumber,ScheduleId,SchueduleNumber,UserId,UserNumber,[Status]) 
                              VALUES (@{0},@MachineId,@MachineNumber,@MachineName,@RoomId,@RoomNumber,
                                    @OrderId,@OrderNumber,@ScheduleId,@SchueduleNumber,@UserId,@UserNumber,@Status)";
            string strSql    = string.Empty;

            if (info.Status == enumDeviceWorkStatus.Start)
            {
                strSql = "DateStart";
            }
            else
            {
                strSql = "DateEnd";
            }
            strSql = string.Format(formatSql, strSql);
            using (SqlCommand cmd = new SqlCommand(strSql, conn))
            {
                if (info.Status == enumDeviceWorkStatus.Start)
                {
                    cmd.Parameters.AddWithValue("@DateStart", info.DateStart);
                }
                else
                {
                    cmd.Parameters.AddWithValue("@DateEnd", info.DateEnd);
                }

                cmd.Parameters.AddWithValue("@MachineId", info.MachineId);
                cmd.Parameters.AddWithValue("@MachineNumber", info.MachineNumber);
                cmd.Parameters.AddWithValue("@MachineName", info.MachineName);
                cmd.Parameters.AddWithValue("@RoomId", info.RoomId);
                cmd.Parameters.AddWithValue("@RoomNumber", info.RoomNumber);
                cmd.Parameters.AddWithValue("@OrderId", info.OrderId);
                cmd.Parameters.AddWithValue("@OrderNumber", info.OrderNumber);
                cmd.Parameters.AddWithValue("@ScheduleId", info.ScheduleId);
                cmd.Parameters.AddWithValue("@SchueduleNumber", info.SchueduleNumber);
                cmd.Parameters.AddWithValue("@UserId", info.UserId);
                cmd.Parameters.AddWithValue("@UserNumber", info.UserNumber);
                cmd.Parameters.AddWithValue("@Status", info.Status);

                cmd.ExecuteNonQuery();
            }
        }
Exemple #3
0
        public byte[] HandlerClientData(byte[] buff)
        {
            byte[]    buffResp    = { 1 };
            DbHandler db          = new DbHandler();
            DateTime  currentTime = DateTime.Now;

            NetStructure.DeviceStartEnd outInfo = this.DecodeData(buff);
            Machines        machine             = db.SelectMachine(outInfo.MachineId);
            Schedules       schedule            = db.SelectSchedule(outInfo.ScheduleNumber);
            UserProfile     userInfo            = db.SelectUser(outInfo.UserNumber);
            MachineStartEnd innerInfo           = this.exchangeData(outInfo, machine, schedule, userInfo);

            //记录原始数据

            if (outInfo.Status == enumDeviceWorkStatus.Start)
            {
                innerInfo.DateStart = currentTime;
                db.InsertMachineStartEnd(innerInfo);
            }
            else
            {
                int startId = db.GetStartEndID(new MachineStartEnd()
                {
                    MachineId       = outInfo.MachineId,
                    SchueduleNumber = outInfo.ScheduleNumber,
                    UserNumber      = outInfo.UserNumber,
                    Status          = enumDeviceWorkStatus.Start
                });
                if (startId == 0)
                {
                    innerInfo.DateEnd = currentTime;
                    db.InsertMachineStartEnd(innerInfo);
                }
                else
                {
                    db.FinishStartStatus(startId);
                }
            }

            buffResp[0] = 0;

            return(buffResp);
        }
Exemple #4
0
        /// <summary>
        /// 内外部数据转换
        /// </summary>
        /// <param name="info"></param>
        /// <param name="machine"></param>
        /// <returns></returns>
        private MachineStartEnd exchangeData(NetStructure.DeviceStartEnd outInfo, Machines machine, Schedules schedule, UserProfile userInfo)
        {
            MachineStartEnd startEndItem = new MachineStartEnd()
            {
                MachineNumber = machine.Number,
                MachineId     = machine.ID,
                MachineName   = machine.Name,
                RoomId        = machine.RoomID,
                RoomNumber    = machine.RoomName
            };

            startEndItem.OrderId         = schedule.OrderId;
            startEndItem.OrderNumber     = schedule.OrderNumber;
            startEndItem.ScheduleId      = schedule.ID;
            startEndItem.SchueduleNumber = schedule.Number;
            startEndItem.UserId          = userInfo == null ? 0 : userInfo.UserId;
            startEndItem.UserNumber      = userInfo == null ? "" : userInfo.UserName;
            startEndItem.Status          = outInfo.Status;

            return(startEndItem);
        }