public MetaResponse getInitialData(string COMPANY_NO_BOX, string REQ_SEQ)
 {
     try
     {
         string         msg = "";
         REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
         DataTable      dt = DAL_REQUEST_DETAIL.Search(COMPANY_NO_BOX, REQ_SEQ, out msg);
         response.Data = Utility.Utility_Component.DtToJSon(dt, "Initial Data");
         if (dt.Rows.Count > 0)
         {
             response.Status = 1;
         }
         else
         {
             if (msg == "")
             {
                 response.Status  = 1;
                 response.Message = "There is no data to display.";
             }
             else
             {
                 response.Status  = 0;
                 response.Message = msg;
             }
         }
         return(response);
     }
     catch (Exception ex)
     {
         return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
     }
 }
 public MetaResponse GetSubProgramLists()
 {
     try
     {
         string         msg = "";
         REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
         DataTable      dt = DAL_REQUEST_DETAIL.GetSubProgramLists(out msg);
         response.Data = Utility.Utility_Component.DtToJSon(dt, "Usage Application : Sub Program Lists");
         if (dt.Rows.Count > 0)
         {
             response.Status = 1;
         }
         else
         {
             if (msg == "")
             {
                 response.Status  = 1;
                 response.Message = "There is no data to display.";
             }
             else
             {
                 response.Status  = 0;
                 response.Message = msg;
             }
         }
         timer.Stop();
         response.Meta.Duration = timer.Elapsed.TotalSeconds;
         return(response);
     }
     catch (Exception ex)
     {
         return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
     }
 }
        private void HandleModify(BOL_REQUEST_DETAIL oREQUEST_DETAIL, BOL_REQUEST_ID oREQUEST_ID, DataRow row)
        {
            string msg = "";

            using (TransactionScope dbTxn = new TransactionScope())
            {
                #region UPDATE REQUEST_DETSIL
                REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                if (!DAL_REQUEST_DETAIL.IsAlreadyUpdated(oREQUEST_DETAIL, out msg)) // If updated_at is not already modified
                {
                    //insert the record
                    DAL_REQUEST_DETAIL.UpdateUsageApplication(oREQUEST_DETAIL, CURRENT_DATETIME, CURRENT_USER, out msg);

                    if (!string.IsNullOrEmpty(msg))
                    {
                        dbTxn.Dispose();
                        ResponseUtility.ReturnFailMessage(row);
                        return;
                    }
                }
                else
                {
                    dbTxn.Dispose();
                    ResponseUtility.ReturnFailMessage(row);
                    return;
                }
                #endregion

                #region UPDATE REQUEST_ID
                REQUEST_ID DAL_REQUEST_ID = new REQUEST_ID(con);

                if (!DAL_REQUEST_ID.IsAlreadyUpdated(oREQUEST_ID, out msg)) // If updated_at is not already modified
                {
                    //insert the record
                    DAL_REQUEST_ID.UpdateUsageApplication(oREQUEST_ID, CURRENT_DATETIME, CURRENT_USER, out msg);
                }
                else
                {
                    dbTxn.Dispose();
                    ResponseUtility.ReturnFailMessage(row);
                    return;
                }

                //return message and MK value
                if (String.IsNullOrEmpty(msg)) //success
                {
                    dbTxn.Complete();
                    ResponseUtility.ReturnSuccessMessage(row, UPDATED_AT_DATETIME, CURRENT_DATETIME, CURRENT_USER);
                }
                else //failed
                {
                    dbTxn.Dispose();
                    ResponseUtility.ReturnFailMessage(row);
                }
                #endregion
            }
        }
        public MetaResponse UpdateApplicationCancel(string list)
        {
            try
            {
                string    msg     = "";
                DataTable dgvList = Utility.Utility_Component.JsonToDt(list);

                for (int i = 0; i < dgvList.Rows.Count; i++)
                {
                    BOL_REQUEST_DETAIL oREQUEST_DETAIL = new BOL_REQUEST_DETAIL();
                    oREQUEST_DETAIL = Cast_REQUEST_DETAIL(dgvList.Rows[i]);

                    REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);

                    //already setting
                    if (oREQUEST_DETAIL.SYSTEM_SETTING_STATUS != 0)
                    {
                        ResponseUtility.ReturnFailMessage(dgvList.Rows[i], Messages.Jimugo.E000WB011);
                    }
                    else
                    {
                        if (!DAL_REQUEST_DETAIL.IsAlreadyUpdated(oREQUEST_DETAIL, out msg)) // If updated_at is not already modified
                        {
                            //insert the record
                            DAL_REQUEST_DETAIL.ApplicationCancelUpdate(oREQUEST_DETAIL, CURRENT_DATETIME, CURRENT_USER, out msg);

                            //return message and MK value
                            if (String.IsNullOrEmpty(msg)) //success
                            {
                                dgvList.Rows[i]["REQ_STATUS"] = "申請取消";
                                ResponseUtility.ReturnSuccessMessage(dgvList.Rows[i], UPDATED_AT_DATETIME, CURRENT_DATETIME, CURRENT_USER, string.Format(Utility.Messages.Jimugo.I000ZZ016, "申請取消"));
                            }
                            else //failed
                            {
                                ResponseUtility.ReturnFailMessage(dgvList.Rows[i]);
                            }
                        }
                        else
                        {
                            ResponseUtility.ReturnFailMessage(dgvList.Rows[i]);
                        }
                    }
                }
                response.Status = 1;
                response.Data   = Utility.Utility_Component.DtToJSon(dgvList, "Application Cancel ");;
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                return(response);
            }
            catch (Exception ex)
            {
                return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
            }
        }
 public ControllerRegisterCompleteNotificationSending()
 {
     response               = new MetaResponse();
     DAL_REQUEST_ID         = new REQUEST_ID(con);
     DAL_REQUEST_DETAIL     = new REQUEST_DETAIL(con);
     DAL_REPORT_HISTORY     = new REPORT_HISTORY(con);
     DAL_CLIENT_CERTIFICATE = new CLIENT_CERTIFICATE(con);
     DAL_REQ_ADDRESS        = new REQ_ADDRESS(con);
     timer = new Stopwatch();
     timer.Start();
     //UPDATED_AT
     UPDATED_AT_DATETIME = TEMP.ToString("yyyy/MM/dd HH:mm");
     CURRENT_DATETIME    = TEMP.ToString("yyyyMMddHHmmss");
 }
        public MetaResponse SettingCompleteMail(string UsageInfoRegList)
        {
            try
            {
                string    msg     = "";
                DataTable dgvList = Utility.Utility_Component.JsonToDt(UsageInfoRegList);

                for (int i = 0; i < dgvList.Rows.Count; i++)
                {
                    USAGE_INFO_REGISTRATION oUSAGE_INFO_REG = new USAGE_INFO_REGISTRATION();
                    oUSAGE_INFO_REG = CAST_TO_USAGE_INFO_REGISTRATION(dgvList.Rows[i]);

                    REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                    DAL_REQUEST_DETAIL.UpdateSystemSettingStatus(2, oUSAGE_INFO_REG.COMPNAY_NO_BOX, CURRENT_USER, CURRENT_DATETIME, out msg);

                    if (string.IsNullOrEmpty(msg))
                    {
                        bool mailSuccess = PrepareAndSendMail(oUSAGE_INFO_REG);

                        if (mailSuccess)
                        {
                            dgvList.Rows[i]["SYSTEM_SETTING_STATUS"] = 2;
                            ResponseUtility.ReturnMailSuccessMessage(dgvList.Rows[i], UPDATED_AT_DATETIME, CURRENT_DATETIME, CURRENT_USER);
                        }
                        else
                        {
                            ResponseUtility.MailSendingFail(dgvList.Rows[i]);
                        }
                    }
                    else
                    {
                        ResponseUtility.MailSendingFail(dgvList.Rows[i]);
                    }
                }

                response.Data = Utility.Utility_Component.DtToJSon(dgvList, "Mail status");;
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                return(response);
            }
            catch (Exception ex)
            {
                return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
            }
        }
Ejemplo n.º 7
0
        private void HandleDelete(BOL_REQUEST_ID oREQUEST_ID, DataRow row)
        {
            string strMsg = "";

            using (TransactionScope dbTxn = new TransactionScope())
            {
                //check if it is already registered in REQUEST_DETAIL
                REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                REQUEST_ID     DAL_REQUEST_ID     = new REQUEST_ID(con);

                if (!DAL_REQUEST_ID.IsAlreadyUpdated(oREQUEST_ID, out strMsg)) // IF updated_at is not already modified
                {
                    if (!DAL_REQUEST_DETAIL.IsAlreadyUsed(oREQUEST_ID.COMPANY_NO_BOX, out strMsg))
                    {
                        //delete the record
                        DAL_REQUEST_ID.Delete(oREQUEST_ID, out strMsg);
                    }
                    else //Already used
                    {
                        dbTxn.Dispose();
                        ResponseUtility.ReturnFailMessage(row, string.Format(Utility.Messages.Jimugo.E000ZZ033, oREQUEST_ID.COMPANY_NO_BOX));
                        return;
                    }
                }
                else
                {
                    dbTxn.Dispose();
                    ResponseUtility.ReturnFailMessage(row);
                    return;
                }

                //return message and MK value
                if (String.IsNullOrEmpty(strMsg)) //success
                {
                    dbTxn.Complete();
                    ResponseUtility.ReturnDeleteSuccessMessage(row);
                }
                else //failed
                {
                    ResponseUtility.ReturnFailMessage(row);
                }
            }
        }
 public MetaResponse getRequestDetailList(String COMPANY_NO_BOX, String COMPANY_NAME, String CLOSE_FLAG, String GD, String REQUEST_STATUS, String REQ_DATE_FROM, String REQ_DATE_TO, String QUOTATION_DATE_FROM, String QUOTATION_DATE_TO, String ORDER_DATE_FROM, String ORDER_DATE_TO, String SYSTEM_SETTING_STATUS, int OFFSET, int LIMIT)
 {
     try
     {
         string         strMessage         = "";
         int            TOTAL              = 0;
         REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
         DataTable      dt = DAL_REQUEST_DETAIL.GetRequestDetailList(COMPANY_NO_BOX, COMPANY_NAME, CLOSE_FLAG, GD, REQUEST_STATUS, REQ_DATE_FROM, REQ_DATE_TO, QUOTATION_DATE_FROM, QUOTATION_DATE_TO, ORDER_DATE_FROM, ORDER_DATE_TO, SYSTEM_SETTING_STATUS, OFFSET, LIMIT, out strMessage, out TOTAL);
         response.Data = Utility.Utility_Component.DtToJSon(dt, "UsageApplicatioList");
         if (dt.Rows.Count > 0)
         {
             response.Status = 1;
         }
         else
         {
             if (strMessage == "")
             {
                 response.Status  = 1;
                 response.Message = "There is no data to display.";
             }
             else
             {
                 response.Status  = 0;
                 response.Message = strMessage;
             }
         }
         response.Meta.Offset = OFFSET;
         response.Meta.Limit  = LIMIT;
         response.Meta.Total  = TOTAL;
         timer.Stop();
         response.Meta.Duration = timer.Elapsed.TotalSeconds;
         return(response);
     }
     catch (Exception ex)
     {
         return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
     }
 }
        public MetaResponse SubmitOrderRegister(string list, System.Web.HttpPostedFile file)
        {
            using (TransactionScope dbTxn = new TransactionScope())
            {
                try
                {
                    string msg = "";
                    //set global PARAMETERS
                    PARAMETERS = Utility.Utility_Component.JsonToDt(list);

                    #region Update REQUEST_DETAIL
                    //cast to REQUEST DETAIL OBJECT
                    BOL_REQUEST_DETAIL oREQUEST_DETAIL = new BOL_REQUEST_DETAIL();
                    oREQUEST_DETAIL = Cast_REQUEST_DETAIL();
                    oREQUEST_DETAIL.SYSTEM_SETTING_STATUS = 1;

                    REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                    DAL_REQUEST_DETAIL.Update(oREQUEST_DETAIL, CURRENT_DATETIME, CURRENT_USER, out msg);

                    //rollback if not success
                    if (!String.IsNullOrEmpty(msg))
                    {
                        dbTxn.Dispose();
                        return(ResponseUtility.ReturnFailMessage(response, timer, BodyMessage));
                    }
                    #endregion

                    #region Insert CUSTOMER MASTER
                    //COUNT IN CUSTOMER MASTER
                    string   COMPANY_NAME     = GetParameterByKey("COMPANY_NAME");
                    string   COMPANY_NO_BOX   = GetParameterByKey("COMPANY_NO_BOX");
                    string   CONTRACT_PLAN    = GetParameterByKey("CONTRACT_PLAN");
                    int      TRANSACTION_TYPE = int.Parse(GetParameterByKey("TRANSACTION_TYPE"));
                    int      REQ_SEQ          = int.Parse(GetParameterByKey("REQ_SEQ"));
                    int      REQ_TYPE         = int.Parse(GetParameterByKey("REQ_TYPE"));
                    DateTime START_USE_DATE   = DateTime.Parse(GetParameterByKey("START_USE_DATE"));

                    CUSTOMER_MASTER DAL_CUSTOMER_MASTER = new CUSTOMER_MASTER(con);
                    int             customer_count      = DAL_CUSTOMER_MASTER.getCustomerCountByKeys(COMPANY_NO_BOX, TRANSACTION_TYPE, START_USE_DATE, REQ_SEQ, out msg);

                    if (customer_count == 0) //if customer not found
                    {
                        DataTable           LatestCustomer   = new DataTable();
                        BOL_CUSTOMER_MASTER oCUSTOMER_MASTER = new BOL_CUSTOMER_MASTER();

                        if (REQ_TYPE == 2)
                        {
                            LatestCustomer = DAL_CUSTOMER_MASTER.GetTopCustomerByKeys(COMPANY_NO_BOX, TRANSACTION_TYPE, START_USE_DATE, out msg);

                            if (LatestCustomer.Rows.Count > 0)
                            {
                                oCUSTOMER_MASTER = Cast_CUSTOMER_MASTER(LatestCustomer.Rows[0]);
                                oCUSTOMER_MASTER.UPDATE_CONTENT = 3;
                            }
                            else //Need another message?
                            {
                                dbTxn.Dispose();
                                return(ResponseUtility.ReturnFailMessage(response, timer, BodyMessage));
                            }
                        }
                        if (REQ_TYPE == 1)
                        {
                            oCUSTOMER_MASTER.UPDATE_CONTENT = 1;
                        }
                        //insert info form screen
                        oCUSTOMER_MASTER.COMPANY_NO_BOX   = COMPANY_NO_BOX;
                        oCUSTOMER_MASTER.TRANSACTION_TYPE = TRANSACTION_TYPE;
                        oCUSTOMER_MASTER.EFFECTIVE_DATE   = START_USE_DATE;
                        oCUSTOMER_MASTER.REQ_SEQ          = REQ_SEQ;

                        DAL_CUSTOMER_MASTER.Insert(oCUSTOMER_MASTER, CURRENT_DATETIME, CURRENT_USER, out msg);

                        //rollback if not success
                        if (!String.IsNullOrEmpty(msg))
                        {
                            dbTxn.Dispose();
                            return(ResponseUtility.ReturnFailMessage(response, timer, BodyMessage));
                        }

                        #region Insert Browsing supplier CUSTOMER MASTER
                        BOL_CUSTOMER_MASTER oBROWSING_SUPPLIER = new BOL_CUSTOMER_MASTER();


                        if (CONTRACT_PLAN == "PRODUCT" && REQ_TYPE == 2)
                        {
                            DateTime NEW_EFFECTIVE_DATE = Convert.ToDateTime(DAL_CUSTOMER_MASTER.GetEffectiveDateForNewApplyingTime(oREQUEST_DETAIL.COMPANY_NO_BOX, TRANSACTION_TYPE, START_USE_DATE, out msg));
                            if ((NEW_EFFECTIVE_DATE.Month + NEW_EFFECTIVE_DATE.Day) != (START_USE_DATE.Month + START_USE_DATE.Day))
                            {
                                oBROWSING_SUPPLIER = Cast_CUSTOMER_MASTER(LatestCustomer.Rows[0]);
                                oBROWSING_SUPPLIER.COMPANY_NO_BOX   = COMPANY_NO_BOX;
                                oBROWSING_SUPPLIER.TRANSACTION_TYPE = TRANSACTION_TYPE;
                                oBROWSING_SUPPLIER.EFFECTIVE_DATE   = Convert.ToDateTime(START_USE_DATE.Year + "/" + NEW_EFFECTIVE_DATE.Month + "/" + NEW_EFFECTIVE_DATE.Day);
                                oBROWSING_SUPPLIER.UPDATE_CONTENT   = 3;
                                oBROWSING_SUPPLIER.REQ_SEQ          = REQ_SEQ;
                                DAL_CUSTOMER_MASTER.Insert(oBROWSING_SUPPLIER, CURRENT_DATETIME, CURRENT_USER, out msg);
                            }

                            //rollback if not success
                            if (!String.IsNullOrEmpty(msg))
                            {
                                dbTxn.Dispose();
                                return(ResponseUtility.ReturnFailMessage(response, timer, BodyMessage));
                            }
                        }
                        #endregion
                    }
                    #endregion

                    #region Insert REPORT_HISTORY
                    //Insert Report_History
                    BOL_REPORT_HISTORY oREPORT_HISTORY = new BOL_REPORT_HISTORY();
                    oREPORT_HISTORY.COMPANY_NO_BOX = COMPANY_NO_BOX;
                    oREPORT_HISTORY.REQ_SEQ        = REQ_SEQ;
                    oREPORT_HISTORY.REPORT_TYPE    = 4;

                    REPORT_HISTORY DAL_REPORT_HISTORY = new REPORT_HISTORY(con);
                    int            HISTORY_SEQ        = DAL_REPORT_HISTORY.GetReportHistorySEQ(COMPANY_NO_BOX, oREPORT_HISTORY.REPORT_TYPE, oREPORT_HISTORY.REQ_SEQ, out msg);

                    //rollback if not success
                    if (!String.IsNullOrEmpty(msg))
                    {
                        dbTxn.Dispose();
                        return(ResponseUtility.ReturnFailMessage(response, timer, BodyMessage));
                    }

                    oREPORT_HISTORY.REPORT_HISTORY_SEQ = HISTORY_SEQ;
                    oREPORT_HISTORY.OUTPUT_AT          = Utility_Component.dtColumnToDateTime(DateTime.Now.ToString());
                    oREPORT_HISTORY.OUTPUT_FILE        = COMPANY_NO_BOX + "-1-" + REQ_SEQ + "_注文書_" + COMPANY_NAME + "様.pdf";
                    oREPORT_HISTORY.EMAIL_ADDRESS      = null;

                    DAL_REPORT_HISTORY.Insert(oREPORT_HISTORY, CURRENT_DATETIME, CURRENT_USER, out msg);

                    //rollback if not success
                    if (!String.IsNullOrEmpty(msg))
                    {
                        dbTxn.Dispose();
                        return(ResponseUtility.MailSendingFail(response, timer, BodyMessage));
                    }
                    #endregion

                    #region Save File
                    //get destination path form config table
                    BOL_CONFIG config      = new BOL_CONFIG("CTS050", con);
                    string     destination = config.getStringValue("fileSavePath.purchaseOrder");
                    SaveFile(file, destination, oREPORT_HISTORY.OUTPUT_FILE, out msg);

                    if (!string.IsNullOrEmpty(msg))
                    {
                        dbTxn.Dispose();
                        response.Status = 0;
                        timer.Stop();
                        response.Meta.Duration = timer.Elapsed.TotalSeconds;
                        response.Message       = "File Path Not Found";
                        //add in body message
                        DataRow row = BodyMessage.NewRow();
                        row["Error Message"] = "File Path Not Found";
                        BodyMessage.Rows.Add(row);
                        response.Data = Utility_Component.DtToJSon(BodyMessage, "Message");
                        return(response);
                    }
                    #endregion

                    #region SendMail
                    bool mailSuccess = PrepareAndSendMail();

                    if (!mailSuccess)
                    {
                        dbTxn.Dispose();
                        return(ResponseUtility.MailSendingFail(response, timer, BodyMessage));
                    }
                    #endregion

                    //all process success
                    dbTxn.Complete();
                    response.Status  = 1;
                    response.Message = string.Format(Utility.Messages.Jimugo.I000ZZ016, "注文登録");
                    DataRow dr = BodyMessage.NewRow();
                    dr["Message"]        = response.Message;
                    dr["UPDATED_AT"]     = UPDATED_AT_DATETIME;
                    dr["UPDATED_AT_RAW"] = CURRENT_DATETIME;
                    BodyMessage.Rows.Add(dr);
                    response.Data = Utility_Component.DtToJSon(BodyMessage, "Message");
                    timer.Stop();
                    response.Meta.Duration = timer.Elapsed.TotalSeconds;
                    return(response);
                }
                catch (Exception ex)
                {
                    dbTxn.Dispose();
                    ResponseUtility.GetUnexpectedResponse(response, timer, ex);
                    //add in body message
                    DataRow dr = BodyMessage.NewRow();
                    dr["Error Message"] = "something went wrong.";
                    BodyMessage.Rows.Add(dr);
                    response.Data = Utility_Component.DtToJSon(BodyMessage, "Message");
                    return(response);
                }
            }
        }
        public MetaResponse getInitialData(string COMPANY_NO_BOX, string REQ_SEQ, int REQ_STATUS, int REQ_TYPE)
        {
            try
            {
                DataSet ds = new DataSet();

                string         strMessage         = "";
                REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                DataTable      dtList             = DAL_REQUEST_DETAIL.GetInitialDataForApproval(COMPANY_NO_BOX, REQ_SEQ, REQ_STATUS, REQ_TYPE, out strMessage);
                dtList.TableName = "LISTING";
                ds.Tables.Add(dtList);
                if (dtList.Rows.Count > 0)
                {
                    response.Status = 1;
                    //SERVICE DESK POP UP
                    REQ_ADDRESS DAL_REQ_ADDRESS = new REQ_ADDRESS(con);
                    string      _REQ_SEQ        = dtList.Rows[0]["REQ_SEQ"].ToString().Trim();
                    if (REQ_TYPE == 2)
                    {
                        DataTable SERVICE_DESK_CURRENT = DAL_REQ_ADDRESS.GetServiceDeskPopUp(COMPANY_NO_BOX, _REQ_SEQ, out strMessage);
                        SERVICE_DESK_CURRENT.TableName = "SERVICE_DESK_CURRENT";
                        ds.Tables.Add(SERVICE_DESK_CURRENT);
                    }
                    DataTable SERVICE_DESK_NEW = DAL_REQ_ADDRESS.GetServiceDeskPopUp(COMPANY_NO_BOX, REQ_SEQ, out strMessage);
                    SERVICE_DESK_NEW.TableName = "SERVICE_DESK_CHANGE";
                    ds.Tables.Add(SERVICE_DESK_NEW);

                    //ERROR NOTI POP UP
                    if (REQ_TYPE == 2)
                    {
                        DataTable ERROR_NOTI_CURRENT = DAL_REQ_ADDRESS.GetErrorNotificationPopUp(COMPANY_NO_BOX, _REQ_SEQ, out strMessage);
                        ERROR_NOTI_CURRENT.TableName = "ERROR_NOTI_CURRENT";
                        ds.Tables.Add(ERROR_NOTI_CURRENT);
                    }
                    DataTable ERROR_NOTI_NEW = DAL_REQ_ADDRESS.GetErrorNotificationPopUp(COMPANY_NO_BOX, REQ_SEQ, out strMessage);
                    ERROR_NOTI_NEW.TableName = "ERROR_NOTI_CHANGE";
                    ds.Tables.Add(ERROR_NOTI_NEW);

                    //BREAK DOWN
                    if (REQ_TYPE == 2)
                    {
                        DataTable BREAKDOWN_CURRENT = DAL_REQ_ADDRESS.GetUsageChargeBreakDownPopUp(COMPANY_NO_BOX, _REQ_SEQ, out strMessage);
                        BREAKDOWN_CURRENT.TableName = "BREAKDOWN_CURRENT";
                        ds.Tables.Add(BREAKDOWN_CURRENT);
                    }
                    DataTable BREAKDOWN_NEW = DAL_REQ_ADDRESS.GetUsageChargeBreakDownPopUp(COMPANY_NO_BOX, REQ_SEQ, out strMessage);
                    BREAKDOWN_NEW.TableName = "BREAKDOWN_CHANGE";
                    ds.Tables.Add(BREAKDOWN_NEW);
                }
                else
                {
                    if (string.IsNullOrEmpty(strMessage))
                    {
                        response.Status  = 1;
                        response.Message = "There is no data to display.";
                    }
                    else
                    {
                        response.Status  = 0;
                        response.Message = strMessage;
                    }
                }
                response.Data = Utility.Utility_Component.DsToJSon(ds, "INITIAL DATA");
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                return(response);
            }
            catch (Exception ex)
            {
                return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
            }
        }
        public MetaResponse Disapprove(string COMPANY_NO_BOX, int REQ_TYPE, string CHANGED_ITEMS, string SYSTEM_EFFECTIVE_DATE, string SYSTEM_REGIST_DEADLINE, string List)
        {
            try
            {
                DataSet   ds      = new DataSet();
                DataTable Listing = Utility_Component.JsonToDt(List);
                DataRow   row;

                if (Listing.Rows.Count > 1)
                {
                    row = Listing.Rows[1];
                }
                else
                {
                    row = Listing.Rows[0];
                }

                string             msg             = "";
                BOL_REQUEST_DETAIL oREQUEST_DETAIL = new BOL_REQUEST_DETAIL();
                oREQUEST_DETAIL.REQ_STATUS = 3;
                if (REQ_TYPE == 1 || REQ_TYPE == 9 || (REQ_TYPE == 2 && !string.IsNullOrEmpty(CHANGED_ITEMS.Trim())))
                {
                    oREQUEST_DETAIL.AMIGO_COOPERATION = 1;
                }
                else
                {
                    oREQUEST_DETAIL.AMIGO_COOPERATION = 2;
                }

                oREQUEST_DETAIL.AMIGO_COOPERATION_CHENGED_ITEMS = CHANGED_ITEMS.Trim();
                try
                {
                    oREQUEST_DETAIL.SYSTEM_EFFECTIVE_DATE = Convert.ToDateTime(SYSTEM_EFFECTIVE_DATE);
                }
                catch (Exception)
                {
                }
                try
                {
                    oREQUEST_DETAIL.SYSTEM_REGIST_DEADLINE = Convert.ToDateTime(SYSTEM_REGIST_DEADLINE);
                }
                catch (Exception)
                {
                }

                oREQUEST_DETAIL.REQ_SEQ        = int.Parse(row["REQ_SEQ"].ToString());
                oREQUEST_DETAIL.UPDATED_AT     = row["UPDATED_AT_RAW"].ToString();
                oREQUEST_DETAIL.COMPANY_NO_BOX = COMPANY_NO_BOX;

                REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                DAL_REQUEST_DETAIL.Disapprove(oREQUEST_DETAIL, CURRENT_USER, CURRENT_DATETIME, out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                }

                CUSTOMER_MASTER     DAL_CUSTOMER_MASTER = new CUSTOMER_MASTER(con);
                BOL_CUSTOMER_MASTER oCUSTOMER_MASTER    = new BOL_CUSTOMER_MASTER();
                oCUSTOMER_MASTER.COMPANY_NO_BOX = COMPANY_NO_BOX;
                oCUSTOMER_MASTER.REQ_SEQ        = oREQUEST_DETAIL.REQ_SEQ;
                DAL_CUSTOMER_MASTER.Delete(oCUSTOMER_MASTER, out msg);

                if (string.IsNullOrEmpty(msg))
                {
                    DataTable dtMail  = new DataTable();
                    bool      success = DisapproveSendMail(row["COMPANY_NAME"].ToString(), row["INPUT_PERSON"].ToString(), row["INPUT_PERSON_EMAIL_ADDRESS"].ToString(), out dtMail);

                    if (success)
                    {
                        response.Status       = 1;
                        row["UPDATED_AT"]     = UPDATED_AT_DATETIME;
                        row["UPDATED_AT_RAW"] = CURRENT_DATETIME;
                        row["UPDATED_BY"]     = CURRENT_USER;
                        row["UPDATE_MESSAGE"] = string.Format(Messages.Jimugo.I000ZZ016, "否認");
                        Listing.TableName     = "LISTING";
                        ds.Tables.Add(Listing.Copy());
                        dtMail.TableName = "MAIL";
                        ds.Tables.Add(dtMail.Copy());
                    }
                    else
                    {
                        return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                    }
                }
                else
                {
                    return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                }

                response.Data = Utility.Utility_Component.DsToJSon(ds, "Approval");
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                return(response);
            }
            catch (Exception ex)
            {
                return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
            }
        }
        public MetaResponse Approve(string COMPANY_NO_BOX, int REQ_TYPE, string REQ_TYPE_RAW, string CHANGED_ITEMS, string SYSTEM_EFFECTIVE_DATE, string SYSTEM_REGIST_DEADLINE, string List)
        {
            try
            {
                DataSet   ds      = new DataSet();
                DataTable Listing = Utility_Component.JsonToDt(List);
                DataRow   row;
                if (Listing.Rows.Count > 1)
                {
                    row = Listing.Rows[1];
                }
                else
                {
                    row = Listing.Rows[0];
                }

                string   EMIAL_SENDING_TARGET_FLG = row["MAIL_SENDING_TARGET_FLG"].ToString().Trim();
                string   MAIL_DESTINATION         = row["MAIL_DESTINATION"].ToString().Trim();
                int      TRANSACTION_TYPE         = getTRANSACTION_TYPE(row["TRANSACTION_TYPE"].ToString().Trim());
                DateTime START_USE_DATE           = Convert.ToDateTime(row["START_USE_DATE"].ToString().Trim());

                using (TransactionScope dbTxn = new TransactionScope())
                {
                    #region Approve
                    BOL_REQUEST_DETAIL oREQUEST_DETAIL = new BOL_REQUEST_DETAIL();
                    oREQUEST_DETAIL.COMPANY_NO_BOX = COMPANY_NO_BOX;
                    oREQUEST_DETAIL.REQ_STATUS     = 2;
                    if (REQ_TYPE == 1 || REQ_TYPE == 9 || (REQ_TYPE == 2 && !string.IsNullOrEmpty(CHANGED_ITEMS.Trim())))
                    {
                        oREQUEST_DETAIL.AMIGO_COOPERATION = 1;
                    }
                    else
                    {
                        oREQUEST_DETAIL.AMIGO_COOPERATION = 2;
                    }
                    oREQUEST_DETAIL.AMIGO_COOPERATION_CHENGED_ITEMS = CHANGED_ITEMS.Trim();
                    try
                    {
                        oREQUEST_DETAIL.SYSTEM_EFFECTIVE_DATE = Convert.ToDateTime(SYSTEM_EFFECTIVE_DATE);
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        oREQUEST_DETAIL.SYSTEM_REGIST_DEADLINE = Convert.ToDateTime(SYSTEM_REGIST_DEADLINE);
                    }
                    catch (Exception)
                    {
                    }
                    oREQUEST_DETAIL.REQ_SEQ = int.Parse(row["REQ_SEQ"].ToString());

                    if (MAIL_DESTINATION == "1")
                    {
                        oREQUEST_DETAIL.SYSTEM_SETTING_STATUS = 1;
                    }
                    else
                    {
                        oREQUEST_DETAIL.SYSTEM_SETTING_STATUS = 0;
                    }
                    oREQUEST_DETAIL.UPDATED_AT = row["UPDATED_AT_RAW"].ToString();

                    string         msg = "";
                    REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);

                    DAL_REQUEST_DETAIL.Approve(oREQUEST_DETAIL, CURRENT_USER, CURRENT_DATETIME, out msg);

                    if (!string.IsNullOrEmpty(msg))
                    {
                        return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                    }
                    #endregion

                    if (EMIAL_SENDING_TARGET_FLG == "*" && TRANSACTION_TYPE == 3)
                    {
                        DataTable       LatestCustomer      = new DataTable();
                        CUSTOMER_MASTER DAL_CUSTOMER_MASTER = new CUSTOMER_MASTER(con);
                        if (REQ_TYPE == 2 || REQ_TYPE == 9)
                        {
                            LatestCustomer = DAL_CUSTOMER_MASTER.GetTopCustomerByKeys(oREQUEST_DETAIL.COMPANY_NO_BOX, TRANSACTION_TYPE, START_USE_DATE, out msg);
                        }

                        #region CONDUCT NEW CUSTOMER MASTER
                        BOL_CUSTOMER_MASTER oCUSTOMER_MASTER = new BOL_CUSTOMER_MASTER();

                        if (LatestCustomer.Rows.Count > 0 && REQ_TYPE != 1)
                        {
                            oCUSTOMER_MASTER = Cast_CUSTOMER_MASTER(LatestCustomer.Rows[0]);
                        }
                        oCUSTOMER_MASTER.COMPANY_NO_BOX   = COMPANY_NO_BOX;
                        oCUSTOMER_MASTER.TRANSACTION_TYPE = TRANSACTION_TYPE;
                        oCUSTOMER_MASTER.EFFECTIVE_DATE   = START_USE_DATE;
                        oCUSTOMER_MASTER.REQ_SEQ          = oREQUEST_DETAIL.REQ_SEQ;
                        oCUSTOMER_MASTER.UPDATE_CONTENT   = REQ_TYPE;
                        DAL_CUSTOMER_MASTER.Delete(oCUSTOMER_MASTER, out msg);
                        if (!string.IsNullOrEmpty(msg))
                        {
                            return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                        }
                        DAL_CUSTOMER_MASTER.Insert(oCUSTOMER_MASTER, CURRENT_DATETIME, CURRENT_USER, out msg);

                        if (!string.IsNullOrEmpty(msg))
                        {
                            return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                        }

                        #endregion

                        string CONTRACT_PLAN = row["CONTRACT_PLAN_RAW"].ToString().ToString();
                        if (CONTRACT_PLAN == "PRODUCT" && REQ_TYPE == 9)
                        {
                            //get latest customer for new applying time
                            DateTime NEW_EFFECTIVE_DATE = Convert.ToDateTime(DAL_CUSTOMER_MASTER.GetEffectiveDateForNewApplyingTime(oREQUEST_DETAIL.COMPANY_NO_BOX, TRANSACTION_TYPE, START_USE_DATE, out msg));

                            if ((NEW_EFFECTIVE_DATE.Month + NEW_EFFECTIVE_DATE.Day) != (START_USE_DATE.Month + START_USE_DATE.Day))
                            {
                                #region Insert Browsing CUSTOMER MASTER
                                BOL_CUSTOMER_MASTER oCUSTOMER_MASTER_BROWSING = new BOL_CUSTOMER_MASTER();
                                oCUSTOMER_MASTER_BROWSING = Cast_CUSTOMER_MASTER(LatestCustomer.Rows[0]);
                                oCUSTOMER_MASTER_BROWSING.COMPANY_NO_BOX   = COMPANY_NO_BOX;
                                oCUSTOMER_MASTER_BROWSING.TRANSACTION_TYPE = TRANSACTION_TYPE;
                                oCUSTOMER_MASTER_BROWSING.EFFECTIVE_DATE   = Convert.ToDateTime(START_USE_DATE.Year + "/" + NEW_EFFECTIVE_DATE.Month + "/" + NEW_EFFECTIVE_DATE.Day);
                                oCUSTOMER_MASTER_BROWSING.REQ_SEQ          = oREQUEST_DETAIL.REQ_SEQ;
                                oCUSTOMER_MASTER_BROWSING.UPDATE_CONTENT   = REQ_TYPE;

                                DAL_CUSTOMER_MASTER = new CUSTOMER_MASTER(con);
                                DAL_CUSTOMER_MASTER.Insert(oCUSTOMER_MASTER_BROWSING, CURRENT_DATETIME, CURRENT_USER, out msg);

                                if (!string.IsNullOrEmpty(msg))
                                {
                                    return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                                }
                                #endregion
                            }
                        }
                    }
                    DataTable dtMail      = new DataTable();
                    bool      mailSuccess = false;
                    if (EMIAL_SENDING_TARGET_FLG == "*" && MAIL_DESTINATION == "1")
                    {
                        mailSuccess = SendMailToMaintenance(COMPANY_NO_BOX, REQ_TYPE_RAW, row["COMPANY_NAME"].ToString(), CHANGED_ITEMS, SYSTEM_REGIST_DEADLINE, out dtMail);
                        if (mailSuccess)
                        {
                            dbTxn.Complete();
                            return(SetSuccessMessage(row, Listing, dtMail, ds));
                        }
                        else
                        {
                            return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                        }
                    }
                    else if (EMIAL_SENDING_TARGET_FLG == "*" && MAIL_DESTINATION == "2")
                    {
                        mailSuccess = SendMailToSupplier(row["COMPANY_NAME"].ToString(), row["INPUT_PERSON"].ToString(), row["INPUT_PERSON_EMAIL_ADDRESS"].ToString(), out dtMail);

                        if (mailSuccess)
                        {
                            dbTxn.Complete();
                            return(SetSuccessMessage(row, Listing, dtMail, ds));
                        }
                        else
                        {
                            return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                        }
                    }
                    dbTxn.Complete();
                    return(SetSuccessMessage(row, Listing, dtMail, ds));
                }
            }
            catch (Exception ex)
            {
                return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
            }
        }
        public MetaResponse ApproveCancel(string COMPANY_NO_BOX, string REQ_SEQ, string List)
        {
            try
            {
                string    msg     = "";
                DataSet   ds      = new DataSet();
                DataTable Listing = Utility_Component.JsonToDt(List);
                DataRow   row;
                if (Listing.Rows.Count > 1)
                {
                    row = Listing.Rows[1];
                }
                else
                {
                    row = Listing.Rows[0];
                }

                REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                //serch with COMPANY_NO_BOX AND REQ_SEQ
                DataTable APPROVAL_CHECK = DAL_REQUEST_DETAIL.GetDataToCheckApproveCancel(COMPANY_NO_BOX, REQ_SEQ, out msg);


                //IF QUOTATION DATE NOT NULL THEN ERROR
                if (!string.IsNullOrEmpty(APPROVAL_CHECK.Rows[0]["QUOTATION_DATE"].ToString()))
                {
                    return(ResponseError(response, Utility.Messages.Jimugo.E000ZZ037, Listing, ds, row));
                }
                //IF SYSTEM_SETTING_STATUS NOT NULL THEN ERROR
                if (APPROVAL_CHECK.Rows[0]["SYSTEM_SETTING_STATUS"].ToString() != "0")
                {
                    return(ResponseError(response, Utility.Messages.Jimugo.E000WB015, Listing, ds, row));
                }

                DAL_REQUEST_DETAIL.ApproveCancel(COMPANY_NO_BOX, row["REQ_SEQ"].ToString(), CURRENT_USER, CURRENT_DATETIME, out msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                }

                CUSTOMER_MASTER     DAL_CUSTOMER_MASTER = new CUSTOMER_MASTER(con);
                BOL_CUSTOMER_MASTER oCUSTOMER_MASTER    = new BOL_CUSTOMER_MASTER();
                oCUSTOMER_MASTER.COMPANY_NO_BOX = COMPANY_NO_BOX;
                oCUSTOMER_MASTER.REQ_SEQ        = Convert.ToInt32(row["REQ_SEQ"]);
                DAL_CUSTOMER_MASTER.Delete(oCUSTOMER_MASTER, out msg);

                if (!string.IsNullOrEmpty(msg))
                {
                    return(ResponseError(response, Utility.Messages.Jimugo.I000ZZ005, Listing, ds, row));
                }
                else
                {
                    response.Status       = 1;
                    row["UPDATE_MESSAGE"] = string.Format(Messages.Jimugo.I000ZZ016, "承認解除");
                    Listing.TableName     = "LISTING";
                    ds.Tables.Add(Listing.Copy());
                }
                response.Data = Utility.Utility_Component.DsToJSon(ds, "Approval");
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                return(response);
            }
            catch (Exception ex)
            {
                return(ResponseUtility.GetUnexpectedResponse(response, timer, ex));
            }
        }
        public MetaResponse getBreakDownScreenData(string COMPANY_NO_BOX, string REQ_SEQ)
        {
            try
            {
                string         strMessage         = "";
                int            TOTAL              = 0;
                REQUEST_DETAIL DAL_REQUEST_DETAIL = new REQUEST_DETAIL(con);
                DataTable      dt = DAL_REQUEST_DETAIL.getBreakDownScreenData(COMPANY_NO_BOX, REQ_SEQ, out strMessage);

                DataTable dtREQUEST_DETAIL = new DataTable();
                dtREQUEST_DETAIL.Columns.Add("COST", typeof(decimal));
                dtREQUEST_DETAIL.Columns.Add("DISCOUNT", typeof(decimal));
                dtREQUEST_DETAIL.Columns.Add("DIFFERENT", typeof(decimal));

                REQ_USAGE_FEE DAL_REQ_USAGE_FEE  = new REQ_USAGE_FEE(con);
                DataTable     dtUSAGE_FEE_MASTER = DAL_REQ_USAGE_FEE.getPopUpScreenData(COMPANY_NO_BOX, REQ_SEQ);

                if (dt.Rows.Count > 0)
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        DataRow newRow = dtREQUEST_DETAIL.NewRow();
                        newRow["COST"]      = row["INITIAL_COST"];
                        newRow["DISCOUNT"]  = row["MONTHLY_COST"];
                        newRow["DIFFERENT"] = row["YEAR_COST"];
                        dtREQUEST_DETAIL.Rows.Add(newRow);

                        DataRow newRow1 = dtREQUEST_DETAIL.NewRow();
                        string  initial = row["INITIAL_COST_DISCOUNTS"].ToString();
                        string  monthly = row["MONTHLY_COST_DISCOUNTS"].ToString();
                        string  year    = row["YEAR_COST_DISCOUNTS"].ToString();
                        if (initial != "0")
                        {
                            newRow1["COST"] = "-" + row["INITIAL_COST_DISCOUNTS"];
                        }
                        else
                        {
                            newRow1["COST"] = row["INITIAL_COST_DISCOUNTS"];
                        }

                        if (monthly != "0")
                        {
                            newRow1["DISCOUNT"] = "-" + row["MONTHLY_COST_DISCOUNTS"];
                        }
                        else
                        {
                            newRow1["DISCOUNT"] = row["MONTHLY_COST_DISCOUNTS"];
                        }

                        if (year != "0")
                        {
                            newRow1["DIFFERENT"] = "-" + row["YEAR_COST_DISCOUNTS"];
                        }
                        else
                        {
                            newRow1["DIFFERENT"] = row["YEAR_COST_DISCOUNTS"];
                        }
                        dtREQUEST_DETAIL.Rows.Add(newRow1);

                        DataRow newRow2 = dtREQUEST_DETAIL.NewRow();
                        newRow2["COST"]      = row["INITIAL_COST_DIFF"];
                        newRow2["DISCOUNT"]  = row["MONTHLY_COST_DIFF"];
                        newRow2["DIFFERENT"] = row["YEAR_COST_DIFF"];
                        dtREQUEST_DETAIL.Rows.Add(newRow2);
                    }

                    //foreach (DataRow row in dt.Rows)
                    //{
                    //    DataRow newRow = dtREQUEST_DETAIL.NewRow();
                    //    newRow["COST"] = row["INITIAL_COST"];
                    //    newRow["DISCOUNT"] = row["INITIAL_COST_DISCOUNTS"];
                    //    newRow["DIFFERENT"] = row["INITIAL_COST_DIFF"];
                    //    dtREQUEST_DETAIL.Rows.Add(newRow);

                    //    DataRow newRow1 = dtREQUEST_DETAIL.NewRow();
                    //    newRow1["COST"] = row["MONTHLY_COST"];
                    //    newRow1["DISCOUNT"] = row["MONTHLY_COST_DISCOUNTS"];
                    //    newRow1["DIFFERENT"] = row["MONTHLY_COST_DIFF"];
                    //    dtREQUEST_DETAIL.Rows.Add(newRow1);

                    //    DataRow newRow2 = dtREQUEST_DETAIL.NewRow();
                    //    newRow2["COST"] = row["YEAR_COST"];
                    //    newRow2["DISCOUNT"] = row["YEAR_COST_DISCOUNTS"];
                    //    newRow2["DIFFERENT"] = row["YEAR_COST_DIFF"];
                    //    dtREQUEST_DETAIL.Rows.Add(newRow2);
                    //}
                }

                DataSet ds = new DataSet();
                ds.Tables.Add(dtREQUEST_DETAIL);
                ds.Tables.Add(dtUSAGE_FEE_MASTER);

                response.Data = Utility.Utility_Component.DsToJSon(ds, "Maintenance List");

                if (dt.Rows.Count > 0)
                {
                    response.Status = 1;
                }
                else
                {
                    if (strMessage == "")
                    {
                        response.Status  = 1;
                        response.Message = "There is no data to display.";
                    }
                    else
                    {
                        response.Status  = 0;
                        response.Message = strMessage;
                    }
                }
                response.Meta.Total = TOTAL;
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                return(response);
            }
            catch (Exception ex)
            {
                response.Status = 0;
                timer.Stop();
                response.Meta.Duration = timer.Elapsed.TotalSeconds;
                response.Message       = ex.Message + "/n" + ex.StackTrace;
                return(response);
            }
        }