Esempio n. 1
0
    public string resendRFQ()
    {
        GatewayResponse response = new GatewayResponse();
        String          s;
        RFQ             rfqToResend;

        try
        {
            s           = new StreamReader(Request.InputStream).ReadToEnd();
            rfqToResend = JsonConvert.DeserializeObject <RFQ>(s);
        }
        catch (Exception ex)
        {
            response.ErrorThrown         = true;
            response.ResponseDescription = "ERROR: When trying to parse JSON in server. " + ex.Message;
            return(JsonConvert.SerializeObject(response));
        }

        UserCRUD user_CRUD   = new UserCRUD();
        string   strAuthUser = HttpContext.Current.User.Identity.Name;
        User     user        = user_CRUD.readById(strAuthUser);

        SupplierCRUD supplier_CRUD = new SupplierCRUD();
        Supplier     supplier      = supplier_CRUD.readById(rfqToResend.SupplierId);

        if (supplier != null)
        {
            if (supplier.ContactEmail.Trim() != rfqToResend.LastEmail.Trim())
            {
                supplier.ContactEmail = rfqToResend.LastEmail.Trim();
                if (!supplier_CRUD.update(supplier))
                {
                    response.ErrorThrown         = true;
                    response.ResponseDescription = "ERROR:" + supplier_CRUD.ErrorMessage;
                    return(JsonConvert.SerializeObject(response));
                }
            }
        }

        TokenCRUD token_CRUD = new TokenCRUD();
        Token     token      = token_CRUD.readByRFQ(rfqToResend);

        ConnectionManager CM = new ConnectionManager();

        Data_Base_MNG.SQL DM = CM.getDataManager();

        /*Begin Transaction*/
        DM.Open_Connection("RFQ Re-send");

        rfqToResend.SentToVendor = DateTime.Now;
        if (!rfq_CRUD.update(rfqToResend, ref DM))
        {
            response.ErrorThrown         = true;
            response.ResponseDescription = "ERROR:" + rfq_CRUD.ErrorMessage;
            return(JsonConvert.SerializeObject(response));
        }

        if (token == null)
        {
            token             = new Token();
            token.Subject     = "RFQ";
            token.SubjectKey  = rfqToResend.Id;
            token.TokenNumber = MD5HashGenerator.GenerateKey(DateTime.Now);
            token_CRUD.create(token, ref DM);
            if (token_CRUD.ErrorOccur)
            {
                response.ErrorThrown         = true;
                response.ResponseDescription = "ERROR:" + token_CRUD.ErrorMessage;
                return(JsonConvert.SerializeObject(response));
            }
        }


        Email       NewMail = new Email();
        MailMessage Message = new MailMessage();

        try
        {
            Message.From = new MailAddress("*****@*****.**", "*****@*****.**");
            Message.To.Add(new MailAddress(supplier.ContactEmail.ToString()));
            Message.Subject      = "Request For Quote";
            Message.IsBodyHtml   = true;
            Message.BodyEncoding = System.Text.Encoding.UTF8;

            var url             = ResolveUrl("~/Vendor/Email_RFQ_Request.htm");
            var strEmailContent = HTMLContent(url);
            strEmailContent = strEmailContent.Replace("{BuyerName}", user.Name);
            strEmailContent = strEmailContent.Replace("{BuyerPhone}", user.Phone1);
            strEmailContent = strEmailContent.Replace("{BuyerEmail}", user.Email);
            strEmailContent = strEmailContent.Replace("{RFQ Number}", rfqToResend.RfqGenerated);
            strEmailContent = strEmailContent.Replace("{Part Number}", rfqToResend.PartNumber);
            strEmailContent = strEmailContent.Replace("{RFQLink}", "http://" + Request.Url.Authority + Request.ApplicationPath + "/Vendor/RFQHandler.ashx?token=" + token.TokenNumber);

            Message.Body = strEmailContent;


            NewMail.SendMail(Message);
        }
        catch (Exception ex)
        {
            DM.RollBack();
            response.ErrorThrown         = true;
            response.ResponseDescription = "ERROR: Could not send email to: " + supplier.ContactEmail.ToString();
            return(JsonConvert.SerializeObject(response));
        }

        DM.CommitTransaction();
        DM.Close_Open_Connection();

        if (DM.ErrorOccur)
        {
            response.ErrorThrown         = true;
            response.ResponseDescription = "ERROR:" + DM.Error_Mjs;
            return(JsonConvert.SerializeObject(response));
        }

        response.ErrorThrown         = false;
        response.ResponseDescription = "RFQ " + rfqToResend.RfqGenerated + " re-sent successfully.";
        response.Result = rfqToResend;
        return(JsonConvert.SerializeObject(response));
    }
Esempio n. 2
0
    public string sendRFQ()
    {
        List <RFQ>      resultRFQs = new List <RFQ>();
        GatewayResponse response   = new GatewayResponse();
        String          s;
        NewRFQScreen    newRFQScreen;

        try
        {
            s            = new StreamReader(Request.InputStream).ReadToEnd();
            newRFQScreen = JsonConvert.DeserializeObject <NewRFQScreen>(s);
        }
        catch (Exception ex)
        {
            response.ErrorThrown         = true;
            response.ResponseDescription = "ERROR: When trying to parse JSON in server. " + ex.Message;
            return(JsonConvert.SerializeObject(response));
        }

        RFQNumberCRUD rfqNumberCRUD  = new RFQNumberCRUD();
        bomDetailCRUD bomDetail_CRUD = new bomDetailCRUD();
        UserCRUD      user_CRUD      = new UserCRUD();

        string baseBOMAttachmentsPath = ConfigurationManager.AppSettings["BOMLineAttachments"];
        string baseRFQAttachmentsPath = ConfigurationManager.AppSettings["RFQAttachmentsSent"];

        string strAuthUser = HttpContext.Current.User.Identity.Name;
        User   user        = user_CRUD.readById(strAuthUser);

        List <SIFDetail> EAUsList = newRFQScreen.SIFVolumesList;

        if (EAUsList.Count == 0)
        {
            response.ErrorThrown         = true;
            response.ResponseDescription = "ERROR: Cannot create RFQ without EAU specified.";
            return(JsonConvert.SerializeObject(response));
        }

        List <RFQEAV> newEAUList = new List <RFQEAV>();

        foreach (SIFDetail eau in EAUsList)
        {
            RFQEAV eauParsed = new RFQEAV();
            eauParsed.Volume = eau.ProjectedAnnualVolume;
            eauParsed.Year   = eau.ProgramYear;
            RFQEAV alreadyExists = newEAUList.Find(eauInternal => eauInternal.Volume == eauParsed.Volume);
            if (alreadyExists == null)
            {
                newEAUList.Add(eauParsed);
            }
            else
            {
                alreadyExists.Year = alreadyExists.Year.Trim() + ", " + eauParsed.Year.Trim();
            }
        }

        List <BOMDetail> bomDetailList = newRFQScreen.BomDetailList;


        ConnectionManager CM = new ConnectionManager();

        Data_Base_MNG.SQL DM = CM.getDataManager();

        if (newRFQScreen.SupplierList.Count > 0)
        {
            foreach (Supplier supplier in newRFQScreen.SupplierList)
            {
                foreach (BOMDetail component in bomDetailList)
                {
                    RFQNumberEntity rfqNumber = new RFQNumberEntity();

                    rfqNumber.BOMDetailKey = component.Id;
                    rfqNumber.SifHeaderKey = newRFQScreen.SIFHeaderID;
                    rfqNumber.RFQNumber    = rfqNumberCRUD.generateNewRFQNumber(rfqNumber.SifHeaderKey);

                    if (rfqNumber.RFQNumber == -1)
                    {
                        response.ErrorThrown         = true;
                        response.ResponseDescription = "ERROR: There was an error generating a new RFQ number.";
                        return(JsonConvert.SerializeObject(response));
                    }

                    CM = new ConnectionManager();
                    DM = CM.getDataManager();

                    /*Begin Transaction*/
                    DM.Open_Connection("Send New RFQ");

                    RFQ             rfq = new RFQ();
                    RFQNumberEntity rfqNumberGenereated = rfqNumberCRUD.create_return_object(rfqNumber, ref DM);
                    if (rfqNumberCRUD.ErrorOccur)
                    {
                        response.ErrorThrown         = true;
                        response.ResponseDescription = "ERROR:" + rfqNumberCRUD.ErrorMessage;
                        return(JsonConvert.SerializeObject(response));
                    }
                    else
                    {
                        //rfq.SentAttachmentsFolder = newRFQScreen.FolderAttachments;

                        newRFQScreen.FolderAttachments = newRFQScreen.FolderAttachments.Trim();
                        if (newRFQScreen.FolderAttachments != "")
                        {
                            if (System.IO.Directory.Exists((baseRFQAttachmentsPath + newRFQScreen.FolderAttachments)))
                            {
                                DirectoryInfo directory = new DirectoryInfo((baseRFQAttachmentsPath + newRFQScreen.FolderAttachments));
                                if (directory.GetFiles().Length > 0)
                                {
                                    string folderName = "";
                                    do
                                    {
                                        DateTime date = DateTime.Now;
                                        folderName = date.Year.ToString() + date.Month.ToString() +
                                                     date.Day.ToString() + "_" + MD5HashGenerator.GenerateKey(date);
                                    } while (Directory.Exists((baseRFQAttachmentsPath + folderName)));
                                    Directory.CreateDirectory((baseRFQAttachmentsPath + folderName));
                                    rfq.SentAttachmentsFolder = folderName;


                                    foreach (FileInfo file in directory.GetFiles())
                                    {
                                        try
                                        {
                                            File.Copy(file.FullName, (baseRFQAttachmentsPath + rfq.SentAttachmentsFolder + @"\" + file.Name), true);
                                        }
                                        catch (Exception ex)
                                        {
                                            response.ErrorThrown         = true;
                                            response.ResponseDescription = "ERROR:" + ex.Message;
                                            return(JsonConvert.SerializeObject(response));
                                        }
                                    }
                                }
                            }
                        }

                        foreach (Attachment bomAttachment in component.AttachmentsList)
                        {
                            if (rfq.SentAttachmentsFolder.Trim() == "")
                            {
                                string folderName = "";
                                do
                                {
                                    DateTime date = DateTime.Now;
                                    folderName = date.Year.ToString() + date.Month.ToString() +
                                                 date.Day.ToString() + "_" + MD5HashGenerator.GenerateKey(date);
                                } while (Directory.Exists((baseRFQAttachmentsPath + folderName)));
                                Directory.CreateDirectory((baseRFQAttachmentsPath + folderName));
                                rfq.SentAttachmentsFolder = folderName;
                            }
                            string currentPathAttachmentSource = baseBOMAttachmentsPath + bomAttachment.Directory + @"\" + bomAttachment.FileName;
                            string currentPathAttachmentTarget = baseRFQAttachmentsPath + rfq.SentAttachmentsFolder + @"\" + bomAttachment.FileName;
                            try
                            {
                                File.Copy(currentPathAttachmentSource, currentPathAttachmentTarget, true);
                            }
                            catch (Exception e)
                            {
                                response.ErrorThrown         = true;
                                response.ResponseDescription = "ERROR:" + e.Message;
                                return(JsonConvert.SerializeObject(response));
                            }
                        }


                        RfqCRUD rfqCRUD = new RfqCRUD();

                        rfq.SupplierId       = supplier.Id;
                        rfq.SupplierName     = supplier.SupplierName;
                        rfq.SentToVendor     = DateTime.Now;
                        rfq.LastEmail        = supplier.ContactEmail;
                        rfq.Status           = "PENDING";
                        rfq.BomDetailId      = component.Id;
                        rfq.Um               = component.Um;
                        rfq.RfqNumberKey     = rfqNumberGenereated.Id;
                        rfq.RfqGenerated     = rfqNumberGenereated.RfqGenerated;
                        rfq.DueDate          = newRFQScreen.DueDate;
                        rfq.MarketSectorID   = newRFQScreen.MarketSectorID;
                        rfq.DrawingLevel     = newRFQScreen.DrawingLevel;
                        rfq.TargetPrice      = newRFQScreen.TargetPrice;
                        rfq.CommentsToVendor = newRFQScreen.CommentsToVendor;


                        rfq.CreatedBy = strAuthUser;

                        string idGenerated = rfqCRUD.createAndReturnIdGenerated(rfq, component, ref DM);

                        if (!rfqCRUD.ErrorOccur)
                        {
                            rfq.Id = long.Parse(idGenerated);

                            foreach (RFQEAV eau in newEAUList)
                            {
                                RFQEAVCRUD rfqEAV_CRUD      = new RFQEAVCRUD();
                                RFQEAV     rfqEAV_toPersist = new RFQEAV();
                                rfqEAV_toPersist.RfqHeaderKey = long.Parse(idGenerated);
                                rfqEAV_toPersist.Volume       = eau.Volume * component.Qty;
                                rfqEAV_toPersist.Year         = eau.Year;
                                rfqEAV_toPersist.Status       = "CREATED";
                                rfqEAV_CRUD.createAndReturnIdGenerated(rfqEAV_toPersist, ref DM);
                                if (rfqEAV_CRUD.ErrorOccur)
                                {
                                    response.ErrorThrown         = true;
                                    response.ResponseDescription = "ERROR:" + rfqEAV_CRUD.ErrorMessage;
                                    return(JsonConvert.SerializeObject(response));
                                }
                            }

                            TokenCRUD token_CRUD = new TokenCRUD();
                            Token     token      = new Token();
                            token.Subject     = "RFQ";
                            token.SubjectKey  = long.Parse(idGenerated);
                            token.TokenNumber = MD5HashGenerator.GenerateKey(DateTime.Now);
                            if (token_CRUD.create(token, ref DM))
                            {
                                Email       NewMail = new Email();
                                MailMessage Message = new MailMessage();
                                try
                                {
                                    Message.From = new MailAddress("*****@*****.**", "*****@*****.**");
                                    Message.To.Add(new MailAddress(supplier.ContactEmail.ToString()));
                                    Message.Subject      = "Request For Quote";
                                    Message.IsBodyHtml   = true;
                                    Message.BodyEncoding = System.Text.Encoding.UTF8;

                                    var url             = ResolveUrl("~/Vendor/Email_RFQ_Request.htm");
                                    var strEmailContent = HTMLContent(url);
                                    strEmailContent = strEmailContent.Replace("{BuyerName}", user.Name);
                                    strEmailContent = strEmailContent.Replace("{BuyerPhone}", user.Phone1);
                                    strEmailContent = strEmailContent.Replace("{BuyerEmail}", user.Email);
                                    strEmailContent = strEmailContent.Replace("{RFQ Number}", rfqNumber.RfqGenerated);
                                    strEmailContent = strEmailContent.Replace("{Part Number}", component.PartNumber);
                                    strEmailContent = strEmailContent.Replace("{RFQLink}", "http://" + Request.Url.Authority + Request.ApplicationPath + "/Vendor/RFQHandler.ashx?token=" + token.TokenNumber);

                                    Message.Body = strEmailContent;


                                    NewMail.SendMail(Message);
                                }
                                catch (Exception ex)
                                {
                                    DM.RollBack();
                                    response.ErrorThrown         = true;
                                    response.ResponseDescription = "ERROR: Could not send email to: " + supplier.ContactEmail.ToString() + "; " + ex.Message;
                                    return(JsonConvert.SerializeObject(response));
                                }
                            }
                            else
                            {
                                response.ErrorThrown         = true;
                                response.ResponseDescription = "ERROR: " + token_CRUD.ErrorMessage;
                                return(JsonConvert.SerializeObject(response));
                            }
                        }
                        else
                        {
                            response.ErrorThrown         = true;
                            response.ResponseDescription = "ERROR: " + rfqCRUD.ErrorMessage;
                            return(JsonConvert.SerializeObject(response));
                        }
                    }

                    DM.CommitTransaction();
                    DM.Close_Open_Connection();

                    if (DM.ErrorOccur)
                    {
                        response.ErrorThrown         = true;
                        response.ResponseDescription = "ERROR: " + DM.Error_Mjs;
                        return(JsonConvert.SerializeObject(response));
                    }
                    resultRFQs.Add(rfq);
                }
            }
        }

        response.ErrorThrown         = false;
        response.ResponseDescription = "RFQs created successfully.";
        response.Result = resultRFQs;
        return(JsonConvert.SerializeObject(response));
    }
Esempio n. 3
0
    protected void btnSendSurvey_Click(object sender, EventArgs e)
    {
        if (supplier.ContactEmail.Trim() != txtEmail.Text.Trim())
        {
            SupplierCRUD supplierCRUD = new SupplierCRUD();
            supplier.ContactEmail = txtEmail.Text.Trim();
            if (!supplierCRUD.update(supplier))
            {
                Navigator.goToPage("~/Error.aspx", "ERROR:" + supplierCRUD.ErrorMessage);
                return;
            }
        }

        SupplierSurveyCRUD surveyCRUD = new SupplierSurveyCRUD();
        SupplierSurvey     survey     = new SupplierSurvey();

        survey.SupplierMasterKey = supplier.Id;
        survey.SentToVendor      = DateTime.Now;
        supplier.SupplierSurvey  = survey;



        ConnectionManager CM = new ConnectionManager();

        Data_Base_MNG.SQL DM = CM.getDataManager();

        /*Begin Transaction*/
        DM.Open_Connection("Survey Save");


        string idGenerated = surveyCRUD.createAndReturnIdGenerated(survey, ref DM);

        if (!surveyCRUD.ErrorOccur)
        {
            TokenCRUD token_CRUD = new TokenCRUD();
            Token     token      = new Token();
            token.Subject     = "SURVEY";
            token.SubjectKey  = long.Parse(idGenerated);
            token.TokenNumber = MD5HashGenerator.GenerateKey(DateTime.Now);
            if (token_CRUD.create(token, ref DM))
            {
                Email       NewMail = new Email();
                MailMessage Message = new MailMessage();

                Message.From = new MailAddress("*****@*****.**", "*****@*****.**");
                Message.To.Add(new MailAddress(supplier.ContactEmail.ToString()));
                Message.Subject      = "Survey";
                Message.IsBodyHtml   = true;
                Message.BodyEncoding = System.Text.Encoding.UTF8;
                //Message.Body = "Aqui va el link con el token= " + " <a href:\"http://localhost:29724/APQM/Vendor/RFQ.aspx?token=" + token.TokenNumber + "\">Link</a>";
                //Message.Body = "Aqui va el link con el token= " + " <a href:\"http://www.google.com\">Google</a>";

                string strEmailContent = "Dear Potential Supplier," + Environment.NewLine
                                         + "Please click the following link to fill out our supplier survey form.  Please fill out as completely as possible.  Once we have received your completed survey, a representative will contact you to discuss the next steps."
                                         + Environment.NewLine + Environment.NewLine
                                         + "http://" + Request.Url.Authority + Request.ApplicationPath + "/Vendor/Survey.aspx?token=" + token.TokenNumber
                                         + Environment.NewLine + Environment.NewLine
                                         + "Thank you for your time. We look forward to hearing from you."
                                         + Environment.NewLine + Environment.NewLine
                                         + "Sincerely," + Environment.NewLine + Environment.NewLine + "The Capsonic Advanced Purchasing Team";


                AlternateView htmlView = AlternateView.CreateAlternateViewFromString(strEmailContent);
                Message.AlternateViews.Add(htmlView);

                try
                {
                    NewMail.SendMail(Message);
                }
                catch
                {
                    DM.RollBack();
                    Navigator.goToPage("~/Error.aspx", "ERROR:Could not send email to: " + supplier.ContactEmail.ToString());
                    return;
                }
            }
            else
            {
                Navigator.goToPage("~/Error.aspx", "ERROR:" + token_CRUD.ErrorMessage);
                return;
            }
        }
        else
        {
            Navigator.goToPage("~/Error.aspx", "ERROR:" + surveyCRUD.ErrorMessage);
            return;
        }

        DM.CommitTransaction();
        DM.Close_Open_Connection();

        if (DM.ErrorOccur)
        {
            Navigator.goToPage("~/Error.aspx", "ERROR:" + DM.Error_Mjs);
            return;
        }

        supplier = null;
        Ok_Click(this, e);
    }