public static bool DecideUPSCDSI(UPSDatabase db, ProductInfo productInfo,CDSIPO poInfo, out UPSCombinePO combinePo) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { combinePo = null; if (db.UPSModelEntity.Any(x => x.Model== productInfo.Model && x.Status==EnumUPSModelStatus.Enable.ToString())) { combinePo = db.UPSCombinePOEntity.Where(x => x.Model == productInfo.Model && x.IECPO == poInfo.PO && (x.Status == EnumUPSCombinePOStatus.Free.ToString() || x.Status == EnumUPSCombinePOStatus.Release.ToString())) .OrderBy(x=>x.ID).FirstOrDefault(); return true; } else { return false; } } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
public static bool AssignCNRSPO(AppConfig config, UPSDatabase db, ProductInfo productInfo, CDSIPO poInfo, UPSCombinePO combinePo, out string errorText) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { errorText = string.Empty; //Get AVPart Number string hpPo = combinePo.HPPO; IList<string> avPartNoList = db.UPSPOAVPartEntity.Where(x => x.HPPO == hpPo && x.IECPartNo!=null && x.IECPartNo!="" ) .Select(x=>x.AVPartNo).Distinct().ToList(); if (avPartNoList == null || avPartNoList.Count == 0) { errorText = string.Format("HPPO: {0} Not Find AV PartNo in UPS System", hpPo); return false; } productInfo.ATSNAV = avPartNoList[0]; logger.InfoFormat("HPPO: {0} AVPartNo:{1}", hpPo, avPartNoList[0]); ATMStruct ret = GetATM(productInfo.CUSTSN, productInfo.ATSNAV, combinePo.HPPO); if (ret.retcode < 0 || string.IsNullOrEmpty(ret.assetTagNum)) { errorText = string.Format("UPSATM Return:{0} AssetTag:{1} Message:{2}", ret.retcode.ToString(),ret.assetTagNum??"", ret.message); logger.ErrorFormat(errorText); return false; } else { logger.InfoFormat(" UPSATM Return:{0} Message:{1} Asset Tag:{2}", ret.retcode.ToString(), ret.message, ret.assetTagNum); } string astNum = ret.assetTagNum; #region write db data DateTime now = DateTime.Now; SqlConnection dbconnect = (SqlConnection)db.Connection; if (dbconnect.State == System.Data.ConnectionState.Closed) { dbconnect.Open(); } SqlTransaction dbTxn = dbconnect.BeginTransaction(); db.Transaction = dbTxn; //PoMO SQLStatement.InsertCNRSPoMo(dbconnect, dbTxn, poInfo); //int assignQty = poInfo.DeliveryQty - poInfo.RemainQty; //int specialRemainQty = demianOrder.Qty - assignQty; //if (specialRemainQty == 1) //{ // SQLStatement.UpdateSpecialOrderStatus(dbconnect, poInfo.PO, "Closed"); //} //else if (demianOrder.Status.Equals("Created")) //{ // SQLStatement.UpdateSpecialOrderStatus(dbconnect, poInfo.PO, "Active"); //} //CSIAST table SQLStatement.DeleteCDSIAST(dbconnect, dbTxn, productInfo.ProductID); SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "DID", ""); SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "ASSET_TAG", astNum); SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "HPOrder", combinePo.HPPO); SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "PurchaseOrder", ""); SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "FactoryPO", combinePo.IECPO); SQLStatement.WriteProductAttr(dbconnect, dbTxn, productInfo.ProductID, "CNRSState", "OK", "CNRS", now); //Update UPSCombinePO combinePo.ProductID = productInfo.ProductID; combinePo.CUSTSN = productInfo.CUSTSN; combinePo.Status = EnumUPSCombinePOStatus.Used.ToString(); combinePo.IsShipPO = "CNRS"; combinePo.Udt = now; combinePo.Editor = "UPS.CNRS"; db.SubmitChanges(); dbTxn.Commit(); dbconnect.Close(); #endregion return true; } catch (Exception e) { errorText = e.Message; logger.Error(e.Message, e); return false; } finally { if (db.Connection.State == System.Data.ConnectionState.Open) { db.Connection.Close(); } logger.DebugFormat("END: {0}()", methodName); } }
private static void copyUnattend2ImgSrv(AppConfig config, string unattend, ProductInfo productInfo) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); WindowsImpersonationContext wicCdsi = null; try { if (!string.IsNullOrEmpty(config.IMGServerUser)) { wicCdsi = Logon.ImpersinateUser(config.IMGServerUser, config.IMGDomain, config.IMGServerPassword); } string srcPath = config.IMGFolder + productInfo.CUSTSN + "-" + productInfo.MAC + "\\"; string destPathFile = srcPath + "unattend.xml"; FileOperation.CreateDirectory(srcPath); logger.InfoFormat(" Copy imgServer File : {0}", destPathFile); File.WriteAllText(destPathFile, unattend); } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { if (wicCdsi != null) { Logon.Log_off(wicCdsi); } logger.DebugFormat("END: {0}()", methodName); } }
public static bool AssignUPSPO(AppConfig config, UPSDatabase db, ProductInfo productInfo, CDSIPO poInfo, UPSCombinePO combinePo, out string errorText) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { errorText = string.Empty; //ATMStruct ret = GetATM(productInfo.CUSTSN, productInfo.ATSNAV, combinePo.HPPO); //if (ret.retcode < 0 || string.IsNullOrEmpty(ret.assetTagNum)) //{ // errorText = string.Format(" UPSATM Return:{0} Asset Tag:{1} Message:{2}", ret.retcode.ToString(),ret.assetTagNum??"", ret.message); // logger.ErrorFormat(errorText); // return false; //} //else //{ // logger.InfoFormat(" UPSATM Return:{0} Message:{1} Asset Tag:{2}", ret.retcode.ToString(), ret.message, ret.assetTagNum); //} var hppoData=db.UPSHPPOEntity.Where(x=>x.HPPO== combinePo.HPPO).FirstOrDefault(); string hpSku =hppoData==null?null: hppoData.HPSKU; USIStruct returnUSI= GetUSI(productInfo.CUSTSN, productInfo.ATSNAV, combinePo.HPPO,hpSku); if (returnUSI.retcode < 0 || string.IsNullOrEmpty(returnUSI.unattend)) { errorText = string.Format(" UPSUSI Return:{0} unattend:{1} Message:{2}", returnUSI.retcode.ToString(),returnUSI.unattend ??"", returnUSI.message); logger.ErrorFormat(errorText); return false; } else { logger.InfoFormat(" UPSUSI Return:{0} Message:{1} unattend:{2}", returnUSI.retcode.ToString(), returnUSI.message, returnUSI.unattend); } string unattend = returnUSI.unattend; string astNum = null; XmlDocument doc = new XmlDocument(); doc.LoadXml(unattend); XmlNodeList assetTagNodList = doc.GetElementsByTagName("ComputerName"); XmlNodeList userNodeList = doc.GetElementsByTagName("Credentials"); XmlNodeList admNodeList = doc.GetElementsByTagName("AdministratorPassword"); foreach (XmlNode node in assetTagNodList) { if (!string.IsNullOrEmpty(node.InnerText)) { astNum = node.InnerText; break; } } if (string.IsNullOrEmpty(astNum)) { errorText = string.Format("Asset Tag is empty!"); logger.ErrorFormat(errorText); return false; } copyUnattend2ImgSrv(config, unattend, productInfo); #region write db data DateTime now = DateTime.Now; if (db.Connection.State == System.Data.ConnectionState.Closed) { db.Connection.Open(); } db.Transaction = db.Connection.BeginTransaction(); //SqlTransaction dbTxn= dbconnect.BeginTransaction(); //db.Transaction = dbTxn; SqlConnection dbconnect = (SqlConnection)db.Connection; SqlTransaction transaction = (SqlTransaction)db.Transaction; //PoMO SQLStatement.InsertCDSIPoMo(dbconnect, transaction, poInfo); //CSIAST table SQLStatement.DeleteCDSIAST(dbconnect, transaction, productInfo.ProductID); SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "DID", ""); SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "ASSET_TAG", astNum); SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "HPOrder", combinePo.HPPO); SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "PurchaseOrder", hppoData.EndCustomerPO ?? ""); SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "FactoryPO", combinePo.IECPO); SQLStatement.WriteProductAttr(dbconnect, transaction, productInfo.ProductID, "CDSIState", "OK", "CDSI", now); foreach (XmlNode node in userNodeList) { foreach (XmlNode cnode in node.ChildNodes) { SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, cnode.Name, cnode.InnerText); } } foreach (XmlNode node in admNodeList) { foreach (XmlNode cnode in node.ChildNodes) { if (cnode.Name.ToLower() == "value") { SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "AdministratorPassword", cnode.InnerText); } } } //Update UPSCombinePO combinePo.ProductID = productInfo.ProductID; combinePo.CUSTSN = productInfo.CUSTSN; combinePo.Status = EnumUPSCombinePOStatus.Used.ToString(); combinePo.IsShipPO = "CDSI"; combinePo.Udt = now; combinePo.Editor = "UPS.CDSI"; db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); #endregion return true; } catch (Exception e) { errorText = e.Message; logger.Error(e.Message, e); return false; } finally { if (db.Connection.State == System.Data.ConnectionState.Open) { db.Connection.Close(); } logger.DebugFormat("END: {0}()", methodName); } }
static public List<MO> GetAvailableMO(SqlConnection connect, ProductInfo prodInfo, int startDateoffset, int udtOffset) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { List<MO> ret = new List<MO>(); DateTime now = DateTime.Now; DateTime startDate = now.AddDays(startDateoffset); DateTime udtDate = now.AddDays(udtOffset); SqlCommand dbCmd = connect.CreateCommand(); dbCmd.CommandType = CommandType.Text; dbCmd.CommandText = @"select MO, (Qty-Print_Qty) as qty from MO where Model=@model and StartDate>=@StartDate and Qty>Print_Qty and Status ='H' and Udt>=@UpdateTime order by StartDate, Udt"; SQLHelper.createInputSqlParameter(dbCmd, "@model", 15, prodInfo.Model); SQLHelper.createInputSqlParameter(dbCmd, "@StartDate", 1, startDate); SQLHelper.createInputSqlParameter(dbCmd, "@UpdateTime", udtDate); logger.DebugFormat("SQL {0}", dbCmd.CommandText); logger.DebugFormat("SQL {0} {1}", "@model", prodInfo.Model); logger.DebugFormat("SQL {0} {1}", "@StartDate", startDate.ToString()); logger.DebugFormat("SQL {0} {1}", "@UpdateTime", udtDate.ToString()); SqlDataReader sdr = dbCmd.ExecuteReader(); while (sdr.Read()) { MO mo = new MO(); mo.MOId = sdr.GetString(0).Trim(); mo.Qty = sdr.GetInt32(1); ret.Add(mo); } sdr.Close(); return ret; } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
static public List<Delivery> GetAvailableDelivery(SqlConnection connect, ProductInfo prodInfo, int shipDateoffset) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { List<Delivery> ret = new List<Delivery>(); DateTime now = DateTime.Now; DateTime shipDate = new DateTime(now.Year, now.Month, now.Day); //now.AddDays(shipDateoffset); DateTime shipDateEnd = shipDate.AddDays(shipDateoffset); SqlCommand dbCmd = connect.CreateCommand(); dbCmd.CommandType = CommandType.Text; dbCmd.CommandText = @"select DeliveryNo, PoNo,Qty from Delivery where Model=@model and ShipDate between @ShipDate and @ShipDateEnd and Qty> 0 and Status ='00' order by ShipDate"; SQLHelper.createInputSqlParameter(dbCmd, "@model", 15, prodInfo.Model); SQLHelper.createInputSqlParameter(dbCmd, "@ShipDate", shipDate); SQLHelper.createInputSqlParameter(dbCmd, "@ShipDateEnd", shipDateEnd); logger.DebugFormat("SQL {0}", dbCmd.CommandText); logger.DebugFormat("SQL {0} {1}", "@model", prodInfo.Model); logger.DebugFormat("SQL {0} {1}", "@ShipDate", shipDate.ToString()); logger.DebugFormat("SQL {0} {1}", "@ShipDateEnd", shipDateEnd.ToString()); SqlDataReader sdr = dbCmd.ExecuteReader(); while (sdr.Read()) { Delivery delivery = new Delivery(); delivery.DeliveryNo = sdr.GetString(0).Trim(); delivery.PO = sdr.GetString(1).Trim(); delivery.Qty = sdr.GetInt32(2); ret.Add(delivery); } sdr.Close(); return ret; } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
static public bool AssignPO(SqlConnection connect, AppConfig config, ProductInfo prodInfo, CDSIPO poInfo) { bool selectedPo = false; List<Delivery> poList = GetAvailableDelivery(connect, prodInfo, config.ShipDateOffSetDay); if (poList.Count == 0) return selectedPo; int availableQty = 0; foreach (Delivery po in poList) { availableQty = po.Qty - GetAssignPOQty(connect, po.DeliveryNo, po.PO); if (availableQty > 0) { poInfo.PO = po.PO; poInfo.DeliveryNo = po.DeliveryNo; prodInfo.PO = po.PO; selectedPo = true; break; } } return selectedPo; }
static public ProductInfo GetProductInfo(SqlConnection connect, string prodID) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { ProductInfo Prod = null; SqlCommand dbCmd = connect.CreateCommand(); dbCmd.CommandType = CommandType.Text; dbCmd.CommandText = @"select a.CUSTSN, a.Model, a.MAC, isnull(b.Value,'') as ATSNAV , isnull(c.Value,'') as MN1 , isnull(d.Value,'') as SYSID, a.MO from Product a left join ModelInfo b on a.Model =b.Model and b.Name='ATSNAV' left join ModelInfo c on a.Model =c.Model and c.Name='MN1' left join ModelInfo d on a.Model =d.Model and d.Name='SYSID' where ProductID=@ProductID"; SQLHelper.createInputSqlParameter(dbCmd, "@ProductID", 15, prodID); logger.DebugFormat("SQL {0}", dbCmd.CommandText); logger.DebugFormat("SQL {0} {1}", "@ProductID", prodID); SqlDataReader sdr = dbCmd.ExecuteReader(); while (sdr.Read()) { Prod = new ProductInfo(); Prod.ProductID = prodID; Prod.CUSTSN = sdr.GetString(0).Trim(); Prod.Model = sdr.GetString(1).Trim(); Prod.MAC = sdr.GetString(2).Trim(); Prod.ATSNAV = sdr.GetString(3).Trim(); Prod.MN1 = sdr.GetString(4).Trim(); Prod.SYSID = sdr.GetString(5).Trim(); Prod.MOId = sdr.GetString(6).Trim(); Prod.PO = ""; } sdr.Close(); return Prod; } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
static public bool AssignMO(SqlConnection connect, AppConfig config, ProductInfo prodInfo, CDSIPO poInfo) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { bool selectedMo = false; List<MO> moList = GetAvailableMO(connect, prodInfo, config.MOStartDateOffSetDay, config.MOUdtOffSetDay); if (moList.Count == 0) return selectedMo; int availableQty = 0; foreach (MO mo in moList) { availableQty = mo.Qty - GetAssignMOQty(connect, mo.MOId); if (availableQty > 0) { poInfo.MOId = mo.MOId; selectedMo = true; break; } } return selectedMo; } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
static public List<Delivery> GetAvailableDeliveryByCustPo(SqlConnection connect, ProductInfo prodInfo, int shipDateoffset) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { List<Delivery> ret = new List<Delivery>(); DateTime now = DateTime.Now; DateTime shipDate = new DateTime(now.Year, now.Month, now.Day); //now.AddDays(shipDateoffset); DateTime shipDateEnd = shipDate.AddDays(shipDateoffset); SqlCommand dbCmd = connect.CreateCommand(); dbCmd.CommandType = CommandType.Text; // dbCmd.CommandText = @"select DeliveryNo, PoNo,Qty from Delivery // where Model=@model and // ShipDate between @ShipDate and @ShipDateEnd and // Qty> 0 and // Status ='00' // order by ShipDate"; dbCmd.CommandText = @"select a.DeliveryNo, b.FactoryPO, a.Qty , a.PoNo from Delivery a, DeliveryInfo c, SpecialOrder b where a.DeliveryNo =c.DeliveryNo and c.InfoType='CustPo' and c.InfoValue= b.FactoryPO and b.Status in ('Created','Active') and a.Model=@model and a.ShipDate between @ShipDate and @ShipDateEnd and a.Qty> 0 and a.Status ='00' order by ShipDate"; SQLHelper.createInputSqlParameter(dbCmd, "@model", 15, prodInfo.Model); SQLHelper.createInputSqlParameter(dbCmd, "@ShipDate", shipDate); SQLHelper.createInputSqlParameter(dbCmd, "@ShipDateEnd", shipDateEnd); logger.DebugFormat("SQL {0}", dbCmd.CommandText); logger.DebugFormat("SQL {0} {1}", "@model", prodInfo.Model); logger.DebugFormat("SQL {0} {1}", "@ShipDate", shipDate.ToString()); logger.DebugFormat("SQL {0} {1}", "@ShipDateEnd", shipDateEnd.ToString()); SqlDataReader sdr = dbCmd.ExecuteReader(); while (sdr.Read()) { Delivery delivery = new Delivery(); delivery.DeliveryNo = sdr.GetString(0).Trim(); delivery.PO = sdr.GetString(1).Trim(); delivery.Qty = sdr.GetInt32(2); delivery.CustPo = delivery.PO; delivery.HpPo = sdr.GetString(3).Trim(); delivery.isCustPo = true; ret.Add(delivery); } sdr.Close(); return ret; } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
public static void SendCDSIUpdateCmd(SqlConnection dbconnect, AppConfig config, ProductInfo productInfo, string po, bool isLinkPO, ref string msg) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { string localmsg = ""; // write link PO cmd in LocalSN2POFolder #region send CDSI Cmd WindowsImpersonationContext wicCdsi = null; if (isLinkPO) { if (!string.IsNullOrEmpty(config.CDSIServerUser)) wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser, config.CDSIDomain, config.CDSIServerPassword); CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder, productInfo.CUSTSN, po, config.CDSISN2POFolder); logger.DebugFormat("SendCDSIUpdateCmd {0}", "CDSIFile.LinkPO_Cmd1"); } CDSIFile.SignUp_Cmd2(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, config.CDSIMAILBOXFolder); logger.DebugFormat( "SendCDSIUpdateCmd {0}", "CDSIFile.SignUp_Cmd2"); //Thread.Sleep(config.CDSICmdInterval); CDSIFile.OMSUPDATE_Cmd3(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, productInfo.ATSNAV, productInfo.MN1, productInfo.SYSID, config.CDSIMAILBOXFolder); logger.DebugFormat("SendCDSIUpdateCmd {0}", " CDSIFile.OMSUPDATE_Cmd3"); // don't sleep //Vincent add check result enumCDSIResult result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder, config.CDSIMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC); if (result1 == enumCDSIResult.NotFound) { #region retry again and sleep 5 sec result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder, config.CDSIMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC); #endregion } if (result1 == enumCDSIResult.Err || result1 == enumCDSIResult.NotFound) { #region write error message //send error email localmsg = "<br/> OMSUPDATE_Cmd3 CDSIResultFile -- ProductID:" + productInfo.ProductID + " CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" + (result1 == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") + " Please Check CDSI Server, Error Message:"; msg = msg + localmsg; if (result1 == enumCDSIResult.Err) { string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR"); msg = msg + "<br/>" + string.Join("<br/>", data); localmsg = localmsg + "<br/>" + string.Join("<br/>", data); } logger.DebugFormat("SendCDSIUpdateCmd {0} {1}", "OMSUPDATE_CDSIResultFile", localmsg); #endregion } else { logger.DebugFormat("SendCDSIUpdateCmd {0} {1}", "OMSUPDATE_CDSIResultFile", "Get Ack file"); } #endregion #region SIGNOFF Cmd if (!string.IsNullOrEmpty(config.CDSIServerUser)) wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser, config.CDSIDomain, config.CDSIServerPassword); CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, config.CDSIMAILBOXFolder); logger.DebugFormat("SendCDSIUpdateCmd {0}" , "CDSIFile.SIGNOFF_Cmd5"); if (wicCdsi != null) { Logon.Log_off(wicCdsi); } //Disable sleep Vincent //Thread.Sleep(config.CDSICmdInterval); #endregion } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
public static void SendCDSICmd(SqlConnection dbconnect, AppConfig config, ProductInfo productInfo, string po, bool isLinkPO, ref string msg) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { string localmsg = ""; // write link PO cmd in LocalSN2POFolder #region send CDSI Cmd WindowsImpersonationContext wicCdsi = null; if (isLinkPO) { if (!string.IsNullOrEmpty(config.CDSIServerUser)) wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser, config.CDSIDomain, config.CDSIServerPassword); CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder, productInfo.CUSTSN, po, config.CDSISN2POFolder); logger.DebugFormat( "CDSIFile.LinkPO_Cmd1"); } CDSIFile.SignUp_Cmd2(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, config.CDSIMAILBOXFolder); logger.DebugFormat("CDSIFile.SignUp_Cmd2"); //Thread.Sleep(config.CDSICmdInterval); CDSIFile.OMSUPDATE_Cmd3(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, productInfo.ATSNAV, productInfo.MN1, productInfo.SYSID, config.CDSIMAILBOXFolder); logger.DebugFormat(" CDSIFile.OMSUPDATE_Cmd3"); // don't sleep Thread.Sleep(config.CDSICmdInterval); //Vincent add check result enumCDSIResult result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder, config.CDSIMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC); if (result1 == enumCDSIResult.NotFound) { #region retry again and sleep 5 sec System.Threading.Thread.Sleep(config.CDSICmdInterval); result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder, config.CDSIMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC); #endregion } if (result1 == enumCDSIResult.Err || result1 == enumCDSIResult.NotFound) { #region write error message //send error email localmsg = "<br/> OMSUPDATE_Cmd3 CDSIResultFile -- ProductID:" + productInfo.ProductID + " CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" + (result1 == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") + " Please Check CDSI Server, Error Message:"; msg = msg + localmsg; if (result1 == enumCDSIResult.Err) { string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR"); msg = msg + "<br/>" + string.Join("<br/>", data); localmsg = localmsg + "<br/>" + string.Join("<br/>", data); } logger.DebugFormat( "OMSUPDATE_CDSIResultFile {0}", localmsg); #endregion #region SIGNOFF Cmd if (!string.IsNullOrEmpty(config.CDSIServerUser)) wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser, config.CDSIDomain, config.CDSIServerPassword); CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, config.CDSIMAILBOXFolder); logger.DebugFormat("CDSIFile.SIGNOFF_Cmd5"); if (wicCdsi != null) { Logon.Log_off(wicCdsi); } //Disable sleep Vincent //Thread.Sleep(config.CDSICmdInterval); #endregion return; } CDSIFile.RETRIEVE_Cmd4(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, config.CDSIMAILBOXFolder); logger.DebugFormat("CDSIFile.RETRIEVE_Cmd4"); if (wicCdsi != null) { Logon.Log_off(wicCdsi); } Thread.Sleep(config.CDSICmdInterval); #endregion //Get ACK/ERR file enumCDSIResult result = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder, config.CDSIMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC); logger.DebugFormat("CDSIFile.CheckCDSIResult"); if (result == enumCDSIResult.NotFound) { #region retry again and sleep 5 sec Thread.Sleep(config.CDSICmdInterval); result = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder, config.CDSIMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC); #endregion } if (result == enumCDSIResult.Ack) { logger.DebugFormat( "CheckCDSIResult OK"); #region Copy CDSI Result XML file to local Result folder & Read CDSI XML file CDSIFile.CopyCDSIResultFolder(config.CDSIResultFolder, config.LocalResultFolder, productInfo.CUSTSN, productInfo.MAC); logger.DebugFormat("CopyCDSIResultFolder Copy to Result File CDSIFile.CopyCDSIResultFolder"); enumCDSIResult OMSresult = CDSIFile.CheckCDSIResultByOMS(config.LocalResultFolder, productInfo.CUSTSN, productInfo.MAC, productInfo.ATSNAV); logger.DebugFormat("CheckCDSIResultByOMS Check Result CDSIFile.CheckCDSIResultByOMS"); if (OMSresult == enumCDSIResult.Ack) { string xmlName = productInfo.CUSTSN + "-" + productInfo.MAC + "\\" + productInfo.ATSNAV + ".DAT"; string srcXmlPath = config.LocalResultFolder + xmlName; SQLStatement.ReadXMLCDSIAST(dbconnect, productInfo.ProductID, srcXmlPath); logger.DebugFormat( "ReadXMLCDSIAST Parse XML ReadXMLCDSIAST"); } else { //send error email localmsg = "<br/>CDSI " + " ProductID:" + productInfo.ProductID + " PO:" + po + " " + productInfo.ATSNAV + ".OMS File -- " + (OMSresult == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") + " Please Check CDSI Server!!" + "<br/>"; msg = msg + localmsg; } #endregion #region Copy CDSI file to Image download server if (OMSresult == enumCDSIResult.Ack) { if (!string.IsNullOrEmpty(config.IMGServerUser)) { WindowsImpersonationContext wic = Logon.ImpersinateUser(config.IMGServerUser, config.IMGDomain, config.IMGServerPassword); logger.DebugFormat( " CopyCDSIResultFolder Copy Image Server start CopyCDSIResultFolder"); CDSIFile.CopyCDSIResultFolder(config.LocalResultFolder, config.IMGFolder, productInfo.CUSTSN, productInfo.MAC); logger.DebugFormat( "CopyCDSIResultFolder Copy Image Server end CopyCDSIResultFolder"); Logon.Log_off(wic); } else { logger.DebugFormat( "CopyCDSIResultFolder Copy Image Server start (none login) CopyCDSIResultFolder"); CDSIFile.CopyCDSIResultFolder(config.LocalResultFolder, config.IMGFolder, productInfo.CUSTSN, productInfo.MAC); logger.DebugFormat("CopyCDSIResultFolder Copy Image Server end(none login) CopyCDSIResultFolder"); } } #endregion } else { #region CDSI Result Error & not found then send email //send error email localmsg = "<br/> RETRIEVE_Cmd4 CDSIResultFile -- ProductID:" + productInfo.ProductID + " CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" + (result == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") + " Please Check CDSI Server, Error Message:"; msg = msg + localmsg; string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR"); msg = msg + "<br/>" + string.Join("<br/>", data); localmsg = localmsg + "<br/>" + string.Join("<br/>", data); logger.DebugFormat( "RETRIEVE_CDSIResultFile {0}", localmsg); #endregion } #region SIGNOFF Cmd if (!string.IsNullOrEmpty(config.CDSIServerUser)) wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser, config.CDSIDomain, config.CDSIServerPassword); CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder, productInfo.CUSTSN, productInfo.MAC, config.CDSIMAILBOXFolder); logger.DebugFormat( "CDSIFile.SIGNOFF_Cmd5"); if (wicCdsi != null) { Logon.Log_off(wicCdsi); } //Disable sleep Vincent //Thread.Sleep(config.CDSICmdInterval); #endregion //Delete Local File } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }
public static void SendCDSIPOLinkCmd(SqlConnection dbconnect, AppConfig config, ProductInfo productInfo, string po, ref string msg) { string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; logger.DebugFormat("BEGIN: {0}()", methodName); try { WindowsImpersonationContext wicCdsi = null; if (!string.IsNullOrEmpty(config.CDSIServerUser)) wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser, config.CDSIDomain, config.CDSIServerPassword ); CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder, productInfo.CUSTSN, po, config.CDSISN2POFolder); logger.Debug("CDSIFile.LinkPO_Cmd1"); } catch (Exception e) { logger.Error(e.Message, e); throw; } finally { logger.DebugFormat("END: {0}()", methodName); } }