Esempio n. 1
0
        } // dg_StockBorrow_CellMouseClick()

        public static void dg_StockBorrowSystemMenuItem_Click(object sender, MouseEventArgs e)
        {
            //
            // Purpose: A generic menu click event for the Order Right-Click
            //

            // Local Variables
            String            htmlBody;
            String            BorrowContactNumber = "";
            ToolStripMenuItem ts_From             = (ToolStripMenuItem)sender;
            BorrowMenuStruct  myBorrowStruct      = (BorrowMenuStruct)ts_From.Tag;
            Boolean           RetVal = true;

            // Mail message
            MailMessage mail                 = null;
            String      ToEmail              = SystemLibrary.SQLSelectString("Select a.returnBorrowEmail From Custodian a, CustodianMap b Where b.ExtID_Loan = '" + myBorrowStruct.StockLoanAccount + "' and a.CustodianID = b.CustodianID");
            String      Custodian_FromEmail  = SystemLibrary.SQLSelectString("Select dbo.f_GetParamString('Custodian:FromEmail')");
            String      Custodian_CCEmail    = SystemLibrary.SQLSelectString("Select dbo.f_GetParamString('Custodian:CCEmail')");
            String      Custodian_BCCEmail   = SystemLibrary.SQLSelectString("Select dbo.f_GetParamString('Custodian:BCCEmail')");
            String      Custodian_Signature  = SystemLibrary.SQLSelectString("Select dbo.f_GetParamString('Custodian:Signature')");
            String      Custodian_SmtpClient = SystemLibrary.SQLSelectString("Select dbo.f_GetParamString('SmtpClient')");

            if (!myBorrowStruct.isReturn)
            {
                ToEmail = SystemLibrary.SQLSelectString("Select a.BorrowEmail From Custodian a, CustodianMap b Where b.ExtID_Loan = '" + myBorrowStruct.StockLoanAccount + "' and a.CustodianID = b.CustodianID");
                myBorrowStruct.ReturnMessage = SystemLibrary.SQLSelectString("Select a.BorrowContact+',' From Custodian a, CustodianMap b Where b.ExtID_Loan = '" + myBorrowStruct.StockLoanAccount + "' and a.CustodianID = b.CustodianID") + "\r\n\r\n" +
                                               "Hi. " + myBorrowStruct.ReturnMessage;
                BorrowContactNumber = SystemLibrary.SQLSelectString("Select 'Please Phone ' + a.BorrowContact + ' on ' + a.BorrowPhone + ' to Organise / Confirm Borrow.\r\n\r\n\r\n' From Custodian a, CustodianMap b Where b.ExtID_Loan = '" + myBorrowStruct.StockLoanAccount + "' and a.CustodianID = b.CustodianID");

                // Indicate in the table that this email has happened.
                SystemLibrary.SQLExecute(myBorrowStruct.myUpdate);
            }

            // hourglass cursor
            Cursor.Current = Cursors.WaitCursor;

            // TODO (5) When upgrade to .NET 4.0, then can use this
            // using (SmtpClient SmtpServer = new SmtpClient(Custodian_SmtpClient))
            SmtpClient SmtpServer = new SmtpClient(Custodian_SmtpClient);

            {
                SmtpServer.Port = 25;
                //SmtpServer.Credentials = new System.Net.NetworkCredential("username", "pwd");
                SmtpServer.EnableSsl = false;

                // Create a new mail header record
                mail      = new MailMessage();
                mail.From = new MailAddress(Custodian_FromEmail);
                if (ToEmail.Length == 0)
                {
                    mail.To.Add(Custodian_FromEmail);
                }
                else
                {
                    //String
                    foreach (String myStr in ToEmail.Split(",;".ToCharArray()))
                    {
                        mail.To.Add(myStr);
                    }
                }
                if (Custodian_CCEmail != "")
                {
                    //String
                    foreach (String myStr in Custodian_CCEmail.Split(",;".ToCharArray()))
                    {
                        mail.CC.Add(myStr);
                    }
                }
                if (Custodian_BCCEmail != "")
                {
                    //String
                    foreach (String myStr in Custodian_BCCEmail.Split(",;".ToCharArray()))
                    {
                        mail.Bcc.Add(myStr);
                    }
                }
                if (myBorrowStruct.isReturn)
                {
                    mail.Subject = "Return of Stock Borrow on " + DateTime.Now.ToString("dd-MMM-yyyy") + " " + DateTime.Now.ToShortTimeString();
                }
                else
                {
                    mail.Subject = "Request Borrow on " + DateTime.Now.ToString("dd-MMM-yyyy") + " " + DateTime.Now.ToShortTimeString();
                }
                mail.IsBodyHtml = true;

                htmlBody = SystemLibrary.HTMLStart() +
                           SystemLibrary.HTMLLine(myBorrowStruct.ReturnMessage + "\r\n") +
                           SystemLibrary.HTMLLine(Custodian_Signature) +
                           SystemLibrary.HTMLEnd();
                mail.Body = htmlBody;

                //mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure | DeliveryNotificationOptions.OnSuccess;
                try
                {
                    SmtpServer.Send(mail);
                }
                catch (Exception em)
                {
                    Exception CheckMessage = em;
                    String    myMessage    = CheckMessage.Message;

                    while (CheckMessage.InnerException != null)
                    {
                        CheckMessage = CheckMessage.InnerException;
                        myMessage    = myMessage + "\r\n" + CheckMessage.Message;
                    }
                    RetVal = false;
                    MessageBox.Show(myMessage, "Failed to Send email");
                }

                // Clean up
                mail.Dispose();
                mail = null;
            }

            // Cleanup
            Cursor.Current = Cursors.Default;
            if (RetVal)
            {
                MessageBox.Show("The following message was Sent to '" + ToEmail + "' and will appear in your inbox shortly\r\n\r\n" +
                                BorrowContactNumber +
                                myBorrowStruct.ReturnMessage, "Return Stock Borrow");
            }
            myBorrowStruct.myParentForm.bt_Refresh_Click(null, null);
        } //dg_StockBorrowSystemMenuItem_Click()
Esempio n. 2
0
        } //dg_StockBorrow_MouseClick()

        private void dg_StockBorrow_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            // Show the Bloomberg popup menu
            try
            {
                if (e.Button == MouseButtons.Right && e.RowIndex > -1 && e.ColumnIndex > -1)
                {
                    String Ticker = SystemLibrary.ToString(dg_StockBorrow.Rows[e.RowIndex].Cells["Ticker"].Value);
                    if (Ticker.Length > 0)
                    {
                        switch (dg_StockBorrow.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name.ToString())
                        {
                        case "Ticker":
                            SystemLibrary.BBGShowMenu(-1, -1, Ticker, "", SystemLibrary.BBGRelativeTicker(Ticker), this.Location.X + CXLocation, this.Location.Y + CYLocation);
                            break;

                        default:
                            Point myLocation = new Point(this.Location.X + CXLocation, this.Location.Y + CYLocation);
                            // Select the Order as needed in code later on.
                            int    FundID           = SystemLibrary.ToInt32(dg_StockBorrow.Rows[e.RowIndex].Cells["FundID"].Value);
                            String StockLoanAccount = SystemLibrary.ToString(dg_StockBorrow.Rows[e.RowIndex].Cells["Stock Loan Account"].Value);
                            int    CanBeReturned    = -SystemLibrary.ToInt32(dg_StockBorrow.Rows[e.RowIndex].Cells["Can Be Returned Today"].Value);
                            int    PosUncovered     = StockLoanAccount.IndexOf(" - UNCOVERED");

                            ContextMenuStrip  myMenu    = new ContextMenuStrip();
                            ToolStripMenuItem mySubMenu = new ToolStripMenuItem();

                            BorrowMenuStruct myBorrowStruct = new BorrowMenuStruct();
                            myBorrowStruct.myParentForm     = this;
                            myBorrowStruct.isReturn         = true;
                            myBorrowStruct.StockLoanAccount = StockLoanAccount;

                            if (dg_StockBorrow.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name.ToString() == "Stock Loan Account" && PosUncovered > 0)
                            {
                                // Get Borrow for this line
                                StockLoanAccount = StockLoanAccount.Substring(0, PosUncovered);
                                myBorrowStruct.StockLoanAccount = StockLoanAccount;
                                CanBeReturned = SystemLibrary.ToInt32(dg_StockBorrow.Rows[e.RowIndex].Cells["Excess Stock on Trade Date"].Value);

                                mySubMenu = new ToolStripMenuItem("Borrow " + CanBeReturned.ToString("#,##0") + " shortfall '" + Ticker + "' for account '" + StockLoanAccount + "'");
                                myBorrowStruct.ReturnAllExcess = false;
                                myBorrowStruct.isReturn        = false;
                                myBorrowStruct.ReturnMessage   = "Please Borrow " + CanBeReturned.ToString("#,##0") + " of '" +
                                                                 Ticker + "' for stock loan account '" + StockLoanAccount + "'.";
                                myBorrowStruct.myUpdate = "Update	ML_E50 "+
                                                          "Set	SL_Account_ID = '"+ StockLoanAccount + "' " +
                                                          "WHERE	ML_E50.BusDate = (	SELECT	Max(BusDate) "+
                                                          "         	                FROM	ML_E50 "+
                                                          "			                 ) "+
                                                          "And isNull(SL_Account_ID,'') = '' " +
                                                          "And FundID = " + FundID.ToString() + " " +
                                                          "And	BBG_Ticker = '"+ Ticker + "' ";
                            }
                            else
                            {
                                // Return This Lines
                                mySubMenu = new ToolStripMenuItem("Return '" + Ticker + "' for account '" + StockLoanAccount + "'");
                                myBorrowStruct.ReturnAllExcess = false;
                                myBorrowStruct.ReturnMessage   = "Please return " + CanBeReturned.ToString("#,##0") + " of '" +
                                                                 Ticker + "' for stock loan account '" + StockLoanAccount + "' for t+1 settlement.";
                                mySubMenu.Tag      = myBorrowStruct;
                                mySubMenu.MouseUp += new MouseEventHandler(dg_StockBorrowSystemMenuItem_Click);
                                myMenu.Items.Add(mySubMenu);

                                // Return All Lines
                                mySubMenu = new ToolStripMenuItem("Return All Borrow for account '" + StockLoanAccount + "'");
                                myBorrowStruct.ReturnAllExcess = true;
                                myBorrowStruct.ReturnMessage   = "";
                                for (int i = 0; i < dg_StockBorrow.Rows.Count; i++)
                                {
                                    String Row_Ticker           = SystemLibrary.ToString(dg_StockBorrow.Rows[i].Cells["Ticker"].Value);
                                    int    Row_FundID           = SystemLibrary.ToInt32(dg_StockBorrow.Rows[i].Cells["FundID"].Value);
                                    String Row_StockLoanAccount = SystemLibrary.ToString(dg_StockBorrow.Rows[i].Cells["Stock Loan Account"].Value);
                                    int    Row_CanBeReturned    = -SystemLibrary.ToInt32(dg_StockBorrow.Rows[i].Cells["Can Be Returned Today"].Value);

                                    if (Row_FundID == FundID && Row_StockLoanAccount == StockLoanAccount && Row_CanBeReturned > 0)
                                    {
                                        myBorrowStruct.ReturnMessage = myBorrowStruct.ReturnMessage +
                                                                       "Please return " + Row_CanBeReturned.ToString("#,##0") + " of '" +
                                                                       Row_Ticker + "' for stock loan account '" + Row_StockLoanAccount + "' for t+1 settlement.\r\n";
                                    }
                                }
                            }

                            mySubMenu.Tag      = myBorrowStruct;
                            mySubMenu.MouseUp += new MouseEventHandler(dg_StockBorrowSystemMenuItem_Click);
                            myMenu.Items.Add(mySubMenu);

                            // Show the Menu
                            myMenu.Show(myLocation);
                            break;
                        }
                    }
                }
            }
            catch { }
        } // dg_StockBorrow_CellMouseClick()