/// <summary> /// Update a element that match the conditions defined /// </summary> /// <param name="AddressDatabase"></param> /// <param name="e"></param> /// <param name="user"></param> /// <param name="stuff"></param> /// <returns></returns> public async Task <bool> UpdateAsync(string AddressDatabase, EChoice e, object Target, User user = null, Stuff stuff = null) { return(await Task.Run(() => { using (var db = new SQLiteConnection(AddressDatabase)) { string query = String.Empty; var result = SQLiteResult.EMPTY; if (EChoice.Stuff.Equals(e)) { query = $"UPDATE Stuff SET Name ='{stuff.Name}' , Salary = '{stuff.Salary}' , Old = '{stuff.Old}' WHERE ID LIKE '{stuff.ID}'"; result = db.Prepare(query).Step(); if (result == SQLiteResult.DONE) { return true; } } else if (EChoice.User.Equals(e)) { query = $"UPDATE User SET Name ='{stuff.Name}' , Password = '******' , NameOfUser = '******' WHERE Name LIKE '{user.Name}'"; result = db.Prepare(query).Step(); if (result == SQLiteResult.DONE) { return true; } } return false; } })); }
public Choice Create(Choice question) { EChoice eChoice = EChoice(question); eChoice = _iDChoice.Create(eChoice); return(Choice(eChoice)); }
private Choice Choice(EChoice eChoice) { Choice returnChoice = new Choice { Correct = eChoice.Correct, ChoiceId = eChoice.ChoiceId, QuestionId = eChoice.QuestionId, Description = eChoice.Description }; return(returnChoice); }
private EChoice EChoice(Choice choice) { EChoice returnEChoice = new EChoice { Correct = choice.Correct, ChoiceId = choice.ChoiceId, QuestionId = choice.QuestionId, Description = choice.Description }; return(returnEChoice); }
private void tabControl2_Selected(object sender, TabControlEventArgs e) { switch (e.TabPageIndex) { case 0: _choice = EChoice.Employee; break; case 1: _choice = EChoice.Leave; break; default: break; } }
/// <summary> /// Method for SearchAsync /// </summary> /// <param name="AddressDatabase"></param> /// <param name="e"></param> /// <param name="obj"></param> /// <param name="TargetUser"></param> /// <param name="TargetStuff"></param> /// <returns></returns> protected ArrayList Search(string AddressDatabase, EChoice e, object obj, EinUser?TargetUser = null, EinStuff?TargetStuff = null) { ArrayList result = new ArrayList(); string query = string.Empty; using (var db = new SQLiteConnection(AddressDatabase)) { if (EChoice.User == e && TargetUser != null) { query = $"select * from User where {TargetUser.ToString()} like '{obj.ToString()}'"; var statement = db.Prepare(query); while (!(SQLiteResult.DONE == statement.Step())) { result.Add(new User() { Name = statement[0].ToString(), Pass = statement[1].ToString(), NameOfUser = statement[2].ToString() }); } } else if (EChoice.Stuff == e) { query = $"select * from Stuff where {TargetStuff.ToString()} like '{obj.ToString()}'"; var statement = db.Prepare(query); while (!(SQLiteResult.DONE == statement.Step())) { result.Add(new Stuff() { ID = statement[0].ToString(), Name = statement[1].ToString(), Salary = statement[2].ToString(), Old = statement[3].ToString() }); } } } return(result); }
/// <summary> /// /// Removes a element that match the conditions defined /// </summary> /// <param name="AddressDatabase"></param> /// <param name="e"></param> /// <param name="obj"></param> /// <param name="estuff"></param> /// <param name="euser"></param> /// <returns></returns> public async Task <bool> DeleteWithAsync(string AddressDatabase, EChoice e, object obj, EinStuff?estuff = null, EinUser?euser = null) { return(await Task.Run(() => { string query = String.Empty; using (var db = new SQLiteConnection(AddressDatabase)) { if (EChoice.Stuff == e && estuff != null) { query = $"delete from {e.ToString()} where {estuff.ToString()} like {obj.ToString()}"; db.Prepare(query).Step(); return true; } else if (EChoice.User == e && euser != null) { query = $"delete from {e.ToString()} where {euser.ToString()} like '{obj.ToString()}'"; db.Prepare(query).Step(); return true; } } return false; })); }
/// <summary> /// Insert data to database /// And the data is User or Stuff /// </summary> /// <param name="AddressDatabase"></param> /// <param name="e"></param> /// <param name="user"></param> /// <param name="stuff"></param> /// <returns></returns> public async Task <bool> Insert(string AddressDatabase, EChoice e, User user = null, Stuff stuff = null) { Task <IEnumerable <User> > getUser = Task.Factory.StartNew(() => GetAllUser(AddressDatabase)); Task <IEnumerable <Stuff> > getStuff = Task.Factory.StartNew(() => GetAllStuff(AddressDatabase)); using (var db = new SQLiteConnection(AddressDatabase)) { var result = SQLiteResult.EMPTY; var GetUser = await getUser; var GetStuff = await getStuff; if (EChoice.Stuff == e) { if (GetStuff.ToList().Exists(p => p.ID == stuff.ID)) { return(false); } else if (String.IsNullOrWhiteSpace(stuff.ID) || String.IsNullOrWhiteSpace(stuff.Name) || String.IsNullOrWhiteSpace(stuff.Old) || String.IsNullOrWhiteSpace(stuff.Salary)) { return(false); } else if (String.IsNullOrEmpty(stuff.ID) || String.IsNullOrEmpty(stuff.Name) || String.IsNullOrEmpty(stuff.Old) || String.IsNullOrEmpty(stuff.Salary)) { return(false); } else if (stuff != null) { string query = $"INSERT INTO Stuff VALUES ('{stuff.ID}','{stuff.Name.ToString()}','{stuff.Old}','{stuff.Salary}')"; result = db.Prepare(query).Step(); if (result != SQLiteResult.DONE) { return(false); //throw new Exception("Query can't execute"); } return(true); } else { return(false); //throw new ArgumentException("Paramater stuff can't null"); } } else if (EChoice.User == e) { if (GetUser.ToList().Exists(p => p.Name == user.Name)) { return(false); } if (user != null && user.Name != null && user.NameOfUser != null && user.Pass != null) { string query = $"INSERT INTO User VALUES ('{ user.Name.ToString() }','{ user.Pass.ToString() }','{ user.NameOfUser.ToString() }')"; result = db.Prepare(query).Step(); if (result != SQLiteResult.DONE) { return(false); //throw new Exception("Query can't execute"); } return(true); } else { return(false); //throw new ArgumentException("Paramater stuff can't null"); } } } return(false); }
/// <summary> /// Search a elements is in Database /// </summary> /// <param name="AddressDatabase"></param> /// <param name="e"></param> /// <param name="obj"></param> /// <param name="TargetUser"></param> /// <param name="TargetStuff"></param> /// <returns></returns> public Task <ArrayList> SearchAsync(string AddressDatabase, EChoice e, object obj, EinUser?TargetUser = null, EinStuff?TargetStuff = null) { return(Task.Factory.StartNew(() => Search(AddressDatabase, e, obj, TargetUser, TargetStuff))); }