using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; //using eWayPayment; using System.Security.Cryptography; using System.Xml; using System.Text; using System.IO; using DataAccessLayer; public partial class PaymentDetails : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { txtCardNumber.Attributes.Add("autocomplete", "off"); if (!IsPostBack) { LoadYear(); if (Session["Member"] != null) { Customer objDummy = (Customer)Session["Member"]; if (objDummy.MemberId != 0) { Customer objCredit = CustomerTrans.GetCreditCardDetailsByMemberId(objDummy.MemberId); if (objCredit.MemberId != 0) { txtCardNumber.Text = DecryptCreditcardNumber(objCredit.CreditCardNumber); hdnCNum.Value = DecryptCreditcardNumber2(objCredit.CreditCardNumber); txtHolderName.Text = objCredit.CardHolder; try { ddlCardType.ClearSelection(); ddlCardType.Items.FindByText(objCredit.CreditType).Selected = true; } catch (Exception ex) { } char[] ar ={ '/' }; string[] expdate = objCredit.ExpiryDate.Split(ar); if (expdate.Length == 2) { try { ddlExpmonth.ClearSelection(); ddlExpmonth.Items.FindByText(expdate[0].Trim()).Selected = true; } catch (Exception ex) { } try { ddlExpYear.ClearSelection(); ddlExpYear.Items.FindByText(expdate[1].Trim()).Selected = true; } catch (Exception ex) { } } } } } } if (Session["MyBasket"] != null) { DataTable dtBasket = (DataTable)Session["MyBasket"]; if (dtBasket != null && dtBasket.Rows.Count > 0) { if (Session["OrderInfo"] == null) { Response.Redirect("DeliveryDetails.aspx"); } else { ltrDelTot.Text = "$ " + dtBasket.Compute("sum(ProductSum)", "").ToString(); ltrDel.Text = dtBasket.Rows[0]["DeliveryRate"].ToString(); ; //decimal gst = Convert.ToDecimal(Math.Round ( Convert.ToDecimal(dtBasket.Compute("sum(ProductSum)", "").ToString()) * Convert.ToDecimal(0.11),2)); decimal gst = Convert.ToDecimal("0.00"); ltrGst.Text = gst.ToString(); ltrOrder.Text = Convert.ToString(Convert.ToDecimal(dtBasket.Compute("sum(ProductSum)", "").ToString()) + Convert.ToDecimal("15.00")+gst); if (Session["Member"] != null) { tblTotal.Visible = true; // ltrTotal.Text = "$ " + dtBasket.Compute("sum(ProductSum)", "").ToString(); object[] objInfo = (object[])Session["OrderInfo"]; DataTable dtInfo = (DataTable)objInfo[1]; if (dtInfo != null) { ltrRecCount.Text = dtInfo.Rows.Count.ToString(); ltrRecTotal.Text = Convert.ToString(Convert.ToInt32(dtInfo.Rows.Count.ToString()) * Convert.ToDecimal(Convert.ToString(Convert.ToDecimal(dtBasket.Compute("sum(ProductSum)", "").ToString()) + Convert.ToDecimal("15.00")+gst))); ltrTotal.Text = "$ " + Convert.ToString(Convert.ToInt32(dtInfo.Rows.Count.ToString()) * Convert.ToDecimal(Convert.ToString(Convert.ToDecimal(dtBasket.Compute("sum(ProductSum)", "").ToString()) + Convert.ToDecimal("15.00")+gst))); } } else { tblTotal.Visible = false; ltrTotal.Text = "$ " + Convert.ToString (Convert.ToDecimal(dtBasket.Compute("sum(ProductSum)", "").ToString())+ Convert.ToDecimal("15.00")+gst); } } } else { Response.Redirect("ViewBasket.aspx"); } } else Response.Redirect("ViewBasket.aspx"); this.Page.Title = "Payment Details - XXXXXXX"; } private string DecryptCreditcardNumber(string number) { if (number != "") { RijndaelManaged RijndaelCipher = new RijndaelManaged(); string Password = "CSC"; string DecryptedData; try { byte[] EncryptedData = Convert.FromBase64String(number); byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); //Making of the key for decryption PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt); //Creates a symmetric Rijndael decryptor object. ICryptoTransform Decryptor = XXXXXXX(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(EncryptedData); //Defines the cryptographics stream for decryption.THe stream contains decrpted data CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read); byte[] PlainText = new byte[EncryptedData.Length]; int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close(); cryptoStream.Close(); //Converting to string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount); string cardNumber = DecryptedData; string firstfour = cardNumber.Substring(0, 4).Trim(); string middleEight = cardNumber.Substring(4, 8).Trim(); string lastFour = cardNumber.Substring(12, 4); DecryptedData = firstfour + "XXXXXXXX" + lastFour; // return dcryptNumber; } catch { DecryptedData = ""; } return DecryptedData; } else return ""; } private string DecryptCreditcardNumber2(string number) { if (number != "") { XXXXXXX string Password = "XXXXXXX"; string DecryptedData; try { byte[] EncryptedData = Convert.FromBase64String(number); byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); //Making of the key for decryption PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, XXXXXXX); //Creates a symmetric Rijndael decryptor object. ICryptoTransform Decryptor = XXXXXXX, SecretKey.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(EncryptedData); //Defines the cryptographics stream for decryption.THe stream contains decrpted data CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read); byte[] PlainText = new byte[EncryptedData.Length]; int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close(); cryptoStream.Close(); //Converting to string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount); } catch { DecryptedData = ""; } return DecryptedData; } else return ""; } private void LoadYear() { ddlExpYear.Items.Clear(); int year = DateTime.Today.Year + 6; for (int stYear = DateTime.Today.Year; stYear <= year; stYear++) { ddlExpYear.Items.Add(new ListItem(stYear.ToString(), stYear.ToString())); } ddlExpYear.Items.Insert(0, new ListItem("Expiry Year", "0")); } protected void btnOrder_Click(object sender, EventArgs e) { lblMsg.Visible = false; if (Common.Comparedate(Convert.ToDateTime(DateTime.Today.Month + "/" + DateTime.Today.Year), Convert.ToDateTime(ddlExpmonth.SelectedValue + "/" + ddlExpYear.SelectedValue))) { if (Session["OrderInfo"] != null) { object[] objInfo = (object[])Session["OrderInfo"]; OPS objOPS = (OPS)objInfo[2]; if (PayMentProcess(objOPS.DeliveryTypeId, objInfo[0])) { OrderProcessing(); } else { txtCardNumber.Text = ""; txtHolderName.Text = ""; ddlCardType.SelectedIndex = 0; ddlExpmonth.SelectedIndex = 0; ddlExpYear.SelectedIndex = 0; } } else Response.Redirect("Index.aspx"); } else { lblMsg.Visible = true; lblMsg.Text = "*Expiry date is already past."; } } private bool PayMentProcess(int delTypeId,object objCust) { lblMsg.Visible = true; if (delTypeId == 1) { GatewayConnector XXXXXXX = new GatewayConnector(); GatewayRequest XXXXXXX = new GatewayRequest(); try { //XXXXXXXRequest.XXXXXXXCustomerID = "XXXXXXX"; XXXXXXXRequest.XXXXXXXCustomerID = "XXXXXXX"; //get values input by user on form, or set to database values //XXXXXXXgateway.Uri = "https://www.XXXXXXX"; XXXXXXXgateway.Uri = "https://www.XXXXXXX"; XXXXXXXRequest.CardNumber = txtCardNumber.Text.Trim(); XXXXXXXRequest.CardExpiryMonth = ddlExpmonth.SelectedValue; XXXXXXXRequest.CardExpiryYear = ddlExpYear.SelectedValue; XXXXXXXRequest.CardHolderName = txtHolderName.Text.Trim(); string val = ltrTotal.Text.Trim().Remove(0, 1).Trim(); //string val = "10"; decimal dcVal = Convert.ToDecimal(val)*100; XXXXXXXRequest.InvoiceAmount = Convert.ToInt32(dcVal); //int // Do the payment, send XML doc containing information gathered if (XXXXXXXgateway.ProcessRequest(XXXXXXXRequest)) { // payment succesfully sent to gateway GatewayResponse XXXXXXXResponse = XXXXXXXgateway.Response; if (XXXXXXXResponse != null) { lblMsg.Text = ""; lblMsg.Text += "<b>Sorry, unfortunately your transaction FAILED!</b><br/><br/>"; lblMsg.Text += " XXXXXXXTrxnStatus: " + XXXXXXXResponse.Status + "<br/>"; lblMsg.Text += " XXXXXXXAuthCode: " + XXXXXXXResponse.AuthorisationCode + "<br/>"; lblMsg.Text += " XXXXXXXTrxnError: " + XXXXXXXResponse.Error + "<br/>"; lblMsg.Text += " XXXXXXXInvoiceRef: " + XXXXXXXResponse.TransactionNumber + "<br/>"; lblMsg.Text += " XXXXXXXReturnAmount: " + XXXXXXXResponse.Amount + "<br/>"; lblMsg.Text += " XXXXXXXTrxnNumber: " + XXXXXXXResponse.InvoiceReference + "<br/>"; lblMsg.Text += "<p style='color:Black;'><br/><br/>If you have entered an invalid card number please try again! Or contact our friendly customer service on XXXXXXX - Monday to Friday 8:00am to 4:00pm (AEST).</p>"; bool status= XXXXXXXResponse.Status; if (status == false) { if (Session["Member"] != null) { Customer objDummy = (Customer)Session["Member"]; if (objDummy.MemberId != 0) { Customer objCredit = CustomerTrans.GetCreditCardDetailsByMemberId(objDummy.MemberId); XXXXXXXRequest.CardNumber = DecryptCreditcardNumber2(objCredit.CreditCardNumber); hdnCNum.Value = XXXXXXXRequest.CardNumber; if (XXXXXXXgateway.ProcessRequest(XXXXXXXRequest)) { GatewayResponse XXXXXXXResponse2 = XXXXXXXgateway.Response; if (XXXXXXXResponse2 != null) { lblMsg.Text = ""; lblMsg.Text += "<b>Sorry, unfortunately your transaction FAILED!</b><br/><br/>"; lblMsg.Text += " XXXXXXXTrxnStatus: " + XXXXXXXResponse2.Status + "<br/>"; lblMsg.Text += " XXXXXXXAuthCode: " + XXXXXXXResponse2.AuthorisationCode + "<br/>"; lblMsg.Text += " XXXXXXXTrxnError: " + XXXXXXXResponse2.Error + "<br/>"; lblMsg.Text += " XXXXXXXInvoiceRef: " + XXXXXXXResponse2.TransactionNumber + "<br/>"; lblMsg.Text += " XXXXXXXReturnAmount: " + XXXXXXXResponse2.Amount + "<br/>"; lblMsg.Text += " XXXXXXXTrxnNumber: " + XXXXXXXResponse2.InvoiceReference + "<br/>"; lblMsg.Text += "<p style='color:Black;'><br/><br/>If you have entered an invalid card number please try again! Or contact our friendly customer service on XXXXXXX - Monday to Friday 8:00am to 4:00pm (AEST).</p>"; status = XXXXXXXResponse2.Status; } } } } } else { hdnCNum.Value = txtCardNumber.Text.Trim(); } return status; //return true; } else { lblMsg.Text = "Error: An invalid response was recieved from the payment gateway."; return false; } } else { lblMsg.Text = "Error: Connection to the payment gateway failed. Check gateway URL or XML sent." + Server.UrlEncode(XXXXXXXRequest.ToXml().ToString()); return false; } } catch (Exception ex) { string strErrorMessage = "<!-- " + ex.Source + "\r\n" + ex.Message + "\r\n" + ex.StackTrace + "\r\n-->"; //exception occured lblMsg.Text = strErrorMessage; return false; } } else { try { if (Session["schDel"] != null) { Customer objCustomer = (Customer)objCust; OPS objSCH = (OPS)Session["schDel"]; if (txtCardNumber.Text.Trim() != "") { if (txtCardNumber.Text.Trim().Contains("XXXXXXXX")) { if (Session["Member"] != null) { Customer objDummy = (Customer)Session["Member"]; if (objDummy.MemberId != 0) { Customer objCredit = CustomerTrans.GetCreditCardDetailsByMemberId(objDummy.MemberId); hdnCNum.Value = DecryptCreditcardNumber2(objCredit.CreditCardNumber); return true; } else return false; } else return false; } else { hdnCNum.Value = txtCardNumber.Text.Trim(); return true; } } else return false; } else return false; } catch (Exception ex3) { lblMsg.Visible = true; lblMsg.Text = ex3.Message; return false; } return false; } } private string GetIntervalType(int type) { if (type == 2) return "1"; else if (type == 3) return "2"; else if (type == 4) return "3"; else if (type == 5) return "4"; else return "1"; } private int SaveRecipientAddress(int recId) { Recipient objRecipient = RecipientTrans.GetRecipientById(recId); if (objRecipient != null) { RecipientAddress objRecAdd = new RecipientAddress(); objRecAdd.Company = objRecipient.Company; objRecAdd.Country = objRecipient.Country; objRecAdd.EmailAddress = objRecipient.EmailAddress; objRecAdd.FaxCode = objRecipient.FaxCode; objRecAdd.FaxNumber = objRecipient.FaxNumber; objRecAdd.HomePhoneCode = objRecipient.HomePhoneCode; objRecAdd.HomePhoneNumber = objRecipient.HomePhoneNumber; objRecAdd.HospialName = objRecipient.HospialName; objRecAdd.IsOverSeas = objRecipient.IsOverSeas; objRecAdd.Mobilenumber = objRecipient.Mobilenumber; objRecAdd.OverSeasCountry = objRecipient.OverSeasCountry; objRecAdd.OverSeasPostCode = objRecipient.OverSeasPostCode; objRecAdd.OverSeasState = objRecipient.OverSeasState; objRecAdd.OverSeasTown = objRecipient.OverSeasTown; objRecAdd.PostCode = objRecipient.PostCode; objRecAdd.RecAddId = 0; objRecAdd.RecipientAddress1 = objRecipient.RecipientAddress; objRecAdd.RecipientId = recId; objRecAdd.StateId = objRecipient.StateId; objRecAdd.SuburbId = objRecipient.SuburbId; objRecAdd.WorkCode = objRecipient.WorkCode; objRecAdd.WorkNumber = objRecipient.WorkNumber; return RecipientTrans.InsertOrUpdateRecipientAddress(objRecAdd); } else return 0; } private int SaveRecipientOrder(Recipient objRecipient, int recId) { RecipientAddress objRecAdd = new RecipientAddress(); objRecAdd.Company = objRecipient.Company; objRecAdd.Country = objRecipient.Country; objRecAdd.EmailAddress = objRecipient.EmailAddress; objRecAdd.FaxCode = objRecipient.FaxCode; objRecAdd.FaxNumber = objRecipient.FaxNumber; objRecAdd.HomePhoneCode = objRecipient.HomePhoneCode; objRecAdd.HomePhoneNumber = objRecipient.HomePhoneNumber; objRecAdd.HospialName = objRecipient.HospialName; objRecAdd.IsOverSeas = objRecipient.IsOverSeas; objRecAdd.Mobilenumber = objRecipient.Mobilenumber; objRecAdd.OverSeasCountry = objRecipient.OverSeasCountry; objRecAdd.OverSeasPostCode = objRecipient.OverSeasPostCode; objRecAdd.OverSeasState = objRecipient.OverSeasState; objRecAdd.OverSeasTown = objRecipient.OverSeasTown; objRecAdd.PostCode = objRecipient.PostCode; objRecAdd.RecAddId = 0; objRecAdd.RecipientAddress1 = objRecipient.RecipientAddress; objRecAdd.RecipientId = recId; objRecAdd.StateId = objRecipient.StateId; objRecAdd.SuburbId = objRecipient.SuburbId; objRecAdd.WorkCode = objRecipient.WorkCode; objRecAdd.WorkNumber = objRecipient.WorkNumber; return RecipientTrans.InsertOrUpdateRecipientAddress(objRecAdd); } private void OrderProcessing() { if (Session["OrderInfo"] != null) { object[] objInfo = (object[])Session["OrderInfo"]; if (objInfo.Length == 3) { Customer objCustomer =(Customer) objInfo[0]; Recipient objRecipient =null; DataTable dtRecipients = null; OPS objOPS = (OPS)objInfo[2]; if (objCustomer.MemberId != 0 && Session["Member"] != null) { dtRecipients = (DataTable)objInfo[1]; ArrayList objOrList = new ArrayList(); foreach (DataRow drRec in dtRecipients.Rows) { objOPS.OrderId = 0; objOPS.MemberId = objCustomer.MemberId; objOPS.RecipientId =Convert.ToInt32 (drRec["RecipientId"].ToString ()); objOPS.RecipientAddressId = SaveRecipientAddress(Convert.ToInt32(drRec["RecipientId"].ToString())); objOPS.DeliveryRecurrence = 1; objOPS.OrderStatusId = 1; objOPS.OrderStatusDescription = ""; objOPS.Recurrence = 1; //objOPS.IsPaid = 1; /* if (objOPS.PaymentType == 1 || objOPS.PaymentType == 0) {*/ if (objOPS.DeliveryTypeId != 1) { if (objOPS.IsPaid != 1) { objOPS.IsPaid = 0; } } else { objOPS.IsPaid = 1; } /*} else objOPS.IsPaid = 1; */ int orderId = OPSTrans.InsertOrderProcess(objOPS); if (orderId > 0) { if (objOPS.DeliveryTypeId != 1) { if (Session["objArList"] != null) { ArrayList objArList = (ArrayList)Session["objArList"]; if (objArList.Count > 0) { int reBillId= CustomerTrans.InsertRebillCustomers(orderId, objArList[0].ToString(), Convert.ToDecimal(objArList[1].ToString ())); } Session["objArList"] = null; } } GetOrderDeldate(objOPS, orderId); DataTable dtBasket = (DataTable)Session["MyBasket"]; if (dtBasket != null) { foreach (DataRow dr in dtBasket.Rows) { objOPS.OrderId = orderId; objOPS.ProductId = Convert.ToInt32(dr["ProductId"].ToString()); objOPS.Quantity = Convert.ToInt32(dr["Quantity"].ToString()); objOPS.UnitPrice = Convert.ToDecimal(dr["FFPrice"].ToString().Trim().Remove(0, 1).Trim()); objOPS.IsAddOnProduct = dr["ProductType"].ToString().Trim() == "P" ? 1 : 2; objOPS.PromotionId = 0; objOPS.ProductSize = dr["ProductSize"].ToString().Trim(); //objOPS.ProductColor = ""; objOPS.ProductColor = dr["ProductColor"].ToString().Trim(); OPSTrans.InsertOrderProductDetails(objOPS); } objOrList.Add(orderId); } } Session["Orderids"] = objOrList; } objCustomer.CardHolder = txtHolderName.Text.Trim(); objCustomer.CreditCardId = 0; //objCustomer.CreditCardNumber =EncryptCreditCardNumber(txtCardNumber.Text.Trim()); objCustomer.CreditCardNumber = EncryptCreditCardNumber(hdnCNum.Value); objCustomer.CreditType = ddlCardType.SelectedItem.Text; objCustomer.ExpiryDate = ddlExpmonth.SelectedItem.Text + "/" + ddlExpYear.SelectedItem.Text; int creditCard= CustomerTrans.InsertOrUpdateCreditCardDetails(objCustomer); SendTaxInvoice(objInfo); Session["MyBasket"] = null; Session["OrderInfo"] = null; Session["schDel"] = null; Response.Redirect("Message.aspx?msgId=1&scId=y"); } else { objRecipient = (Recipient)objInfo[1]; int custId= CustomerTrans.InsertOrUpdateMemberDetails(objCustomer); if (custId > 0) { objRecipient.MemberId = custId; int recepId=RecipientTrans.SaveOrUpdateRecipientDetails(objRecipient); int recAddId = SaveRecipientOrder(objRecipient, recepId); if (recepId > 0) { objOPS.MemberId = custId; objOPS.RecipientId = recepId; objOPS.RecipientAddressId = recAddId; objOPS .DeliveryRecurrence =1; objOPS .OrderStatusId =1; objOPS .OrderStatusDescription =""; objOPS .Recurrence =1; objOPS .IsPaid =1; int orderId=OPSTrans.InsertOrderProcess(objOPS); if (orderId > 0) { GetOrderDeldate(objOPS, orderId); DataTable dtBasket = (DataTable)Session["MyBasket"]; if (dtBasket != null) { foreach (DataRow dr in dtBasket.Rows) { objOPS.OrderId = orderId; objOPS.ProductId = Convert.ToInt32(dr["ProductId"].ToString ()); objOPS.Quantity = Convert.ToInt32(dr["Quantity"].ToString ()); objOPS.UnitPrice = Convert.ToDecimal(dr["FFPrice"].ToString().Trim().Remove(0,1).Trim ()); objOPS.IsAddOnProduct = dr["ProductType"].ToString().Trim() == "P" ? 1 : 2; objOPS.ProductSize = dr["ProductSize"].ToString().Trim(); objOPS.PromotionId = 0; // objOPS.ProductColor = ""; objOPS.ProductColor = dr["ProductColor"].ToString().Trim(); OPSTrans.InsertOrderProductDetails(objOPS); } } objCustomer.MemberId = custId; objCustomer.CardHolder = txtHolderName.Text.Trim(); objCustomer.CreditCardId = 0; //objCustomer.CreditCardNumber = txtCardNumber.Text.Trim(); //objCustomer.CreditCardNumber = EncryptCreditCard(txtCardNumber.Text.Trim()); //objCustomer.CreditCardNumber = EncryptCreditCardNumber(txtCardNumber.Text.Trim()); objCustomer.CreditCardNumber = EncryptCreditCardNumber(hdnCNum.Value); objCustomer.CreditType = ddlCardType.SelectedItem.Text; objCustomer.ExpiryDate = ddlExpmonth.SelectedItem.Text + "/" + ddlExpYear.SelectedItem.Text; int creditCard = CustomerTrans.InsertOrUpdateCreditCardDetails(objCustomer); SendTaxInvoice(objInfo); Session["MyBasket"] = null; Session["OrderInfo"] = null; Response.Redirect("Message.aspx?msgId=1&OId="+objOPS.OrderId.ToString ()); } } } } } } } private void GetOrderDeldate(OPS objOps, int ordId) { OPS objOrDels = new OPS(); objOrDels.OrderDeliveryId = 0; objOrDels.OrderId = ordId; int repeat = 0; if (objOps.DeliveryTypeId != 1) { int rec = 0; DateTime dtOrDate = objOps.DeliveryStartDate; int rngId = 0; if (objOps.RangeTypeId == 0) { rngId = 20; } else { rngId = objOps.EndAfter; if (rngId == 0) { /* if (dtOrDate < objOps.EndBy) { if (objOps.DeliveryTypeId == 4) { rngId = monthDifference(dtOrDate, objOps.EndBy); } else if (objOps.DeliveryTypeId == 5) { rngId = objOps.EndBy.Year - dtOrDate.Year; } }*/ rngId = 1; } } while (rec < rngId) { if (objOps.DeliveryTypeId == 2) { if (objOps.PatternNumber == 0) { /*if (rec == 0) {*/ objOrDels.OrderDeliveryDate = dtOrDate; /* } else { // objOrDels.OrderDeliveryDate = dtOrDate.AddDays(Convert.ToDouble(objOps.IntervalType)); }*/ } else { /*if (rec == 0) {*/ objOrDels.OrderDeliveryDate = dtOrDate; /* } else { //objOrDels.OrderDeliveryDate = dtOrDate.AddDays(Convert.ToDouble(objOps.IntervalType)); }*/ } //objOrDels.OrderDeliveryDate = dtDeldate; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; repeat = 1; dtOrDate = dtOrDate.AddDays(Convert.ToDouble(objOps.IntervalType)); if (objOps.EndAfter == 0) { if (dtOrDate < objOps.EndBy) { rngId++; } else { rec = rngId; } } } if (objOps.DeliveryTypeId == 3) { int days = (Convert.ToInt32(objOps.IntervalType) * 7); DateTime dtRunDate = dtOrDate; DateTime dtBeginningOfWeek = dtRunDate.AddDays(-1 * Convert.ToInt16(dtRunDate.DayOfWeek)); DateTime dtEndOfWeek = dtBeginningOfWeek.AddDays(Convert.ToDouble("6")); string weeks = objOps.Pattern1.Replace("Recur every " + objOps.IntervalType.ToString().Trim() + " week(s) on: ", "").Trim(); char[] Splitter ={ ',' }; string[] splitWeek = weeks.Split(Splitter); if (splitWeek.Length != 0) { int wDay = 1; while (wDay < 7) { DateTime dtDeldate = dtBeginningOfWeek.AddDays(Convert.ToDouble(wDay.ToString())); for (int i = 0; i < splitWeek.Length; i++) { if (dtDeldate < dtRunDate && repeat == 0) { } else { if (splitWeek[i].Trim().ToLower() == "monday") { if (dtDeldate.DayOfWeek == DayOfWeek.Monday) { objOrDels.OrderDeliveryDate = dtDeldate; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; dtOrDate = dtDeldate; repeat = 1; } } if (splitWeek[i].Trim().ToLower() == "tuesday") { if (dtDeldate.DayOfWeek == DayOfWeek.Tuesday) { objOrDels.OrderDeliveryDate = dtDeldate; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; dtOrDate = dtDeldate; repeat = 1; } } if (splitWeek[i].Trim().ToLower() == "wednesday") { if (dtDeldate.DayOfWeek == DayOfWeek.Wednesday) { objOrDels.OrderDeliveryDate = dtDeldate; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; dtOrDate = dtDeldate; repeat = 1; } } if (splitWeek[i].Trim().ToLower() == "thursday") { if (dtDeldate.DayOfWeek == DayOfWeek.Thursday) { objOrDels.OrderDeliveryDate = dtDeldate; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; dtOrDate = dtDeldate; repeat = 1; } } if (splitWeek[i].Trim().ToLower() == "friday") { if (dtDeldate.DayOfWeek == DayOfWeek.Friday) { objOrDels.OrderDeliveryDate = dtDeldate; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; dtOrDate = dtDeldate; repeat = 1; } } } if (objOps.EndAfter == 0) { if (dtDeldate < objOps.EndBy) { rngId++; } else { rec = rngId; } } if (rec >= rngId) break; } wDay++; if (objOps.EndAfter == 0) { if (dtDeldate < objOps.EndBy) { rngId++; } else { rec = rngId; } } if (rec >= rngId) break; } dtOrDate = dtOrDate.AddDays(Convert.ToDouble(days.ToString())); if (objOps.EndAfter == 0) { if (dtOrDate < objOps.EndBy) { rngId++; } else { rec = rngId; } } } } if (objOps.DeliveryTypeId == 4) { if (objOps.Pattern1 != "" && objOps.Pattern2 == "") { string day = objOps.Pattern1.Substring(0, objOps.Pattern1.LastIndexOf("of every")).Trim(); DateTime delDates = Convert.ToDateTime(dtOrDate.Month.ToString() + "/" + day + "/" + dtOrDate.Year.ToString()); while (rec < rngId) { if (delDates < dtOrDate && repeat == 0) { //delDates = Convert.ToDateTime(delDates).AddMonths(Convert.ToInt32(objOps.IntervalType)); delDates = Convert.ToDateTime(delDates).AddMonths(Convert.ToInt32("1")); } else { objOrDels.OrderDeliveryDate = delDates; objOrDels.OrderDeliveryRecurrence = (rec + 1); OPSTrans.InsertOrUpdateOrderDeliveryDates(objOrDels); rec++; delDates = Convert.ToDateTime(delDates).AddMonths(Convert.ToInt32(objOps.IntervalType)); dtOrDate = delDates; repeat = 1; if (objOps.EndAfter == 0) { if (dtOrDate < objOps.EndBy) { rngId++; } else { rec = rngId; } } } } } {
else if (objOps.Pattern1 == "" && objOps.Pattern2 != "")