Ejemplo n.º 1
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            if (checkValues())
            {
                foreach (object item in checkedListBox1.CheckedItems)
                {
                    Notification_Dep_user dep = (Notification_Dep_user)item;

                    if (!string.IsNullOrEmpty(dep.DepartmentCode))
                    {
                        int      nStartId = AMP_Common.getRecentSnapshotID(dtPickerStart.Value);
                        int      nEndId   = AMP_Common.getRecentSnapshotID(dtPickerEnd.Value);
                        DateTime dtStart  = AMP_Common.getRecentSnapshotDateTime(dtPickerStart.Value);
                        DateTime dtEnd    = AMP_Common.getRecentSnapshotDateTime(dtPickerEnd.Value);

                        string strEventID = txtEventID.Text.ToString();

                        if (!string.IsNullOrEmpty(strEventID))
                        {
                            EventAmendmentBLL.checkAmendmentManually(dep.DepartmentCode, nStartId, nEndId, strEventID);
                        }
                        else
                        {
                            EventAmendmentBLL.checkAmendmentManually(dep.DepartmentCode, nStartId, nEndId);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static List <Notification_Dep_user> getDepartments()
        {
            List <Notification_Dep_user> depts = new List <Notification_Dep_user>();

            SqlConnection conn = new SqlConnection(strEBMSConn);

            try
            {
                conn.Open();

                string strSQL = "SELECT  Noti_Dep_Code,Noti_Dep_Desc, Dep_User_Id, Noti_Method, EmailAddress  FROM  Noti_Dept dep  where Status='1' and (Dep_User_Id<>'' or EmailAddress<>'')";

                SqlCommand comm = new SqlCommand(strSQL, conn);
                comm.CommandTimeout = nCommandTimeOut;

                SqlDataAdapter da = new SqlDataAdapter(comm);
                DataTable      dt = new DataTable();

                da.Fill(dt);
                da.FillSchema(dt, SchemaType.Source);

                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["Noti_Dep_Code"] != DBNull.Value && (dr["Dep_User_Id"] != DBNull.Value || dr["EmailAddress"] != DBNull.Value))
                        {
                            Notification_Dep_user Noti = new Notification_Dep_user();
                            Noti.DepartmentCode = dr["Noti_Dep_Code"].ToString();
                            Noti.DepartmentDesc = dr["Noti_Dep_Desc"].ToString();
                            Noti.NotifiMethod   = dr["Noti_Method"].ToString();
                            Noti.UserId         = dr["Dep_User_Id"].ToString();
                            Noti.EmailAddress   = dr["EmailAddress"].ToString();
                            depts.Add(Noti);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                AMP_Common.sendException(ex, System.Reflection.MethodBase.GetCurrentMethod().Name, strEmailFrom, strEmailTo, ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(depts);
        }
Ejemplo n.º 3
0
        private static void CheckEvent_Amendment(List <EventInfo> lstEvent, Notification_Dep_user dep, int nCurrSnapshotId, int nPrevSnapshotId)
        {
            if (lstEvent.Count > 0)
            {
                AMP_Common.initDB(nCurrSnapshotId, nPrevSnapshotId, lstEvent);
                AMP_EventDAL.dep = dep;

                foreach (EventInfo evt in lstEvent)
                {
                    AMP_EventDAL.evt  = evt;
                    AMP_EventDAL.eMsg = new EventAccountMessage();

                    if (AMP_EventDAL.checkEventCancelled())
                    {
                        AMP_EventDAL.SendMSG();
                    }
                    else if (AMP_EventDAL.checkEventNewOrShortLead())
                    {
                        AMP_EventDAL.SendMSG();
                    }
                    else if (evt.Status != "80" && evt.Status != "86" && AMP_EventDAL.rule.ShortLeadStatusList.IndexOf(evt.Status.ToString()) > -1)
                    {
                        AMP_EventDAL.getEventAmendmentHead();
                        AMP_EventDAL.checkEventStatusChange();
                        AMP_EventDAL.checkEventUpdate();
                        AMP_EventDAL.checkEventNotesChange();

                        EventAccountMessage function_amendment = checkFunction_Amendment(evt, dep, nCurrSnapshotId, nPrevSnapshotId);

                        if (function_amendment.FuncUpdated)
                        {
                            AMP_EventDAL.eMsg.EventUpdated = true;
                            AMP_EventDAL.eMsg.MSGText     += function_amendment.MSGText;
                            AMP_EventDAL.eMsg.MSGHTML     += function_amendment.MSGHTML;
                        }

                        AMP_EventDAL.checkDocumentChange();
                        if (AMP_EventDAL.eMsg.EventUpdated)
                        {
                            AMP_EventDAL.SendMSG();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static Notification_Dep_user getDepartment(string strDeptCode)
        {
            Notification_Dep_user dept = new Notification_Dep_user();

            SqlConnection conn = new SqlConnection(strEBMSConn);

            try
            {
                conn.Open();

                string strSQL = "SELECT  Noti_Dep_Code,Noti_Dep_Desc, Dep_User_Id, Noti_Method, EmailAddress  FROM  Noti_Dept  where (Dep_User_Id<>'' or EmailAddress<>'') and Noti_Dep_Code=@departmentcode";

                SqlCommand comm = new SqlCommand(strSQL, conn);
                comm.Parameters.Add("@departmentcode", SqlDbType.VarChar, 20).Value = strDeptCode;
                comm.CommandTimeout = nCommandTimeOut;

                SqlDataReader dr = comm.ExecuteReader();

                if (dr.Read())
                {
                    if (dr["Noti_Dep_Code"] != DBNull.Value && (dr["Dep_User_Id"] != DBNull.Value || dr["EmailAddress"] != DBNull.Value))
                    {
                        dept.DepartmentCode = dr["Noti_Dep_Code"].ToString();
                        dept.DepartmentDesc = dr["Noti_Dep_Desc"] == DBNull.Value ? "" : dr["Noti_Dep_Desc"].ToString();
                        dept.NotifiMethod   = dr["Noti_Method"].ToString();
                        dept.UserId         = dr["Dep_User_Id"].ToString();
                        dept.EmailAddress   = dr["EmailAddress"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                AMP_Common.sendException(ex, System.Reflection.MethodBase.GetCurrentMethod().Name, strEmailFrom, strEmailTo, ex.Message);
            }
            finally
            {
                conn.Close();
            }

            return(dept);
        }
Ejemplo n.º 5
0
        public static void SaveErrorLog(AMP_Rules rule, EventInfo evt, Function_Info finfo, Notification_Dep_user dep, int nPrevSnapshotId, int nCurrSnapshotId, string strFunctionName, string logText)
        {
            SqlConnection conn = new SqlConnection(strEBMSConn);

            try
            {
                conn.Open();

                string strSQL = " insert into AMP_Error_Logs (RuleCode ,RuleName ,SnapshotPreviousId ,SnapshotCurrentId ,EventId ,Function_Id ,DepartmentCode ,DepartmentDesc ,Dep_User_Id ,EmailAddress ,RunDate ,Function_Name ,logMessage) ";
                strSQL += " values ";
                strSQL += " (@rulecode, @rulename,@prevsnapshotid, @currsnapshotid,@eventid, @functionid, @deptcode,@deptdesc, @deptuser, @emailaddress, @rundate,@funcname, @errmsg ) ";
                SqlCommand comm = new SqlCommand(strSQL, conn);

                comm.Parameters.Add("@rulecode", SqlDbType.VarChar, 20).Value  = rule.RuleId;
                comm.Parameters.Add("@rulename", SqlDbType.VarChar, 255).Value = rule.Rule_Name;
                comm.Parameters.Add("@prevsnapshotid", SqlDbType.Int).Value    = nPrevSnapshotId;
                comm.Parameters.Add("@currsnapshotid", SqlDbType.Int).Value    = nCurrSnapshotId;
                comm.Parameters.Add("@eventid", SqlDbType.Int).Value           = evt.EventId;
                if (finfo != null)
                {
                    comm.Parameters.Add("@functionid", SqlDbType.Int).Value = finfo.FuncId;
                }
                else
                {
                    comm.Parameters.Add("@functionid", SqlDbType.Int).Value = 0;
                }
                if (dep != null)
                {
                    comm.Parameters.Add("@deptcode", SqlDbType.VarChar, 20).Value      = dep.DepartmentCode;
                    comm.Parameters.Add("@deptdesc", SqlDbType.VarChar, 255).Value     = dep.DepartmentDesc;
                    comm.Parameters.Add("@deptuser", SqlDbType.VarChar, 20).Value      = dep.UserId;
                    comm.Parameters.Add("@emailaddress", SqlDbType.VarChar, 200).Value = dep.EmailAddress;
                }
                else
                {
                    comm.Parameters.Add("@deptcode", SqlDbType.VarChar, 20).Value      = "";
                    comm.Parameters.Add("@deptdesc", SqlDbType.VarChar, 255).Value     = "";
                    comm.Parameters.Add("@deptuser", SqlDbType.VarChar, 20).Value      = "";
                    comm.Parameters.Add("@emailaddress", SqlDbType.VarChar, 200).Value = "";
                }
                comm.Parameters.Add("@rundate", SqlDbType.DateTime).Value     = DateTime.Now;
                comm.Parameters.Add("@funcname", SqlDbType.VarChar, 50).Value = strFunctionName;
                comm.Parameters.Add("@errmsg", SqlDbType.NText).Value         = logText;
                comm.CommandTimeout = nCommandTimeOut;

                comm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                sendException(ex, "SaveErrorLog", "*****@*****.**", "*****@*****.**", "EBMS Amendment Runtime Error");
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 6
0
        public static void sendErrorException(string strEmailFrom, string strEmailTo, string strSubject, AMP_Rules rule, EventInfo evt, Function_Info finfo, Notification_Dep_user dep, int nPrevSnapshotId, int nCurrSnapshotId, string strFunctionName, string logText)
        {
            SaveErrorLog(rule, evt, finfo, dep, nPrevSnapshotId, nCurrSnapshotId, strFunctionName, logText);
            string strBody = "";

            strBody  = "There's error with function " + strFunctionName + ". <br/><br/> ";
            strBody  = "Department: " + dep.DepartmentDesc + " (" + dep.DepartmentCode + ") <br/> ";
            strBody  = "Department User: "******" /" + dep.EmailAddress + "<br/> ";
            strBody  = "Rule: " + rule.Rule_Name + " (" + rule.RuleId + ")  <br/> ";
            strBody  = "Snapshot Previous:" + getSnapshotDateTimeFromId(nPrevSnapshotId) + " (" + nPrevSnapshotId.ToString() + ") <br/>";
            strBody  = "Snapshot Current:" + getSnapshotDateTimeFromId(nCurrSnapshotId) + " (" + nCurrSnapshotId.ToString() + ") <br/>";
            strBody  = "Event: " + evt.EventDesc + " (" + evt.EventId.ToString() + ") <br/>";
            strBody  = "Function: " + finfo.FuncDesc + " <br/><br/>";
            strBody += "Error Messages:<br/> " + logText;

            AMP_Notification.sendEmail(strEmailFrom, strEmailTo, strSubject, strBody);
        }
Ejemplo n.º 7
0
        private static EventAccountMessage checkOrder_Amendment(EventInfo evt, Function_Info finfo, Notification_Dep_user dep, int nCurrSnapshotId, int nPrevSnapshotId)
        {
            AMP_OrderDAL.dep   = dep;
            AMP_OrderDAL.evt   = evt;
            AMP_OrderDAL.finfo = finfo;
            AMP_OrderDAL.nSnapshotCurrentID  = nCurrSnapshotId;
            AMP_OrderDAL.nSnapshotPreviousID = nPrevSnapshotId;

            EventAccountMessage order_amendment_msg = new EventAccountMessage();

            List <Order_Info> lstCurrentOrders = AMP_OrderDAL.getCurrentFunctionOrders();

            foreach (Order_Info ord in lstCurrentOrders)
            {
                AMP_OrderDAL.oinfo = ord;

                AMP_OrderDAL.getOrderHeader();

                if (finfo.isOrdersChange)
                {
                    AMP_OrderDAL.checkOrderChange();
                }

                if (finfo.isOrdersNotesChange)
                {
                    AMP_OrderDAL.checkOrderNotesChange();
                }

                if (finfo.isOrderItemsChange)
                {
                    AMP_OrderDAL.checkOrderItemChange();
                }

                if (finfo.isOrderItemsNotesChange)
                {
                    AMP_OrderDAL.checkOrderItemNotesChange();
                }

                if (AMP_OrderDAL.eMsg.OrderUpdated)
                {
                    order_amendment_msg.OrderUpdated = true;
                    order_amendment_msg.MSGText     += AMP_OrderDAL.eMsg.MSGText;
                    order_amendment_msg.MSGHTML     += AMP_OrderDAL.eMsg.MSGHTML;
                }
            }

            List <Order_Info> lstDelOrders = AMP_OrderDAL.getDeletedOrders();

            foreach (Order_Info delord in lstDelOrders)
            {
                AMP_OrderDAL.oinfo = delord;

                AMP_OrderDAL.getOrderHeader();

                AMP_OrderDAL.checkDeltedOrderItems();

                if (AMP_OrderDAL.eMsg.OrderUpdated)
                {
                    order_amendment_msg.OrderUpdated = true;
                    order_amendment_msg.MSGText     += AMP_OrderDAL.eMsg.MSGText;
                    order_amendment_msg.MSGHTML     += AMP_OrderDAL.eMsg.MSGHTML;
                }
            }
            return(order_amendment_msg);
        }
Ejemplo n.º 8
0
        private static EventAccountMessage checkFunction_Amendment(EventInfo evt, Notification_Dep_user dep, int nCurrSnapshotId, int nPrevSnapshotId)
        {
            AMP_FunctionDAL.dep = dep;
            AMP_FunctionDAL.evt = evt;
            AMP_FunctionDAL.nSnapshotCurrentID  = nCurrSnapshotId;
            AMP_FunctionDAL.nSnapshotPreviousID = nPrevSnapshotId;

            EventAccountMessage function_amendment = new EventAccountMessage();

            //List<Function_Info> lstFunctions = AMP_FunctionDAL.getAll_Related_Function();
            List <Function_Info> lstFunctions = AMP_FunctionDAL.getCurrentChangeFunctions();

            //loop functions
            foreach (Function_Info function in lstFunctions)
            {
                AMP_FunctionDAL.finfo = function;

                AMP_FunctionDAL.getFunctionHeader();

                if (function.isFunctionChange)
                {
                    AMP_FunctionDAL.checkFunctionChange();
                }

                if (function.isFunctionNotesChange)
                {
                    AMP_FunctionDAL.checkFunctionNotesChange();
                }

                if (function.isFunctionNotesChange)
                {
                    AMP_FunctionDAL.checkFunctionSignage();
                }

                EventAccountMessage order_amendment = new EventAccountMessage();
                if (function.isOrdersChange || function.isOrdersNotesChange || function.isOrderItemsChange || function.isOrderItemsNotesChange)
                {
                    order_amendment = checkOrder_Amendment(evt, function, dep, nCurrSnapshotId, nPrevSnapshotId);
                }


                if (AMP_FunctionDAL.eMsg.FuncUpdated || order_amendment.OrderUpdated)
                {
                    function_amendment.FuncUpdated = true;
                    function_amendment.MSGText    += AMP_FunctionDAL.eMsg.MSGText + order_amendment.MSGText;
                    function_amendment.MSGHTML    += AMP_FunctionDAL.eMsg.MSGHTML + order_amendment.MSGHTML;
                }
            }

            List <Function_Info> lstDeletedFunctions = AMP_FunctionDAL.getDelFunctions();

            foreach (Function_Info function in lstDeletedFunctions)
            {
                AMP_FunctionDAL.finfo = function;

                AMP_FunctionDAL.getFunctionHeader();

                AMP_FunctionDAL.getDeletedFunctionItems();

                if (AMP_FunctionDAL.eMsg.FuncUpdated)
                {
                    function_amendment.FuncUpdated = true;
                    function_amendment.MSGText    += AMP_FunctionDAL.eMsg.MSGText;
                    function_amendment.MSGHTML    += AMP_FunctionDAL.eMsg.MSGHTML;
                }
            }

            return(function_amendment);
        }
Ejemplo n.º 9
0
        public static void checkAmendmentManually(string strDepartmentCode, int nPrevSnapshotId, int nCurrSnapshotId, string strEventCode = "All")
        {
            Notification_Dep_user dep = AMP_DepartmentDAL.getDepartment(strDepartmentCode);

            DateTime dtSnapshotCurrent, dtSnapshotPrevious;

            dtSnapshotPrevious = AMP_Common.getSnapshotDateTimeFromId(nPrevSnapshotId);
            dtSnapshotCurrent  = AMP_Common.getSnapshotDateTimeFromId(nCurrSnapshotId);
            DateTime dtNow = DateTime.Now;

            int  nTryTimes        = 0;
            bool isSnapshotFinish = false;

            isSnapshotFinish = AMP_Common.isSnapshotFinished(dtNow);

            while (!isSnapshotFinish)
            {
                //delay for 30 seconds then get the status again.
                System.Threading.Thread.Sleep(1000 * 30);


                isSnapshotFinish = AMP_Common.isSnapshotFinished(dtNow);
                nTryTimes       += 1;

                //if tried for 40 times (20 minutes) still fail, then fail.
                if (nTryTimes >= 40)
                {
                    break;
                }
            }

            if (isSnapshotFinish)
            {
                AMP_Rules common_rule = AMP_RulesDAL.getCommonEventRule();

                AMP_EventDAL.dep     = dep;
                AMP_EventDAL.rule    = common_rule;
                AMP_RulesDAL.rule    = common_rule;
                AMP_FunctionDAL.rule = common_rule;
                AMP_OrderDAL.rule    = common_rule;

                AMP_EventDAL.dtSnapshotCurrent  = dtSnapshotCurrent;
                AMP_EventDAL.dtSnapshotPrevious = dtSnapshotPrevious;

                AMP_EventDAL.nSnapshotCurrentID  = nCurrSnapshotId;
                AMP_EventDAL.nSnapshotPreviousID = nPrevSnapshotId;

                AMP_RulesDAL.nSnapshotCurrentID  = nCurrSnapshotId;
                AMP_RulesDAL.nSnapshotPreviousID = nPrevSnapshotId;

                AMP_RulesDAL.dtSnapshotCurrent  = dtSnapshotCurrent;
                AMP_RulesDAL.dtSnapshotPrevious = dtSnapshotPrevious;

                List <EventInfo> lstEvent = new List <EventInfo>();

                if (strEventCode == "All")
                {
                    lstEvent = AMP_EventDAL.getAllEventsFromRule();
                }
                else
                {
                    EventInfo evt = AMP_EventDAL.getEventInfo(int.Parse(strEventCode));
                    lstEvent.Add(evt);
                }

                CheckEvent_Amendment(lstEvent, dep, nCurrSnapshotId, nPrevSnapshotId);
                AMP_Notification.sendEmail("*****@*****.**", "*****@*****.**", "status of running for " + (DateTime.Now.Subtract(dtNow).TotalSeconds), " seconds. Start at:" + dtNow.ToString("dd/MM/yyyy HH:mm") + " finish at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"));
            }
            else
            {
                AMP_Notification.sendEmail("*****@*****.**", "*****@*****.**", "Snapshot is hanging the process. Start from:" + dtNow.ToString("dd/MM/yyyy HH:mm") + " finish at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "Tried very hard for 4 times, the process of snapshot is still not finished yet. I gave up. You can you do it, no can no bibi.");
            }
        }