/// <summary> /// Checks if the request is allowable,returns true if it's allowable, else, returns false /// </summary> /// <param name="request_id">The id of the request in the request table.</param> /// <param name="request_type">The type of request,if it's for test,purchase,etc.</param> /// <param name="current_user">the current user logged in</param> /// <returns>returns true if it's allowable, else, returns false</returns> public bool CheckRequest(int request_id, int request_type, int current_user) { this.request_id = request_id; this.request_type = request_type; Query r_que = new Query(); //query the request table and make sure it's a request that is accepted r_que.Get("SELECT * FROM requests WHERE request_id = '" + this.request_id + "' AND accepted = '1'"); //check if the query returns true if (r_que.CountRows() < 1) { return(false); } else {//THERE'S A RECORD r_que.Record(); //GET THE PROCESSING REQUEST METHOD. Query t_que = new Query(); // string[] r_stuff = this.ProcessingRequests(request_type, "WHERE _editors LIKE '" + request_id + "'"); //column numbers are different, so to get the exact column for _added_by and _editors, int cols = (r_stuff.Length - 1); //now loop to get the exact column int editors_col = 0; int adder_col = 0; int pos = 0; for (int i = cols; i >= 0; i--, pos++) { if (pos == 1) {//its the _editors column editors_col = i; } else if (pos == 2) {//its the _added_by column adder_col = i; } if (pos > 2) { break; } } //check if the the request has exceeded it's allowance. int r_amount = Convert.ToInt32(r_que.Result[4]); int e_amount = 0; //get the value from the editors column //search for the id, and check if the id appears more or less time than the amount value in the request table Split s = new Split(); s.Divide(r_que.Result[4], '|'); for (int i = 0; i < s.Value_array.Length; i++) { if (f.Search(s.Value_array[i], r_que.Result[0]) == true) {//The id was found, e_amount += 1; } } if (e_amount < r_amount) {//its still possible, the amount is less than what is allowed return(true); } else { return(false); } } }
/// <summary> /// method for updating a record in a table /// </summary> /// <param name="table">the name of the table</param> /// <param name="columns">the column(s) to be edited.</param> /// <param name="values">the value of the column(s) listed</param> /// <param name="condition">the conditon, e.g set bla = 'bla' where bla_id = 'bla'</param> public void Change(string table, string columns, string[] values, string condition) { //filter values Filter filter = new Filter(); this.table = table; this.condition = condition; //CHECK IF THE column is empty string col = string.Empty; if (filter.Trim(columns) == "" || filter.Trim(table) == "" || filter.Trim(condition) == "") { //IT CAN'T BE EMPTY if (columns == "") { box = new PopUp("Columns can't be empty in the current Change() method."); } else if (table == "") { box = new PopUp("table can't be empty in the current Change() method."); } else if (condition == "") { box = new PopUp("condition can't be empty in the current Change() method."); } else { box = new PopUp("A value is empty, can't work. I don't even know what is wrong sef, oh, find the problem yourself, i cannot come and be killing myself."); } } else { //COLUMN HAS SOME VALUES,make sure the number of columns are equal to the number of values #region handling the columns stuff Split split = new Split(); //divide split.Divide(columns, ','); //set the start first, we'll accomplish this at the end, under the looping ish. //col = bla = 'bla',bla = 'bla'; //make sure before counting the array, they must not be empty. string comma = ""; //CHECK IF THE COLUMNS LENGTH AND VALUE LENGTH ARE THE SAME. if (split.Length == values.Length) { //now store for (int i = 0; i < split.Value_array.Length; i++) //keep adding to the col variable with comma { //actually this is unecessary work, but it's just to make sure int j = 0; if (filter.Trim(split.Value_array[i]) != "") {//NOW THIS IS WHAT MAKES THE CODE USEFUL /* * SOMEONE MIGHT PUT COMMA AT THE END OR IN BETWEEN BY MISTAKE, * AND THAT COULD DESTROY EVERYTHING, THEN THAT * STUPID ERROR STARTS SHOWING AGAIN. * THIS PREVENTS THAT :) */ //ADD THE VALUE //FILTER THE VALUES ISH PROPERLY TO INSERT INTO THE QUERY /* * THERE COULD BE SOME CONDITIONS. * the string[] values variable holds values in string, so even if you input a sql functional value like "NOW()" * it will be passed as a string, which would not turn out good, if we don't handle it properly. * so we're going to set up an array that holds functional values to determine when we would remove string nature * what i mean is we'll create an array that holds values of functions in sql command, so when we are looking through * the string[] value values, we can check if any functional sql value is part of the values, by comparing the values * with the values inside the other array that stores functional values */ //THE ARRAY THAT STORES THE FUNCTIONAL VALUES, any sql functional values used in queries should be added here. :) // string[] func_val = { "NOW()" }; //THE VARIABLE THAT WILL STORE UP string[] value values //NOW WHILE CHECKING THROUGH THE VALUES, ALSO CHECK FOR FUNCTIONAL VALUES TO REMOVE THE QUOTES for (j = 0; j < func_val.Length; j++) {//STORE THE VALUE //CHECK IF THE VALUE ISN'T THE LAST ARRAY SO THAT WE DON'T PUT COMMA IN THE LAST VALUE int calc = values.Length - i; if (calc == 1)//its the last value, remove the comma { comma = ""; } else { comma = ","; } if (filter.Trim(values[i]).ToUpper() == filter.Trim(func_val[j].ToUpper()) /*making sure they're all uppercase to perfect comparising*/) {//it's a functional value, remove the quotes col += filter.Trim(split.Value_array[i]) + " = " + filter.Trim(values[i]) + "" + comma; } else {//ITS NOT A FUNCTIONAL value, leave the quotes col += filter.Trim(split.Value_array[i]) + " = '" + filter.Trim(values[i]) + "'" + comma; } } //reset j to keep checking if the values match the functional values. } else {//do nothing } } #endregion //update string q = "UPDATE " + this.table + " SET " + col + " " + this.condition; // this.Quering(update, q); } else {//THE COLUMN AND VALUE ARE NOT THE SAME, THAT WILL BE AN ISSUE box = new PopUp("Internal Error: the number of columns and the number of values aren't equivalent in the recent Change() Method."); } } }
/// <summary> /// Converts the date to the format you want /// </summary> /// <param name="date">the string date you want to change, the default format it recognises is MM/dd/yyyy</param> /// <param name="format">the format you want, this recognises the different date formats</param> /// <returns>returns the formatted result. :)</returns> public string Date(string date, string format) { string return_date = ""; //SINCE THE DATE STRING IN CSHARP COMES AS 03/30/2017 12:00:00 AM //we have to seperate the year,month and day if ((this.Trim(format) == "" || format == null) || (this.Trim(date) == "" || date == null)) { // PopUp p = new PopUp(""); return_date = date; } else { Split fs = new Split(); fs.Divide(date, ' '); //second split //FIRST HAS A VALUE OF SPLIT / //SECOND HAS A VALUE OF : //THIRD IS AM OR PM. int year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0; //check the length of the returned array. for (int i = 0; i < fs.Value_array.Length; i++) { if (fs.Value_array.Length > 0) { Split ffs = new Split(); ffs.Divide(fs.Value_array[0], '/'); //some laptops formats could be dd/mm/yyyy or mm/dd/yyyy. //so lets see if the first value is greater than 12 so that we know its days, not month int d_or_m = Convert.ToInt32(ffs.Value_array[0]); if (d_or_m > 12)//the first value is days , not month, so forcefully change { month = Convert.ToInt32(ffs.Value_array[1]); day = Convert.ToInt32(ffs.Value_array[0]); } else//the first value is months, not days { month = Convert.ToInt32(ffs.Value_array[0]); day = Convert.ToInt32(ffs.Value_array[1]); } ///////////////////////////////////////////////// year = Convert.ToInt32(ffs.Value_array[2]); //////////////////////////////////////////////// //SECOND OF FIRST SPLIT if (i == 1) { if (fs.Value_array[i] != "") { Split sfs = new Split(); sfs.Divide(fs.Value_array[i], ':'); hour = Convert.ToInt32(sfs.Value_array[0]); minute = Convert.ToInt32(sfs.Value_array[1]); second = Convert.ToInt32(sfs.Value_array[2]); } } ////////////////////////////////////////////////// } } DateTime dt = new DateTime(year, month, day, hour, minute, second); return_date = dt.ToString(format); } return(return_date); }
/// <summary> /// for adding details into the database. /// </summary> /// <param name="table">The name of the table</param> /// <param name="values">the values to be entered using comma as the separator must be exactly the number /// of columns entered. this is of type array, so values should be inputed like an array /// e.g {"value1","value2","value3"} /// </param> /// <param name="columns">the columns needed, should be seperated with comma. e.g : name,id... /// or you can leave it empty . /// </param> public void Add(string table, string[] values, string columns = "") { //filter values Filter filter = new Filter(); this.table = table; #region CHECK IF THE column is empty //CHECK IF THE column is empty string col = string.Empty; if (filter.Trim(columns) == "") { col = ""; } else { //COLUMN HAS SOME VALUES,make sure the number of columns are equal to the number of values #region handling the columns stuff Split split = new Split(); //divide split.Divide(columns, ','); //set the start first, we'll accomplish this at the end, under the looping ish. //col = (bla,bla,bla,bla,bla); col = "("; //now store for (int i = 0; i < split.Value_array.Length; i++) //keep adding to the col variable with comma { //actually this is unecessary work, but it's just to make sure if (filter.Trim(split.Value_array[i]) != "") { //NOW THIS IS WHAT MAKES THE CODE USEFUL /* * SOMEONE MIGHT PUT COMMA AT THE END OR IN BETWEEN BY MISTAKE, * AND THAT COULD DESTROY EVERYTHING, THEN THAT * STUPID ERROR STARTS SHOWING AGAIN. * THIS PREVENTS THAT :) */ //ADD THE VALUE //CHECK IF THE VALUE ISN'T THE LAST ARRAY SO THAT WE DON'T PUT COMMA IN THE LAST VALUE int calc = split.Value_array.Length - i; if (calc == 1) {//its the last value, don't put the comma col += split.Value_array[i]; } else { col += split.Value_array[i] + " , "; } } else {//do nothing } } col += ") "; } #endregion #endregion #region FILTER THE VALUES ISH PROPERLY TO INSERT INTO THE QUERY //FILTER THE VALUES ISH PROPERLY TO INSERT INTO THE QUERY /* * THERE COULD BE SOME CONDITIONS. * the string[] values variable holds values in string, so even if you input a sql functional value like "NOW()" * it will be passed as a string, which would not turn out good, if we don't handle it properly. * so we're going to set up an array that holds functional values to determine when we would remove string nature * what i mean is we'll create an array that holds values of functions in sql command, so when we are looking through * the string[] value values, we can check if any functional sql value is part of the values, by comparing the values * with the values inside the other array that stores functional values */ //THE ARRAY THAT STORES THE FUNCTIONAL VALUES, any sql functional values used in queries should be added here. :) // string[] func_val = { "NOW()" }; //THE VARIABLE THAT WILL STORE UP string[] value values string val = ""; //for storing string _func_or_val = ""; string comma = ","; int j = 0; //ORDINARY VALUES // string ord_val = ""; for (int i = 0; i < values.Length; i++) { //start looping through the values to store properly //NOW WHILE CHECKING THROUGH THE VALUES, ALSO CHECK FOR FUNCTIONAL VALUES TO REMOVE THE QUOTES for (j = 0; j < func_val.Length; j++) { //STORE THE VALUE //check if it's the last value int calc = values.Length - i; if (calc == 1) //its the last value, remove the comma { comma = ""; } else { comma = ","; } if (filter.Trim(values[i]).ToUpper() == filter.Trim(func_val[j].ToUpper()) /*making sure they're all uppercase to perfect comparising*/) { //it's a functional value, remove the quotes _func_or_val += filter.Trim(values[i]) + comma; } else { //ITS NOT A FUNCTIONAL value, leave the quotes _func_or_val += "'" + filter.Trim(values[i]) + "'" + comma; } } //reset j to keep checking if the values match the functional values. j = 0; } #endregion //FOR THE VALUES, //ADD THE WHOLE RESULTS TOGETHER. val = _func_or_val; string q = "INSERT INTO " + this.table + col + " VALUES(" + val + ")"; //CALL IN THE QUERYing method this.Quering(insert, q); }