Esempio n. 1
0
        public int InsertLogTransactionS02003(List <CUSTOM_S02003_TEMP> listTempHS)
        {
            LogEvent logEvent = new LogEvent();
            int      result   = 0;

            try
            {
                if (listTempHS.Count > 0)
                {
                    //insert into CUSTOM_TRANSACTION
                    CUSTOM_TRANSACTION transaction = new CUSTOM_TRANSACTION();
                    transaction.TicketNo  = "";
                    transaction.ClientTag = "";
                    EntityHelper.SetAuditForInsert(transaction, "SERA");
                    entities.CUSTOM_TRANSACTION.AddObject(transaction);

                    var countListTempHS = listTempHS.Count;
                    //var countListTempIS = listTempIS.Count;

                    for (int i = 0; i < listTempHS.Count; i++)
                    {
                        //insert into CUSTOM_TRANSACTIONDATA
                        CUSTOM_TRANSACTIONDATA transactionData = new CUSTOM_TRANSACTIONDATA();
                        transactionData.CUSTOM_TRANSACTION = transaction;
                        transactionData.TransGUID          = Guid.NewGuid().ToString();
                        transactionData.DocumentNumber     = listTempHS[i].PONumber;
                        transactionData.FileType           = "S02003";
                        transactionData.IPAddress          = "118.97.80.12"; //"127.0.0.1";
                        transactionData.DestinationUser    = "******";
                        //transactionData.Key1 = "0002"; //company toyota
                        transactionData.Key1       = listTempHS[i].CompanyCodeAI;
                        transactionData.Key2       = listTempHS[i].KodeCabangAI;
                        transactionData.Key3       = "";
                        transactionData.DataLength = null;
                        transactionData.RowStatus  = "";
                        EntityHelper.SetAuditForInsert(transactionData, "SERA");
                        entities.CUSTOM_TRANSACTIONDATA.AddObject(transactionData);

                        //CHECK IF DATA HS BY PONUMBER SUDAH ADA, DELETE DULU BY ID, supaya tidak redundant ponumber nya
                        var poNumb = listTempHS[i].PONumber;
                        var query  = (from o in entities.CUSTOM_S02003
                                      where o.PONumber == poNumb
                                      select o).ToList();
                        if (query.Count > 0)
                        {
                            for (int d = 0; d < query.Count; d++)
                            {
                                //delete
                                var           delID = query[d].ID;
                                CUSTOM_S02003 delHS = entities.CUSTOM_S02003.Single(o => o.ID == delID);
                                entities.CUSTOM_S02003.DeleteObject(delHS);
                            }
                        }

                        //insert into CUSTOM_S02003
                        CUSTOM_S02003 DataDetailHS = new CUSTOM_S02003();
                        DataDetailHS.CUSTOM_TRANSACTIONDATA = transactionData;
                        DataDetailHS.PONumber        = listTempHS[i].PONumber;
                        DataDetailHS.VersionPOSera   = listTempHS[i].VersionPOSera;
                        DataDetailHS.DataVersion     = listTempHS[i].DataVersion;
                        DataDetailHS.KodeCabangAI    = listTempHS[i].KodeCabangAI;
                        DataDetailHS.ReasonRejection = listTempHS[i].ReasonRejection;
                        //start add identitas penambahan row custom_s02003 : by fhi 04.06.2014
                        DataDetailHS.dibuatOleh    = "system";
                        DataDetailHS.dibuatTanggal = DateTime.Now;
                        DataDetailHS.diubahOleh    = "system";
                        DataDetailHS.diubahTanggal = DateTime.Now;
                        //end
                        entities.CUSTOM_S02003.AddObject(DataDetailHS);

                        //build HS separator
                        var strHS = ConcateStringHSS02003(listTempHS[i]);

                        //insert into CUSTOM_TRANSACTIONDATADETAIL for HS
                        CUSTOM_TRANSACTIONDATADETAIL transactionDataDetail = new CUSTOM_TRANSACTIONDATADETAIL();
                        transactionDataDetail.CUSTOM_TRANSACTIONDATA = transactionData;
                        transactionDataDetail.Data = strHS;

                        //start add identitas penambahan row CUSTOM_TRANSACTIONDATADETAIL : by fhi 04.06.2014
                        transactionDataDetail.dibuatOleh    = "system";
                        transactionDataDetail.dibuatTanggal = DateTime.Now;
                        transactionDataDetail.diubahOleh    = "system";
                        transactionDataDetail.diubahTanggal = DateTime.Now;
                        //end

                        entities.CUSTOM_TRANSACTIONDATADETAIL.AddObject(transactionDataDetail);
                    }
                    entities.SaveChanges();
                    //todo: delete temp table
                    for (int y = 0; y < countListTempHS; y++)
                    {
                        DeleteTempHSS02003(listTempHS[y]);
                    }
                    result = 1;
                }
                else
                {
                    //add task kill when failed : by  fhi 04.06.2014
                    logEvent.WriteDBLog("", "UploadS02003_Load", false, "", "listTempHS.Count <= 0", "S02003", "SERA");
                    Process.Start("taskkill.exe", "/f /im B2BAISERA_S02003.exe");
                    //end
                }
            }
            catch (Exception ex)
            {
                //add task kill when failed : by  fhi 04.06.2014
                logEvent.WriteDBLog("", "UploadS02003_Load", false, "", ex.Message, "S02003", "SERA");
                Process.Start("taskkill.exe", "/f /im B2BAISERA_S02003.exe");
                //end
                throw ex;
            }
            return(result);
        }
        public int InsertLogTransactionS02007(List <CUSTOM_S02007_TEMP> listTempHS)
        {
            int result = 0;

            try
            {
                if (listTempHS.Count > 0)
                {
                    //insert into CUSTOM_TRANSACTION
                    CUSTOM_TRANSACTION transaction = new CUSTOM_TRANSACTION();
                    transaction.TicketNo  = "";
                    transaction.ClientTag = "";
                    EntityHelper.SetAuditForInsert(transaction, "SERA");
                    entities.CUSTOM_TRANSACTION.AddObject(transaction);

                    var countListTempHS = listTempHS.Count;
                    //var countListTempIS = listTempIS.Count;

                    for (int i = 0; i < listTempHS.Count; i++)
                    {
                        //insert into CUSTOM_TRANSACTIONDATA
                        CUSTOM_TRANSACTIONDATA transactionData = new CUSTOM_TRANSACTIONDATA();
                        transactionData.CUSTOM_TRANSACTION = transaction;
                        transactionData.TransGUID          = Guid.NewGuid().ToString();
                        transactionData.DocumentNumber     = listTempHS[i].PONUMBER;
                        transactionData.FileType           = "S02007";
                        transactionData.IPAddress          = "118.97.80.12"; //IP ADDRESS KOMP SERVER, dan HARUS TERDAFTAR DI DB AI
                        transactionData.DestinationUser    = "******";
                        //transactionData.Key1 = "0002"; //company toyota
                        transactionData.Key1       = listTempHS[i].CompanyCodeAI;
                        transactionData.Key2       = GetKodeCabangAI(listTempHS[i].PONUMBER); //trial: kode cabang AI
                        transactionData.Key3       = listTempHS[i].BILLINGNO;                 //BILLINGNO
                        transactionData.DataLength = null;
                        transactionData.RowStatus  = "";
                        EntityHelper.SetAuditForInsert(transactionData, "SERA");
                        entities.CUSTOM_TRANSACTIONDATA.AddObject(transactionData);

                        //CHECK IF DATA HS BY PONUMBER SUDAH ADA, DELETE DULU BY ID, supaya tidak redundant ponumber nya
                        var poNumb = listTempHS[i].PONUMBER;
                        var query  = (from o in entities.CUSTOM_S02007
                                      where o.PONUMBER == poNumb
                                      select o).ToList();
                        if (query.Count > 0)
                        {
                            for (int d = 0; d < query.Count; d++)
                            {
                                //delete
                                var           delID = query[d].ID;
                                CUSTOM_S02007 delHS = entities.CUSTOM_S02007.Single(o => o.ID == delID);
                                entities.CUSTOM_S02007.DeleteObject(delHS);
                            }
                        }

                        //insert into CUSTOM_S02007
                        CUSTOM_S02007 DataDetailHS = new CUSTOM_S02007();
                        DataDetailHS.CUSTOM_TRANSACTIONDATA = transactionData;
                        DataDetailHS.PONUMBER           = listTempHS[i].PONUMBER;
                        DataDetailHS.VERSIONPOSERA      = listTempHS[i].VERSIONPOSERA;
                        DataDetailHS.BILLINGNO          = listTempHS[i].BILLINGNO;
                        DataDetailHS.INVOICERECEIPTDATE = listTempHS[i].INVOICERECEIPTDATE;
                        DataDetailHS.DATAVERSION        = listTempHS[i].DATAVERSION;
                        DataDetailHS.payPlan            = listTempHS[i].payPlan;
                        //start add identitas penambahan row CUSTOM_S02007 : by fhi 05.06.2014
                        DataDetailHS.dibuatOleh    = "system";
                        DataDetailHS.dibuatTanggal = DateTime.Now;
                        DataDetailHS.diubahOleh    = "system";
                        DataDetailHS.diubahTanggal = DateTime.Now;
                        //end
                        entities.CUSTOM_S02007.AddObject(DataDetailHS);

                        //build HS separator
                        var strHS = ConcateStringHSS02007(listTempHS[i]);

                        //insert into CUSTOM_TRANSACTIONDATADETAIL for HS
                        CUSTOM_TRANSACTIONDATADETAIL transactionDataDetail = new CUSTOM_TRANSACTIONDATADETAIL();
                        transactionDataDetail.CUSTOM_TRANSACTIONDATA = transactionData;
                        transactionDataDetail.Data = strHS;
                        //start add identitas penambahan row CUSTOM_S02007 : by fhi 05.06.2014
                        transactionDataDetail.dibuatOleh    = "system";
                        transactionDataDetail.dibuatTanggal = DateTime.Now;
                        transactionDataDetail.diubahOleh    = "system";
                        transactionDataDetail.diubahTanggal = DateTime.Now;
                        //end
                        entities.CUSTOM_TRANSACTIONDATADETAIL.AddObject(transactionDataDetail);
                    }
                    entities.SaveChanges();
                    //todo: delete temp table
                    for (int y = 0; y < countListTempHS; y++)
                    {
                        DeleteTempHSS02007(listTempHS[y]);
                    }
                    result = 1;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }