/// <summary> /// Fill Container Card By contCardId, cardMode /// </summary> /// <param name="contCardId"></param> /// <param name="cardMode"></param> /// <returns></returns> public ContCard FillContCardByContCardIdAndCardMode(long contCardId, string cardMode) { ContCard contCard = new ContCard(); try { using (NpgsqlConnection npgsqlConnection = AppConfig.GetConnection()) { if (npgsqlConnection.State == ConnectionState.Closed) { npgsqlConnection.Open(); } string query = string.Format("SELECT {0} FROM {1} WHERE contcardid=@ContCardId AND cardmode=@CardMode ", string.Format(DEFAULT_COLUMN, string.Empty), DEFAULT_TABLE); using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(query, npgsqlConnection)) { npgsqlCommand.Parameters.AddWithValue("@ContCardId", contCardId); npgsqlCommand.Parameters.AddWithValue("@CardMode", cardMode); using (NpgsqlDataReader npgsqlDataReader = npgsqlCommand.ExecuteReader()) { if (npgsqlDataReader.Read()) { MappingDataReaderToContCard(npgsqlDataReader, contCard); } } } } } catch (Exception ex) { throw ex; } return(contCard); }
private void MappingDataReaderToContCard(NpgsqlDataReader npgsqlDataReader, ContCard contCard) { contCard.ContCardID = npgsqlDataReader.GetInt64(npgsqlDataReader.GetOrdinal("contcardid")); contCard.CardMode = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("cardmode")); contCard.RefID = npgsqlDataReader.GetInt64(npgsqlDataReader.GetOrdinal("refid")); contCard.Cont = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("cont")); contCard.Size = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("size")); contCard.Type = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("type")); if (npgsqlDataReader["dtm1"] != DBNull.Value) { contCard.Dtm1 = npgsqlDataReader.GetDateTime(npgsqlDataReader.GetOrdinal("dtm1")); } contCard.Loc1 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("loc1")); if (npgsqlDataReader["dtm2"] != DBNull.Value) { contCard.Dtm2 = npgsqlDataReader.GetDateTime(npgsqlDataReader.GetOrdinal("dtm2")); } contCard.Loc2 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("loc2")); contCard.Remark = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("remark")); if (npgsqlDataReader["dtm3"] != DBNull.Value) { contCard.Dtm3 = npgsqlDataReader.GetDateTime(npgsqlDataReader.GetOrdinal("dtm3")); } contCard.ContInOutID = npgsqlDataReader.GetInt64(npgsqlDataReader.GetOrdinal("continoutid")); contCard.UserID3 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("userid3")); contCard.Seal1 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("seal1")); contCard.Seal2 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("seal2")); contCard.Seal3 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("seal3")); contCard.Seal4 = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("seal4")); contCard.NoMobilOut = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("nomobilout")); contCard.AngkutanOut = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("angkutanout")); contCard.Token = npgsqlDataReader.GetString(npgsqlDataReader.GetOrdinal("token")); contCard.IsCombo = npgsqlDataReader.GetBoolean(npgsqlDataReader.GetOrdinal("iscombo")); }
private static void OpenGate(string openedby, SecureGateLog log, ContCard contCard) { try { if (_CaptureImageExeFile.Length > 0) { System.Console.WriteLine("info: capturing container picture..."); Process.Start(_CaptureImageExeFile); System.Console.WriteLine("info: container picture captured"); Thread.Sleep(1000); } else { System.Console.WriteLine("warning: container picture not captured"); } } catch (Exception exception) { System.Console.WriteLine("error: " + exception.Message); } try { var terminal = new Terminal(_SecureGateTelnetAddress, Convert.ToInt32(_SecureGateTelnetPort), 10, 80, 40); // hostname, port, timeout [s], width, height PushCommand.PushOK(terminal); Thread.Sleep(1000); } catch (Exception exception2) { System.Console.WriteLine("error: " + exception2.Message); } try { SecureGateLogDAL logDal = new SecureGateLogDAL(); log.Loc1 = _SecureGateLocName; log.LogCat = "GATE OPEN EVENT"; log.LogRemark = openedby; log.RefID = contCard.ContCardID; if (log.SecureGateLogID <= 0) { logDal.DeleteSecureGateLog(log); logDal.InsertSecureGateLog(log); } else { logDal.UpdateSecureGateLog(log); } } catch (Exception exception3) { System.Console.WriteLine("error: " + exception3.Message); } }
private static void OpenGate(string openedBy, SecureGateLog log, ContCard contCard, Terminal terminal) { try { if (_CaptureImageExeFile.Length > 0) { System.Console.WriteLine("info: capturing container picture..."); Process.Start(_CaptureImageExeFile); System.Console.WriteLine("info: container picture captured"); Thread.Sleep(1000); } else { System.Console.WriteLine("warning: container picture not captured"); } } catch (Exception exception) { System.Console.WriteLine("error: " + exception.Message); } try { PushCommand.PushOK(terminal); Thread.Sleep(1000); } catch (Exception exception2) { System.Console.WriteLine("error: " + exception2.Message); } try { SecureGateLogDAL logDal = new SecureGateLogDAL(); log.Loc1 = _SecureGateLocName; log.LogCat = "GATE OPEN EVENT"; log.LogRemark = openedBy; log.RefID = contCard.ContCardID; if (log.SecureGateLogID <= 0) { logDal.DeleteSecureGateLog(log); logDal.InsertSecureGateLog(log); } else { logDal.UpdateSecureGateLog(log); } } catch (Exception exception3) { System.Console.WriteLine("error: " + exception3.Message); } }
public string CheckKendaraan(long id) { try { ContCard contCard = new ContCard(); contCard = contCardDAL.FillContCardByContCardId(id); return(contCard.ContCardID > 0 ? Converter.ConvertToXML(contCard) : string.Empty); } catch (Exception ex) { log.ErrorFormat("FillContCardByContCardId -> Parameter: id={0}", id); log.ErrorFormat("FillContCardByContCardId -> Message: {0}", ex.Message); log.ErrorFormat("FillContCardByContCardId -> StackTrace: {0}", ex.StackTrace); return("Error: Tidak dapat memproses kartu: " + id); } }
private static void ProcessInput(string input, SecureGateLog log, Terminal terminal) { if (input.Length > 0) { System.Console.WriteLine("container card: " + input); _LastProcessedInput = input; ContCard contCard = new ContCard(); ContCardDal cardDAL = new ContCardDal(); contCard = cardDAL.GetContCardByContCardId(Convert.ToInt64(input)); if (contCard.ContCardID <= 0) { System.Console.WriteLine("INPUT NOT RECOGNIZED !!!"); } else if (contCard.Dtm1.Length == 0) { //DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") contCard.Dtm1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); contCard.Loc1 = _SecureGateLocName; cardDAL.UpdateContCardGateIn(contCard.ContCardID, contCard.Loc1); System.Console.WriteLine("DTM1 USED"); OpenGate(input, log, contCard, terminal); if ((_CaptureFile.Length > 0) && File.Exists(_CaptureFile)) { FileStream stream = File.OpenRead(_CaptureFile); BinaryReader reader = new BinaryReader(stream); ContCardPic pic = new ContCardPic(); ContCardPICDal contCardPICDal = new ContCardPICDal(); pic.ContCardID = contCard.ContCardID; pic.PicName = "IN"; pic.PicData = reader.ReadBytes((int)stream.Length); reader.Close(); stream.Close(); contCardPICDal.InsertContCardPIC(pic); File.Move(_CaptureFile, string.Concat(new object[] { _CaptureFile, ".", CtsCounter.NextValCtsCounter("CONTCARDPICIN_SEQ"), ".jpg" })); System.Console.WriteLine("Picture Captured To Database."); } } else { System.Console.WriteLine("INPUT IS USED UP OR INVALID !!!"); } } }
private static void ProcessInput(string input, SecureGateLog log) { System.Console.WriteLine("Proses " + input); if (input.Length > 0) { string str = string.Empty; string[] strArray = new string[] { ConfigurationSettings.AppSettings["eiroutprint.printer1.code"], ConfigurationSettings.AppSettings["eiroutprint.printer2.code"] }; if ((strArray[0] == null) || (strArray[0] == string.Empty)) { strArray[0] = "#1"; } if ((strArray[1] == null) || (strArray[1] == string.Empty)) { strArray[1] = "#2"; } if (input.ToUpper().EndsWith(strArray[0].ToUpper())) { input = input.Substring(0, input.Length - strArray[0].Length); posnumber = 1; str = strArray[0]; } else if (input.ToUpper().EndsWith(strArray[1].ToUpper())) { input = input.Substring(0, input.Length - strArray[1].Length); posnumber = 2; str = strArray[1]; } else { //input = input.Substring(0, input.Length - strArray[1].Length); posnumber = 1; str = strArray[0]; } if (str != string.Empty) { System.Console.WriteLine("container card: " + input + " terminal: " + str); _LastProcessedInput = input + str; } else { System.Console.WriteLine("container card: " + input + " terminal: default"); _LastProcessedInput = input; } ContCard card = new ContCard(); ContCardDal contCardDal = new ContCardDal(); card = contCardDal.CheckKendaraan(Convert.ToInt64(input)); System.Console.WriteLine(input); if (card.ContCardID == 0) { System.Console.WriteLine("Card #" + card.ContCardID + " is NOT recognized !!!"); } else if (card.Dtm2.Length == 0) { System.Console.WriteLine("Step 1. Start proceeding MODE " + card.CardMode + " at " + DateTime.Now.ToString("hh:mm:ss")); if ((card.CardMode == "OUT") && (card.ContInOutID > 0L)) { if (!PrintEir(card)) { System.Console.WriteLine("INVALID EIROUT CONDITION DETECTED !!!"); return; } System.Console.Write("Step 7. Updating counter at " + DateTime.Now.ToString("hh:mm:ss") + "..."); //string str2 = ""; //int num = 0; //string str4 = ConfigurationSettings.AppSettings["loginserver"]; //if (string.IsNullOrEmpty(str4)) // str4 = "localhost"; //NpgsqlConnection connection = new NpgsqlConnection("Server=" + str4 + ";Port=5432;User=edimsl;Password=medus;Database=mitcts;"); //connection.Open(); //NpgsqlCommand command = new NpgsqlCommand("select * from counter", connection); //if ((posnumber == 0) || (posnumber == 1)) //{ // str2 = "1"; //} //else if (posnumber == 2) //{ // str2 = "2"; //} //num = Convert.ToInt16(str2) - 1; } else if ((card.CardMode == "IN") && ((card.Dtm3.Length == 0) || (card.UserID3.Length == 0))) { System.Console.WriteLine("INVALID UNLOAD CONDITION DETECTED !!! please scan barcode on unload device before gate out."); return; } card.Dtm2 = GlobalWebServiceDAL.GetServerDtm().ToString("yyyy-MM-dd HH:mm:ss"); card.Loc2 = _SecureGateLocName; contCardDal.UpdateContCardGateOut(card.ContCardID, card.Loc2); System.Console.WriteLine("DTM2 USED"); if (card.CardMode == "OUT") { bool flag2 = false; System.Console.Write("Checking DTM2 at " + DateTime.Now.ToString("hh:mm:ss") + "..."); //new ContInOut().FillByID(card.ContInOutID); flag2 = card.Dtm2.Length > 0; if (flag2) { System.Console.WriteLine("OK"); } if (!flag2) { System.Console.WriteLine("Concard dtmout empty, Please contact Customer Service"); } else { OpenGate(input, log, card); } } else { OpenGate(input, log, card); } if ((_CaptureFile.Length > 0) && File.Exists(_CaptureFile)) { FileStream stream = File.OpenRead(_CaptureFile); BinaryReader reader = new BinaryReader(stream); ContCardPic pic = new ContCardPic(); ContCardPICDal contCardPICDal = new ContCardPICDal(); pic.ContCardID = card.ContCardID; pic.PicName = "OUT"; pic.PicData = reader.ReadBytes((int)stream.Length); reader.Close(); stream.Close(); contCardPICDal.InsertContCardPIC(pic); File.Move(_CaptureFile, string.Concat(new object[] { _CaptureFile, ".", CtsCounter.NextValCtsCounter("CONTCARDPICOUT_SEQ"), ".jpg" })); System.Console.WriteLine("Picture Captured To Database."); } } else { System.Console.WriteLine("DTM 2 (STACKING) IS INVALID !!!"); } } }
private static bool PrintEir(ContCard card) { System.Console.Write("Step 2. Checking INOUTREV at " + DateTime.Now.ToString("hh:mm:ss") + "..."); InOutRevenue revenue = new InOutRevenue(); InOutRevenueDAL revenueDal = new InOutRevenueDAL(); revenue = revenueDal.FillInOutRevenueByInOutRevenueId(card.RefID); System.Console.WriteLine("OK"); System.Console.Write("Step 3. Checking CUSTDO at " + DateTime.Now.ToString("hh:mm:ss") + "..."); CustDo custDo = new CustDo(); CustDoDAL custDoDAL = new CustDoDAL(); custDo = custDoDAL.FillCustDoByCustDoId(revenue.RefId); System.Console.WriteLine("OK"); System.Console.Write("Step 4. Checking CONTINOUT at " + DateTime.Now.ToString("hh:mm:ss") + "..."); ContInOut cont = new ContInOut(); ContInOutDAL contInOutDAL = new ContInOutDAL(); cont = contInOutDAL.FillContInOutById(card.ContInOutID); if (cont.ContInOutId == 0) { System.Console.WriteLine("Error: Container is Invalid."); return(false); } if (cont.DtmOut.Length > 0) { System.Console.WriteLine("Error: Container is Gated Out: " + cont.Cont + " " + cont.DtmOut); return(false); } System.Console.WriteLine("OK"); cont.VesselVoyage = custDo.VesselVoyage; cont.VesselVoyageName = custDo.VesselVoyageName; cont.Destination = custDo.Destination; cont.DestinationName = custDo.DestinationName; cont.DoNumber = custDo.DoNumber; cont.NoSeriOrOut = revenue.NoSeri; cont.ActOut = custDo.ActOut; cont.Shipper = (custDo.ExBatalRealShipper.Length == 0) ? custDo.Shipper : custDo.ExBatalRealShipper; if (custDo.ExBatalRealShipper.Length > 0) { cont.Remarks = "EBO"; } cont.DtmOutDepoIn = DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss"); cont.NoMobilOut = card.NoMobilOut; if (cont.AngkutanOut.Length == 0) { cont.AngkutanOut = card.AngkutanOut; } cont.Seal = card.Seal1; if (cont.DtmOut.Length == 0) { cont.DtmOut = GlobalWebServiceDAL.GetServerDtm().AddMinutes(1.0).ToString("yyyy-MM-dd HH:mm:ss"); } if (cont.DtmOut.Length == 0) { System.Console.WriteLine("Error: DtmOut Empty"); return(false); } TruckInDepo depo = new TruckInDepo(); TruckInDepoDAL depoDAL = new TruckInDepoDAL(); depo = depoDAL.FillByNomobilNotOut(cont.NoMobilOut); if (depo.TruckInDepoId == 0) { depo.DtmOut = GlobalWebServiceDAL.GetServerDtm(); } cont.EirOut = CtsCounter.NextValCtsCounter("EIRCTR").ToString(); cont.Location = ""; try { int contCount; ContInOut out2; if (revenue.TakeDef.Contains(cont.Cont)) { goto Label_04FD; } List <ContInOut> list = new List <ContInOut>(); list = contInOutDAL.FillByNoSeriOrOut(revenue.NoSeri, cont.Size, cont.Type, revenue.TakeDef); int count = list.Count; System.Console.WriteLine("Checking over release of " + count.ToString() + " parties at " + DateTime.Now.ToString("hh:mm:ss") + "..."); System.Console.Write("Please wait...."); ContSpec spec = new ContSpec(); string size = cont.Size; if (size != null) { if (size != "20") { if (size == "40") { goto Label_042E; } if (size == "45") { goto Label_0438; } } else { spec[0] = revenue.Take20; } } goto Label_0442; Label_042E: spec[0] = revenue.Take40; goto Label_0442; Label_0438: spec[0] = revenue.Take45; Label_0442: contCount = 0; foreach (ContSpec item in spec) { if (item.ToString() == cont.Type) { contCount = item.ContTotalCount; } } System.Console.WriteLine("completed at " + DateTime.Now.ToString("hh:mm:ss")); if (contCount <= count) { System.Console.WriteLine("Error: Too Many Container Released"); return(false); } Label_04FD: out2 = new ContInOut(); ContInOutDAL contInOutDAL2 = new ContInOutDAL(); out2 = contInOutDAL2.FillContInOutById(cont.ContInOutId); if (out2.DtmOut.Length > 0) { System.Console.WriteLine("Error: Container " + out2.Cont + " Already Gate Out At " + out2.DtmOut + " !!!"); return(false); } contInOutDAL.UpdateContInOut(cont); if (depo.TruckInDepoId == 0) { System.Console.Write("Step 5. Updating truckindepo at " + DateTime.Now.ToString("hh:mm:ss") + "..."); //depo.Update(null, tr); System.Console.WriteLine("OK"); } System.Console.Write("Step 6. Committing changes at " + DateTime.Now.ToString("hh:mm:ss") + "..."); System.Console.WriteLine("OK"); ContInOut out3 = new ContInOut(); ContInOutDAL contInOutDAL3 = new ContInOutDAL(); out3 = contInOutDAL3.FillContInOutById(cont.ContInOutId); if (out3.DtmOut.Length == 0) { System.Console.WriteLine("Re-Checking: continout dtmout is empty"); return(false); } System.Console.WriteLine("Re-Checking: continout dtmout is OK at " + out3.DtmOut); DoPrintEirOut(cont); return(true); } catch (Exception exception) { System.Console.WriteLine("Error printing : " + exception.Message); return(false); } }
/// <summary> /// Update Container Card /// </summary> /// <param name="contCard"></param> /// <returns></returns> public int UpdateContCard(ContCard contCard) { int rowAffected = 0; try { using (NpgsqlConnection npgsqlConnection = AppConfig.GetConnection()) { if (npgsqlConnection.State == ConnectionState.Closed) { npgsqlConnection.Open(); } string query = " UPDATE contcard " + " SET cardmode=@CardMode, refid=@RefID, cont=@Cont, size=@Size, type=@Type, " + " dtm1=@Dtm1, loc1=@Loc1, dtm2=@Dtm2, loc2=@Loc2, remark=@Remark, dtm3=@dtm3, " + " continoutid=@continoutid, userid3=@userid3, " + " seal1=@seal1, seal2=@seal2, seal3=@seal3, seal4=@seal4, " + " nomobilout=@nomobilout, angkutanout=@angkutanout, " + " eiroutno=@eiroutno, token = @Token, iscombo = @IsCombo " + " WHERE contcardid=@ContCardID "; using (NpgsqlCommand npgsqlCommand = new NpgsqlCommand(query, npgsqlConnection)) { npgsqlCommand.Parameters.AddWithValue("@ContCardID", contCard.ContCardID); npgsqlCommand.Parameters.AddWithValue("@CardMode", contCard.CardMode); npgsqlCommand.Parameters.AddWithValue("@RefID", contCard.RefID); npgsqlCommand.Parameters.AddWithValue("@Cont", contCard.Cont); npgsqlCommand.Parameters.AddWithValue("@Size", contCard.Size); npgsqlCommand.Parameters.AddWithValue("@Type", contCard.Type); if (contCard.Dtm1.HasValue) { npgsqlCommand.Parameters.AddWithValue("@Dtm1", contCard.Dtm1.Value); } else { npgsqlCommand.Parameters.AddWithValue("@Dtm1", DBNull.Value); } npgsqlCommand.Parameters.AddWithValue("@Loc1", contCard.Loc1); if (contCard.Dtm2.HasValue) { npgsqlCommand.Parameters.AddWithValue("@Dtm2", contCard.Dtm2.Value); } else { npgsqlCommand.Parameters.AddWithValue("@Dtm2", DBNull.Value); } npgsqlCommand.Parameters.AddWithValue("@Loc2", contCard.Loc2); npgsqlCommand.Parameters.AddWithValue("@Remark", contCard.Remark); if (contCard.Dtm3.HasValue) { npgsqlCommand.Parameters.AddWithValue("@Dtm3", contCard.Dtm3.Value); } else { npgsqlCommand.Parameters.AddWithValue("@Dtm3", DBNull.Value); } npgsqlCommand.Parameters.AddWithValue("@continoutid", contCard.ContInOutID); npgsqlCommand.Parameters.AddWithValue("@userid3", contCard.UserID3); npgsqlCommand.Parameters.AddWithValue("@seal1", contCard.Seal1); npgsqlCommand.Parameters.AddWithValue("@seal2", contCard.Seal2); npgsqlCommand.Parameters.AddWithValue("@seal3", contCard.Seal3); npgsqlCommand.Parameters.AddWithValue("@seal4", contCard.Seal4); npgsqlCommand.Parameters.AddWithValue("@nomobilout", contCard.NoMobilOut); npgsqlCommand.Parameters.AddWithValue("@angkutanout", contCard.AngkutanOut); npgsqlCommand.Parameters.AddWithValue("@eiroutno", contCard.EirOutNo); npgsqlCommand.Parameters.AddWithValue("@Token", contCard.Token); npgsqlCommand.Parameters.AddWithValue("@IsCombo", contCard.IsCombo); rowAffected = npgsqlCommand.ExecuteNonQuery(); } } } catch (Exception ex) { throw ex; } return(rowAffected); }