public static DataTable GetCustomTable(DataTable dataTable, string tempTableName, int userId) { DataTable rDataTable = new DataTable(tempTableName); CommonConnection connection = new CommonConnection(); try { if (tempTableName.Trim() != string.Empty) { //string strDelete = string.Format("Delete {0} Where UserId={1}", tempTableName, userId); string strDelete = string.Format("Delete {0} ", tempTableName, userId); connection.ExecuteNonQuery(strDelete); } String sql = "Select top (0) * from " + tempTableName; var tableStructure = connection.GetDataTable(sql); foreach (DataRow rowWithValue in dataTable.Rows) { tableStructure.Rows.Add(CustomDataRow(tableStructure, rowWithValue, userId)); } rDataTable = tableStructure; } catch (Exception) { throw; } finally { connection.Close(); } return rDataTable; }
public Result SavePesonalDetails(PersonalDetails profileObj) { Result result = new Result(); var db = new CommonConnection(); var sql = ""; if (profileObj.PersonalDetailsId == 0) { sql = sqlBuilder.GetInsertQuery<PersonalDetails>(profileObj); db.ExecuteNonQuery(sql); } return result; }
public static DataTable GetCustomTable(DataTable dataTable, string tempTableName, int userId) { DataTable rDataTable = new DataTable(tempTableName); CommonConnection connection = new CommonConnection(); try { if (tempTableName.Trim() != string.Empty) { string strDelete = ""; if (userId > 0) { strDelete = string.Format("Delete {0} Where UserId={1}", tempTableName, userId); } else if (userId == 0) { strDelete = ""; } else if (userId == -1) { strDelete = string.Format("Delete {0} ", tempTableName); } if (strDelete != "") { connection.ExecuteNonQuery(strDelete); } } String sql = "Select top (0) * from " + tempTableName; var tableStructure = connection.GetDataTable(sql); foreach (DataRow rowWithValue in dataTable.Rows) { tableStructure.Rows.Add(CustomDataRow(tableStructure, rowWithValue, userId)); } rDataTable = tableStructure; } catch (Exception) { throw; } finally { connection.Close(); } return(rDataTable); }
public string UpdateMenuSorting(List <Menu> menuList, User user) { string res = ""; CommonConnection con = new CommonConnection(); try { var quary = ""; foreach (var menu in menuList) { quary += string.Format(" Update Menu Set SorOrder = {0} where MenuId = {1};", menu.SortOrder, menu.MenuId); } if (quary != "") { con.ExecuteNonQuery(quary); } res = Operation.Success.ToString(); } catch (Exception ex) { res = Operation.Failed.ToString(); } return(res); }
//public string GenerateEntityId(string prefix, string suffix, bool useSeperator, CommonConnection connection, string enitityName,int transectionResetType) //{ // //transectionResetType = 1 then Yearly, 2 then Monthly, 3 then Daily // string idCode = ""; // var idPolicy = GetIdPolicy(connection, enitityName); // if (prefix == "") // { // prefix = idPolicy.Prefix.Trim(); // } // if (suffix == "") // { // suffix =idPolicy.Suffix==null?"": idPolicy.Suffix.Trim(); // } // if (idPolicy.LastNumber < 0) // { // idPolicy.LastNumber = 0; // } // if (transectionResetType == 1) // { // if (idPolicy.YearName == DateTime.Now.Year) // { // //idPolicy.LastNumber = 0; // } // else // { // idPolicy.LastNumber = 0; // } // } // else if (transectionResetType == 2) // { // if (idPolicy.YearName == DateTime.Now.Year && idPolicy.MonthName == DateTime.Now.Month) // { // //idPolicy.LastNumber = 0; // } // else // { // idPolicy.LastNumber = 0; // } // } // else // { // if (idPolicy.YearName == DateTime.Now.Year && idPolicy.MonthName == DateTime.Now.Month && // idPolicy.DateName == DateTime.Now.Day) // { // //idPolicy.LastNumber = 0; // } // else // { // idPolicy.LastNumber = 0; // } // } // string newNumber = GenerateIDNumber(idPolicy.StartNumber, idPolicy.NumberDigit, idPolicy.LastNumber, enitityName, connection); // if (useSeperator == false) // { // idCode = prefix + newNumber + suffix; // } // else // { // idCode = prefix + "-" + newNumber + "-" + suffix; // } // return idCode.Trim(); //} //private IDPolicy GetIdPolicy(CommonConnection connection, string enitityName) //{ // string quary = string.Format("Select * from IDPolicy where EntityName = '{0}'", enitityName); // return connection.Data<IDPolicy>(quary).FirstOrDefault(); //} private string GenerateIDNumber(int startNumber, int digit, int lastNumber, string entityName, CommonConnection connection) { string num = ""; var length = (lastNumber + 1).ToString().Length; var diff = digit - length; if (diff < 0) { try { num = "000001"; startNumber = startNumber + 1; lastNumber = 1; string quary = string.Format(UPDATE_IDPOLICY_WITH_STNUMBER, startNumber, lastNumber, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, entityName); connection.ExecuteNonQuery(quary); } catch { connection.RollBack(); } } else { for (int i = 0; i < diff; i++) { num += "0"; } num = num + (lastNumber + 1); try { lastNumber = lastNumber + 1; string quary = string.Format(UPDATE_IDPOLICY, lastNumber, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, entityName); connection.ExecuteNonQuery(quary); } catch { connection.RollBack(); } } return num; }