Пример #1
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            string selecteddoctype     = ((DocuSignViewModel)LayoutRoot.DataContext)._documenttype;
            string selectedreferenceid = "";

            string selectedrecipientsname  = "";
            string selectedrecipientsemail = "";
            string selectedOrder           = "";
            string selectedsortorder       = "";
            string selectedRecipientType   = "";
            string actionstring            = "";
            string mergesurcharge          = "0";
            string includestd                = "0";
            string errormessage              = "";
            int    signinofficecount         = 0;
            int    customerdocumentsentcount = 0;
            string customerdocumentname      = "";

            bool signinoffice = false;

            BusyIndicator1.IsBusy = true;
            List <DocumentAttributes> listd = new List <DocumentAttributes>();
            string methodid = (cboMethod.SelectedItem as DocuSignMethod).MethodID.ToString();

            // get selected value from document grid

            foreach (var item2 in ((DocuSignViewModel)LayoutRoot.DataContext).DocuSignStatus)
            {
                selectedreferenceid = item2.estimateid;
                if (item2.Selected)
                {
                    DocumentAttributes da = new DocumentAttributes();
                    da.VersionType           = item2.versiontype;
                    da.VersionNumber         = item2.revisionnumber;
                    da.PrintType             = item2.printtype;
                    da.EnableSendViaDocuSign = item2.EnableSendViaDocuSign;
                    da.EnableSignInPerson    = item2.EnableSignInPerson;
                    da.EnableVoid            = item2.EnableVoid;
                    da.Status = item2.status;
                    if (item2.status == null || (item2.status != null && item2.status.ToLower().Contains("voided")))
                    {
                        da.EnvelopeID = Guid.Empty.ToString();
                    }
                    else
                    {
                        da.EnvelopeID = item2.envelopeId;
                    }
                    da.IntegrationID = item2.integrationid.ToString();

                    listd.Add(da);
                }
                else
                {
                    if (item2.versiontype.ToUpper().Contains("CUSTOMER") && (item2.status != null && item2.status.ToUpper() == "SENT"))
                    {
                        customerdocumentname      = item2.versiontype;
                        customerdocumentsentcount = customerdocumentsentcount + 1;
                    }
                }
            }

            // get selected value from recipient grid
            foreach (var item in ((DocuSignViewModel)LayoutRoot.DataContext).Contacts)
            {
                if (item.Selected && item.SortOrder > 0)
                {
                    if (selectedrecipientsname == "")
                    {
                        selectedrecipientsname  = item.RecipientName;
                        selectedrecipientsemail = item.RecipientEmail;
                        selectedOrder           = item.RoutingOrder.ToString();
                        actionstring            = item.SelectedAction.ToString();
                        selectedsortorder       = item.SortOrder.ToString();
                        selectedRecipientType   = item.RecipientType;
                    }
                    else
                    {
                        selectedrecipientsname  = selectedrecipientsname + "," + item.RecipientName;
                        selectedrecipientsemail = selectedrecipientsemail + "," + item.RecipientEmail;
                        selectedOrder           = selectedOrder + "," + item.RoutingOrder.ToString();
                        actionstring            = actionstring + "," + item.SelectedAction.ToString();
                        selectedsortorder       = selectedsortorder + "," + item.SortOrder.ToString();
                        selectedRecipientType   = selectedRecipientType + "," + item.RecipientType;
                    }

                    if (item.SelectedAction == 2)
                    {
                        signinofficecount = signinofficecount + 1;
                        signinoffice      = true;
                    }
                }
            }
            if ((bool)chkmerge.IsChecked)
            {
                mergesurcharge = "1";
            }
            else
            {
                mergesurcharge = "0";
            }


            if ((bool)chkinclusion.IsChecked)
            {
                includestd = "1";
            }
            else
            {
                includestd = "0";
            }

            #region simple validation and warning message of UI
            if (listd.Count < 1)
            {
                MessageBox.Show("Please select at least one of the document.");
                BusyIndicator1.IsBusy = false;
                return;
            }

            if (methodid == "0")
            {
                if (selectedrecipientsname == "")
                {
                    MessageBox.Show("Please select at least one of the customer recipient.");
                    BusyIndicator1.IsBusy = false;
                    return;
                }

                if (actionstring.Contains("0"))
                {
                    MessageBox.Show("Not all the recipients has the right action.");
                    BusyIndicator1.IsBusy = false;
                    return;
                }

                if (customerdocumentsentcount > 0 && listd[0].VersionType.ToUpper().Contains("CUSTOMER")) // only allow one of the 3 customer copy sent to customer at a time
                {
                    MessageBox.Show("A copy of " + customerdocumentname + " has been sent for signing. Please void the document first then send this copy.");
                    BusyIndicator1.IsBusy = false;
                    return;
                }

                if (signinoffice)
                {
                    if (!ValidateSignInOffice(out errormessage))
                    {
                        MessageBox.Show(errormessage);
                        BusyIndicator1.IsBusy = false;
                        return;
                    }
                }
                else
                {
                    if (!ValidateSginRemote(listd[0], methodid, out errormessage))
                    {
                        MessageBox.Show(errormessage);
                        BusyIndicator1.IsBusy = false;
                        return;
                    }
                }
            }
            else if (methodid == "1")// void
            {
                if (txtvoidreason.Text.Trim() == "")
                {
                    MessageBox.Show("Please enter void reason.");
                    BusyIndicator1.IsBusy = false;
                    return;
                }
                if (listd[0].Status.ToUpper().Contains("VOIDED") || listd[0].Status.ToUpper().Contains("COMPLETED"))
                {
                    MessageBox.Show("Can NOT void envelope in status Void or Completed.");
                    BusyIndicator1.IsBusy = false;
                    return;
                }
            }

            if (txtsubject.Text.Trim() == "")
            {
                MessageBox.Show("Email subject can NOT be blank.");
                BusyIndicator1.IsBusy = false;
                return;
            }
            if (txtbody.Text.Trim() == "")
            {
                MessageBox.Show("Email body can NOT be blank.");
                BusyIndicator1.IsBusy = false;
                return;
            }
            #endregion

            #region validate in database for further business rule
            if (methodid == "0")
            {
                RetailSystemClient mrsClient = new RetailSystemClient();
                mrsClient = new RetailSystemClient();
                mrsClient.Endpoint.Address = new System.ServiceModel.EndpointAddress(Internal.Utilities.GetMetriconRetailSystemWcfClientEndpointUrl());

                mrsClient.DocuSign_ValidateSignerAndDocuemntCompleted += delegate(object o, DocuSign_ValidateSignerAndDocuemntCompletedEventArgs es)
                {
                    if (es.Error == null)
                    {
                        if (es.Result.ToUpper() == "OK")
                        {
                            Processing(signinoffice, listd, selecteddoctype, includestd, mergesurcharge, selectedrecipientsname, selectedrecipientsemail, selectedOrder, actionstring, selectedsortorder);
                        }
                        else
                        {
                            RadWindow.Alert(es.Result);
                            BusyIndicator1.IsBusy = false;
                            return;
                        }
                    }
                };

                mrsClient.DocuSign_ValidateSignerAndDocuemntAsync(_estimateid, _revisionnumber, selectedrecipientsname, selectedRecipientType, actionstring);
            }
            else // void envelope
            {
                Processing(false, listd, selecteddoctype, includestd, mergesurcharge, selectedrecipientsname, selectedrecipientsemail, selectedOrder, actionstring, selectedsortorder);
            }
            #endregion
        }