/// <summary> /// Gets by UserId and password. /// </summary> /// <param name="userId">The UserId.</param> /// /// <param name="password">The password in MD5.</param> /// <returns>Returns User instance.</returns> public static NDbResult <User> GetByUserId(string userId, string password) { var result = new NDbResult <User>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM UserView "; cmd += " WHERE UserId = ? "; cmd += " AND Password = ? "; var ret = NQuery.Query <FKs>(cmd, userId, password).FirstOrDefault(); var data = (null != ret) ? ret.ToModel() : null; result.Success(data); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Save User. /// </summary> /// <param name="value">The User instance.</param> /// <returns>Returns User instance.</returns> public static NDbResult <User> SaveUser(User value) { var result = new NDbResult <User>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { result = Save(value); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Save Plaza Revenue. /// </summary> /// <param name="value">The UserShiftRevenue instance.</param> /// <param name="revenueDate">The Revenue Date.</param> /// <param name="revenueId">The Revenue Id.</param> /// <returns>Returns save UserShiftRevenue instance.</returns> public static NDbResult <UserShiftRevenue> SavePlazaRevenue(UserShiftRevenue value, DateTime revenueDate, string revenueId) { var result = new NDbResult <UserShiftRevenue>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == value) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { value.RevenueDate = revenueDate; value.RevenueId = revenueId; // save. result = Save(value); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Create UserShift. /// </summary> /// <param name="shift">The Shift instance.</param> /// <param name="supervisor">The User instance.</param> /// <returns>Returns UserShift instance.</returns> public static NDbResult <UserShift> Create(Shift shift, User supervisor) { var result = new NDbResult <UserShift>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } UserShift inst = Create(); var tsb = TSB.GetCurrent().Value(); if (null != tsb) { tsb.AssignTo(inst); } if (null != shift) { shift.AssignTo(inst); } if (null != supervisor) { supervisor.AssignTo(inst); } result.Success(inst); return(result); }
/// <summary> /// Gets Plazas (By PlazaGroup Id). /// </summary> /// <param name="tsbId">The TSB Id.</param> /// <param name="plazaGroupId">The PlazaGroup Id.</param> /// <returns>Returns List of Plaza.</returns> public static NDbResult <List <Plaza> > GetPlazaGroupPlazas( string tsbId, string plazaGroupId) { var result = new NDbResult <List <Plaza> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM PlazaView "; cmd += " WHERE TSBId = ? "; cmd += " AND PlazaGroupId = ? "; var rets = NQuery.Query <FKs>(cmd, tsbId, plazaGroupId).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets All TSB Coupon Balance. /// </summary> /// <returns>Returns List fo all TSB Coupon balance.</returns> public static NDbResult <List <TSBCouponBalance> > GetTSBBalances() { var result = new NDbResult <List <TSBCouponBalance> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = @" SELECT * FROM TSBCouponBalanceView " ; var rets = NQuery.Query <FKs>(cmd).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Create Lane Attendance. /// </summary> /// <param name="lane">The Lane instance.</param> /// <param name="collector">The User instance.</param> /// <returns>Returns LaneAttendance instance.</returns> public static NDbResult <LaneAttendance> Create(Lane lane, User collector) { var result = new NDbResult <LaneAttendance>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } LaneAttendance inst = Create(); var tsb = TSB.GetCurrent().Value(); if (null == tsb) { result.ParameterIsNull(); } else { if (null != tsb) { tsb.AssignTo(inst); } if (null != lane) { lane.AssignTo(inst); } if (null != collector) { collector.AssignTo(inst); } result.Success(inst); } return(result); }
/// <summary> /// Gets Active TSB. /// </summary> /// <returns>Returns Active TSB instance.</returns> public static NDbResult <TSB> GetCurrent() { var result = new NDbResult <TSB>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { // inactive all TSBs string cmd = string.Empty; cmd += "SELECT * FROM TSB "; cmd += " WHERE Active = 1 "; var results = NQuery.Query <TSB>(cmd); var data = (null != results) ? results.FirstOrDefault() : null; result.Success(data); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Find Users by Group Id. /// </summary> /// <param name="groupId">The Group Id.</param> /// <param name="status">The status.</param> /// <returns>Returns List of User.</returns> public static NDbResult <List <User> > FindByGroupId(int groupId, int status) { var result = new NDbResult <List <User> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM UserView "; cmd += " WHERE GroupId = ? "; cmd += " AND Status = ? "; var rets = NQuery.Query <FKs>(cmd, groupId, status).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Plaza Lane. /// </summary> /// <param name="plazaId">The plaza Id.</param> /// <param name="laneNo">The lane number.</param> /// <returns>Returns match lane.</returns> public static NDbResult <Lane> GetPlazaLane(string plazaId, int laneNo) { var result = new NDbResult <Lane>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM LaneView "; cmd += " WHERE PlazaId = ? "; cmd += " AND LaneNo = ? "; var ret = NQuery.Query <FKs>(cmd, plazaId, laneNo).FirstOrDefault(); var data = (null != ret) ? ret.ToModel() : null; result.Success(data); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Payments. /// </summary> /// <param name="db">The database connection.</param> /// <returns>Returns List of Payment.</returns> public static NDbResult <List <Payment> > GetPayments(SQLiteConnection db) { var result = new NDbResult <List <Payment> >(); if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * FROM Payment "; var data = NQuery.Query <Payment>(cmd); result.Success(data); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Plaza by SCW Id. /// </summary> /// <param name="db">The database connection.</param> /// <param name="scwPlazaId">The SCW Plaza Id</param> /// <returns>Returns Plaza instance.</returns> public static NDbResult <Plaza> GetPlazaBySCWPlazaId(SQLiteConnection db, int scwPlazaId) { var result = new NDbResult <Plaza>(); if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM PlazaView "; cmd += " WHERE SCWPlazaId = ? "; var ret = NQuery.Query <FKs>(cmd, scwPlazaId).FirstOrDefault(); var data = (null != ret) ? ret.ToModel() : null; result.Success(data); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Un Close User Shifts. /// </summary> /// <param name="tsbid">The TSB Id.</param> /// <returns>Returns List of User Shifts.</returns> public static NDbResult <List <UserShift> > GetUnCloseUserShifts(string tsbid) { var result = new NDbResult <List <UserShift> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM UserShiftView "; cmd += " WHERE TSBId = ? "; cmd += " AND End = ? "; var rets = NQuery.Query <FKs>(cmd, tsbid, DateTime.MinValue).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Shift. /// </summary> /// <param name="db">The database connection.</param> /// <param name="shiftId">The Shift Id.</param> /// <returns>Returns Shift instance.</returns> public static NDbResult <Shift> GetShift(SQLiteConnection db, string shiftId) { var result = new NDbResult <Shift>(); if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * FROM Shift "; cmd += " WHERE ShiftId = ? "; var data = NQuery.Query <Shift>(cmd, shiftId).FirstOrDefault(); result.Success(data); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Role. /// </summary> /// <param name="db">The database connection.</param> /// <param name="roleId">The Role Id.</param> /// <returns>Returns Role instance.</returns> public static NDbResult <Role> GetRole(SQLiteConnection db, string roleId) { var result = new NDbResult <Role>(); if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * FROM Role "; cmd += " WHERE RoleId = ? "; var results = NQuery.Query <Role>(cmd, roleId).FirstOrDefault(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets TSB Coupon summaries. /// </summary> /// <param name="tsb">The target TSB to get balance.</param> /// <returns>Returns List of TSB Coupon balance. If TSB not found returns null.</returns> public static NDbResult <List <TSBCouponSummary> > GetTSBCouponSummaries(TSB tsb) { var result = new NDbResult <List <TSBCouponSummary> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == tsb) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = @" SELECT * FROM TSBCouponSummarryView WHERE TSBId = ? " ; var rets = NQuery.Query <FKs>(cmd, tsb.TSBId).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Users. /// </summary> /// <param name="db">The database connection.</param> /// <returns>Returns List of User.</returns> public static NDbResult <List <User> > GetUsers(SQLiteConnection db) { var result = new NDbResult <List <User> >(); if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM UserView "; var rets = NQuery.Query <FKs>(cmd).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets UserShift by TSBId and UserId. /// </summary> /// <param name="tsbId">Ths TSB id.</param> /// <param name="userId">The User Id.</param> /// <returns>Returns UserShift instance.</returns> public static NDbResult <UserShift> GetUserShift(string tsbId, string userId) { var result = new NDbResult <UserShift>(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM UserShiftView "; cmd += " WHERE TSBId = ? "; cmd += " AND UserId = ? "; cmd += " AND End = ? "; var ret = NQuery.Query <FKs>(cmd, tsbId, userId, DateTime.MinValue).FirstOrDefault(); result.data = (null != ret) ? ret.ToModel() : null; result.Success(); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
public static NDbResult SaveMCardAllows(List <MCardAllow> values) { lock (sync) { SQLiteConnection db = Default; MethodBase med = MethodBase.GetCurrentMethod(); var result = new NDbResult(); try { db.BeginTransaction(); values.ForEach(value => { MCardAllow.Save(value); }); db.Commit(); result.Success(); } catch (Exception ex) { db.Rollback(); med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets PlazaGroups (By TSBId). /// </summary> /// <param name="tsbId">The TSB Id.</param> /// <returns>Returns List of PlazaGroup.</returns> public static NDbResult <List <PlazaGroup> > GetTSBPlazaGroups(string tsbId) { var result = new NDbResult <List <PlazaGroup> >(); lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM PlazaGroupView "; cmd += " WHERE TSBId = ? "; var rets = NQuery.Query <FKs>(cmd, tsbId).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Data instance. /// </summary> /// <typeparam name="T">The type for data instance.</typeparam> /// <param name="value">The instance to get data.</param> /// <returns>Returns data instance.</returns> public static T Value <T>(this NDbResult <T> value) where T : new() { T ret = (null != value && !value.errors.hasError && null != value.data) ? value.data : DefaultData <T>(); return(ret); }
public static NDbResult SaveUsers(List <User> users) { var result = new NDbResult(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == users || users.Count <= 0) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { db.BeginTransaction(); var roles = Models.Role.GetRoles().Value(); users.ForEach(user => { User match = User.GetUser(user.UserId).Value(); if (null == match) { Save(user); // insert } else { match.UserId = user.UserId; match.PrefixEN = user.PrefixEN; match.PrefixTH = user.PrefixTH; match.FirstNameEN = user.FirstNameEN; match.FirstNameTH = user.FirstNameTH; match.MiddleNameEN = user.MiddleNameEN; match.MiddleNameTH = user.MiddleNameTH; match.LastNameEN = user.LastNameEN; match.LastNameTH = user.LastNameTH; match.Password = user.Password; Save(match); // update } }); db.Commit(); } catch (Exception ex) { med.Err(ex); db.Rollback(); } return(result); } }
/// <summary> /// Gets Output instance. /// </summary> /// <typeparam name="T">The type for data instance.</typeparam> /// <typeparam name="O">The type for output instance.</typeparam> /// <param name="value">The instance to get output.</param> /// <returns>Returns output instance.</returns> public static O Output <T, O>(this NDbResult <T, O> value) where T : new() where O : new() { O ret = (null != value && !value.errors.hasError && null != value.output) ? value.output : DefaultOutput <O>(); return(ret); }
/// <summary> /// Gets List of BHT35 by User in target TSB. /// </summary> /// <param name="tsb">The target TSB instance.</param> /// <param name="user">The user instance.</param> /// <returns>Returns List of BHT35.</returns> public static NDbResult <List <UserCouponTransaction> > GetUserBHT35Coupons( TSB tsb, User user) { var result = new NDbResult <List <UserCouponTransaction> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == tsb) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM UserCouponTransactionView "; cmd += " WHERE TSBId = ? "; cmd += " AND CouponType = ? "; if (null != user) { cmd += " AND UserId = ? "; } List <FKs> rets; if (null != user) { rets = NQuery.Query <FKs>(cmd, tsb.TSBId, CouponType.BHT35, user.UserId).ToList(); } else { rets = NQuery.Query <FKs>(cmd, tsb.TSBId, CouponType.BHT35).ToList(); } var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
public static NDbResult <List <TSBExchangeGroup> > GetTSBExchangeGroups(TSB tsb, StateTypes state, FinishedFlags flag, DateTime reqBegin, DateTime reqEnd) { var result = new NDbResult <List <TSBExchangeGroup> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == tsb) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM TSBExchangeGroupView "; cmd += " WHERE TSBId = ? "; cmd += " AND FinishFlag = ? "; if (state != StateTypes.None) { cmd += " AND State = ? "; } if (reqBegin != DateTime.MinValue) { cmd += " AND RequestDate >= ? "; if (reqEnd != DateTime.MinValue) { cmd += " AND RequestDate <= ? "; } } var rets = NQuery.Query <FKs>(cmd, tsb.TSBId, flag, state, reqBegin, reqEnd).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
public static NDbResult <List <LaneAttendance> > GetAllNotHasRevenueEntryByUser(User user) { var result = new NDbResult <List <LaneAttendance> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == user) { result.ParameterIsNull(); return(result); } var tsb = TSB.GetCurrent().Value(); if (null == tsb) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { string cmd = string.Empty; cmd += "SELECT * "; cmd += " FROM LaneAttendanceView "; cmd += " WHERE TSBId = ? "; cmd += " AND (RevenueDate = ?"; cmd += " OR RevenueId IS NULL "; cmd += " OR RevenueId = ?) "; cmd += " AND UserId = ? "; cmd += " ORDER BY UserId, Begin"; var rets = NQuery.Query <FKs>(cmd, tsb.TSBId, DateTime.MinValue, string.Empty, user.UserId).ToList(); var results = rets.ToModels(); result.Success(results); } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Begin User Shift. /// </summary> /// <param name="value">The UserShift instance.</param> /// <returns>Returns Begin User Shift Result.</returns> public static NDbResult BeginUserShift(UserShift value) { var result = new NDbResult(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == value) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { var last = GetUserShift(value.TSBId, value.UserId); if (null != last && null != last.data && !last.errors.hasError) { // not enter revenue entry. result.Error(new Exception("ยังมีกะที่ยังไม่ได้ป้อนรายได้")); result.errors.errNum = -10; return(result); } // Begin new shift. if (value.Begin == DateTime.MinValue) { value.Begin = DateTime.Now; } var saveRet = Save(value); result.errors = saveRet.errors; if (!result.errors.hasError) { result.Success(); } } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }
/// <summary> /// Gets Lanes (By Plaza). /// </summary> /// <param name="value">The Plaza instance.</param> /// <returns>Returns List fo Lanes.</returns> public static NDbResult <List <Lane> > GetPlazaLanes(Plaza value) { var result = new NDbResult <List <Lane> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { return(GetPlazaLanes(value.TSBId, value.PlazaGroupId, value.PlazaId)); } }
/// <summary> /// Gets PlazaGroups (By TSB). /// </summary> /// <param name="value">The TSB instance.</param> /// <returns>Returns List of PlazaGroup.</returns> public static NDbResult <List <PlazaGroup> > GetTSBPlazaGroups(TSB value) { var result = new NDbResult <List <PlazaGroup> >(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } lock (sync) { return(GetTSBPlazaGroups(value.TSBId)); } }
/// <summary> /// Change Shift. /// </summary> /// <param name="value">The TSBShift instance.</param> /// <returns>Returns Change Shift result.</returns> public static NDbResult ChangeShift(TSBShift value) { var result = new NDbResult(); SQLiteConnection db = Default; if (null == db) { result.DbConenctFailed(); return(result); } if (null == value) { result.ParameterIsNull(); return(result); } lock (sync) { MethodBase med = MethodBase.GetCurrentMethod(); try { var last = GetTSBShift(value.TSBId).Value(); if (null != last) { // End shift. last.End = DateTime.Now; Save(last); } // Begin new shift. if (value.Begin == DateTime.MinValue) { value.Begin = DateTime.Now; } var saveRet = Save(value); result.errors = saveRet.errors; if (!result.errors.hasError) { result.Success(); } } catch (Exception ex) { med.Err(ex); result.Error(ex); } return(result); } }