Esempio n. 1
0
        public void Calculate(string rnno, string cond, List <ColumnInfo> personalParameters, string perd)
        {
            try
            {
                List <vw_employment> lstStaff = GetPersonals(personalParameters, cond);

                //目前只分配
                List <tprsalhi> lstSalaryHistory = GetSalaryHistory(rnno);

                log.LogInfoWithLevel("Start calculate salary to cumulation.", Log_LoggingLevel.Normal);
                log.LogInfoWithLevel("Period:" + perd + ".", Log_LoggingLevel.Normal);
                log.LogInfoWithLevel("Run No:" + rnno + ".", Log_LoggingLevel.Normal);
                log.LogInfoWithLevel("Total " + lstStaff.Count.ToString() + " staff(s) to calculate.", Log_LoggingLevel.Normal);

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(1, 0, 0)))
                {
                    for (int i = 0; i < lstStaff.Count; i++)
                    {
                        log.LogInfoWithLevel("Start to calculate staff[" + lstStaff[i].sfid + "," + lstStaff[i].ntnm + "].", Log_LoggingLevel.Normal);

                        //Delete first
                        List <ColumnInfo> runParameter = new List <ColumnInfo>()
                        {
                            new ColumnInfo()
                            {
                                ColumnName = "rnno", ColumnValue = rnno
                            },
                            new ColumnInfo()
                            {
                                ColumnName = "emno", ColumnValue = lstStaff[i].emno
                            }
                        };
                        DoMultiDelete <tpraccalc>(runParameter);

                        List <tprsalhi> lstCurrentSalaryHistory = lstSalaryHistory.Where(p => p.emno == lstStaff[i].emno).ToList();

                        CalculateOneByOne(lstStaff[i], lstCurrentSalaryHistory);

                        log.LogInfoWithLevel("End to calculate staff[" + lstStaff[i].sfid + "," + lstStaff[i].ntnm + "].", Log_LoggingLevel.Normal);
                        log.LogInfoWithLevel(" ", Log_LoggingLevel.Normal);
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public Exception_ErrorMessage CheckData(int rownum, string checkDesc, String fun)
        {
            log.LogInfoWithLevel("Start: " + MethodBase.GetCurrentMethod().Name + ".", Log_LoggingLevel.Admin);

            try
            {
                Type       t      = dal.GetType();
                MethodInfo method = t.GetMethod(fun);
                DataSet    ds     = (DataSet)method.Invoke(dal, new object[] { });

                if (ds.Tables[0].Rows.Count > 0)
                {
                    //string errDetails = JsonHelper.toJson(ds.Tables[0], ds.Tables[0].Rows.Count);
                    //log.LogInfoWithLevel(checkDesc + " fail. ", Log_LoggingLevel.Admin);
                    //log.LogInfoWithLevel("Total " + ds.Tables[0].Rows.Count.ToString() + " record(s) fail.", Log_LoggingLevel.Admin);
                    //string fileName = (new UtilLog()).LogInfoToNewFile(errDetails, CurrentPageInfo.PageId, "[" + CurrentPageInfo.PageName + "]Data check fail at " + UtilDatetime.FormatDateTime3(Function.GetCurrentTime()) + " by " + Function.GetCurrentUser());
                    //log.LogInfoWithLevel("Please check error details in  " + fileName + ".", Log_LoggingLevel.Admin);

                    string fileName = string.Empty;
                    AddIntoResultDT(rownum.ToString(), checkDesc, "Fail.Please check " + fileName, fileName);
                }
                else
                {
                    AddIntoResultDT(rownum.ToString(), checkDesc, "Success", string.Empty);
                    log.LogInfoWithLevel("End: " + MethodBase.GetCurrentMethod().Name + "[successfully].", Log_LoggingLevel.Admin);
                }
                return(Exception_ErrorMessage.NoError);
            }
            catch (UtilException ex)
            {
                AddIntoResultDT(rownum.ToString(), checkDesc, "Error." + ex.Message, string.Empty);
                log.LogInfoWithLevel("End: " + MethodBase.GetCurrentMethod().Name + "[fail]. ", Log_LoggingLevel.Admin);
                //throw ex;
            }
            catch (Exception ex)
            {
                AddIntoResultDT(rownum.ToString(), checkDesc, "Error." + ex.Message, string.Empty);
                log.LogInfoWithLevel("End: " + MethodBase.GetCurrentMethod().Name + "[fail]. Error:" + ex.Message + ".", Log_LoggingLevel.Admin);
            }

            return(Exception_ErrorMessage.NoError);
        }
Esempio n. 3
0
        public static SqlDataReader ExecuteReader(UtilLog log, string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
        {
            //Create the command and connection
            SqlCommand cmd = new SqlCommand();
            SqlConnection conn = new SqlConnection(connectionString);
            log.LogInfoWithLevel(connectionString, Log_LoggingLevel.Admin);
            try
            {
                //Prepare the command to execute
                PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);

                //Execute the query, stating that the connection should close when the resulting datareader has been read
                SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                cmd.Parameters.Clear();
                return rdr;

            }
            catch
            {

                //If an error occurs close the connection as the reader will not be used and we expect it to close the connection
                conn.Close();
                throw;
            }
        }