using Ease.Core.DataAccess; using HRM.BO; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.DirectoryServices.Protocols; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HRM.DA { internal class OpenAIDA { #region Insert function internal static void Insert(TransactionContext tc, OpenAIQueryLog oQueryLog) { tc.ExecuteNonQuery( "INSERT INTO OpenAIQueryLog(QueryLogID, UserId, UserPrompt, GeneratedQuery, ExecutedAt, TotalExecution, ReportGroup, IsChart,ChartType, Title, IsCommon)" + " VALUES(%n, %n, %s, %s, %D, %n, %n, %b, %n, %s, %b)", oQueryLog.ID, oQueryLog.UserId, oQueryLog.UserPrompt, oQueryLog.GeneratedQuery, oQueryLog.ExecutedAt, oQueryLog.TotalExecution, (int)oQueryLog.ReportGroup, oQueryLog.IsChart, (int)oQueryLog.ChartType, oQueryLog.Title, oQueryLog.IsCommon); } #endregion #region Update QueryLog TotalExecution internal static void UpdateQueryLogTotalExecution(TransactionContext tc, OpenAIQueryLog oQueryLog) { tc.ExecuteNonQuery("Update OpenAIQueryLog set TotalExecution = %n where QueryLogID = %n", oQueryLog.TotalExecution, oQueryLog.ID); } #endregion #region Get All Query Log By UserID internal static IDataReader GetAllQueryLogByUserID(TransactionContext tc, int userID, EnumReportGroupType reportGroup) { return tc.ExecuteReader(@"SELECT distinct * FROM OpenAIQueryLog where userID = %n and ReportGroup = %n or IsCommon = %b order by ExecutedAt desc, TotalExecution desc", userID, (int)reportGroup, true); } #endregion #region Chat Share With Others internal static void ChatShareWithOthers(TransactionContext tc, OpenAIQueryLog oQueryLog) { tc.ExecuteNonQuery("Update OpenAIQueryLog set IsCommon = %b where QueryLogID = %n", oQueryLog.IsCommon, oQueryLog.ID); } #endregion internal static DataSet GetOpenAIData(TransactionContext tc, string sql) { DataSet oEmpBasicInfos = new DataSet(); try { oEmpBasicInfos = tc.ExecuteDataSet(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return oEmpBasicInfos; } internal static DataTable GetColumnDefinitions(TransactionContext tc, EnumReportGroupType reportGroupType) { DataTable oColumnDefinition = new DataTable(); string sql = ""; try { sql = SQLParser.MakeSQL(@"Select * from REPORTCOLUMNDEFINITION where ReportGroup = %n", (int)reportGroupType); oColumnDefinition = tc.ExecuteDataTable(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return oColumnDefinition; } internal static DataTable GetAllType(TransactionContext tc, EnumReportGroupType reportGroupType) { DataTable oColumnDefinition = new DataTable(); string sql = ""; try { if (reportGroupType == EnumReportGroupType.Salary) { sql = SQLParser.MakeSQL("select distinct(Head) as Head from vwEmployeeSalary"); } else if(reportGroupType == EnumReportGroupType.Leave) { sql = SQLParser.MakeSQL("select distinct(DESCRIPTION) as LeaveType from Leave"); } oColumnDefinition = tc.ExecuteDataTable(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return oColumnDefinition; } internal static DataTable GetColumnRelations(TransactionContext tc, EnumReportGroupType reportGroupType) { DataTable oColumnRelations = new DataTable(); string sql = ""; try { sql = SQLParser.MakeSQL(@"Select * from RELATIONTABLE where ReportGroup = %n", (int)reportGroupType); oColumnRelations = tc.ExecuteDataTable(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return oColumnRelations; } internal static IDataReader TotalOpenAICall(TransactionContext tc) { return tc.ExecuteReader("SELECT COUNT(*) FROM OpenAIQueryLog"); } } }