コード例 #1
0
    public string SaveSmsVendorCredentials(SmsVendorCredentials credentials)
    {
        try
        {
            string certPathOrSecretKey = credentials.vendorType == SmsVendorCredentials.VENDOR_TYPE_PREPAID ?
                                         credentials.prepaidCertificatePath : credentials.postpaidSecretKey;

            _db.SaveVendorCredentialsV1(credentials.vendorCode, certPathOrSecretKey, credentials.prepaidCertificatePassword, credentials.vendorPassword, credentials.assignedBy);


            object[] data = { "Save_Vendor_Credentials", credentials.assignedBy, credentials.vendorCode, "Assigned Vendor Credentials to Vendor=" + credentials.vendorCode, "", GetLocalIPAddress() };
            _db.LogActivity("LogActivity", data);
            return("SAVED");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
コード例 #2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            //to hold the vendor credentials
            SmsVendorCredentials smsVendorCredentials = new SmsVendorCredentials();

            //general vendor credentials
            string vendorCode     = ddlVendors.SelectedValue;
            string vendorPassword = txtVendorPassword.Text;

            //for postpaid vendors
            string postpaidSecreteKey = txtKey.Text;

            //for prepaid vendors
            string prepaidCertificateFile     = FileUpload1.FileName;
            string prepaidCertificatePassword = txtCertPassword.Text;

            //user who is doing the assignment
            string assignedBy = Session["Username"].ToString();

            //get the vendor type based on vendor code
            data_table = data_file.GetArea(vendorCode);

            //we failed to get the type of vendor
            if (data_table == null || data_table.Rows.Count == 0)
            {
                ShowMessage("Failed to get vendor type for vendor: " + vendorCode, true);
                return;
            }

            //get the vendor type
            string vendorType = data_table.Rows[0]["VendorType"].ToString().ToUpper();

            if (vendorCode.Equals(""))
            {
                ShowMessage("Please Select a vendor ", true);
                ddlVendors.Focus();
            }
            else if (vendorPassword.Equals(""))
            {
                ShowMessage("Please Enter a password", true);
                txtVendorPassword.Focus();
            }
            else if (vendorType == SmsVendorCredentials.VENDOR_TYPE_POSTPAID && postpaidSecreteKey.Equals(""))
            {
                ShowMessage("Please Enter a secrete key", true);
                txtKey.Focus();
            }
            else if (vendorType == SmsVendorCredentials.VENDOR_TYPE_PREPAID && prepaidCertificateFile.Equals(""))
            {
                ShowMessage("Please Upload a certficate file", true);
                FileUpload1.Focus();
            }
            else if (vendorType == SmsVendorCredentials.VENDOR_TYPE_PREPAID && prepaidCertificatePassword.Equals(""))
            {
                ShowMessage("Please Enter the Certficate Password", true);
                txtCertPassword.Focus();
            }
            else
            {
                //assign the vendor credentials
                smsVendorCredentials.vendorCode     = vendorCode;
                smsVendorCredentials.vendorPassword = vendorPassword;
                smsVendorCredentials.vendorType     = vendorType;
                smsVendorCredentials.assignedBy     = assignedBy;


                if (vendorType == SmsVendorCredentials.VENDOR_TYPE_POSTPAID)
                {
                    //if the vendor is postpaid, we just need their secret key
                    smsVendorCredentials.vendorType        = SmsVendorCredentials.VENDOR_TYPE_POSTPAID;
                    smsVendorCredentials.postpaidSecretKey = postpaidSecreteKey;
                }
                else if (vendorType == SmsVendorCredentials.VENDOR_TYPE_PREPAID)
                {
                    string filename  = Path.GetFileName(FileUpload1.FileName);
                    string extension = Path.GetExtension(filename);

                    string   pathToFile = @"E:\SMSUploads\Certificates\";
                    DateTime todaydate  = DateTime.Now;
                    string   datetoday  = todaydate.ToString().Replace("/", "-").Replace(":", "-").Replace(" ", "-");
                    string   filepath   = pathToFile + filename + "_" + datetoday + extension;
                    if (!Directory.Exists(pathToFile))
                    {
                        Directory.CreateDirectory(pathToFile);
                    }

                    FileUpload1.SaveAs(filepath);

                    //if the vendor is prepaid, we need the certificate and the certificate password
                    //assign the certificate details
                    smsVendorCredentials.vendorType                 = SmsVendorCredentials.VENDOR_TYPE_PREPAID;
                    smsVendorCredentials.prepaidCertificatePath     = filepath;
                    smsVendorCredentials.prepaidCertificatePassword = prepaidCertificatePassword;
                }

                //save the SMS Vendor Credentials
                string res_mask = Process_file.SaveSmsVendorCredentials(smsVendorCredentials);

                //check if we managed to save the credentials
                if (res_mask == "SAVED")
                {
                    ShowMessage("VENDOR CREDENTIALS ASSIGNED SUCCESSFULLY", false);
                    txtName.Text = "";
                    LoadVendorCredentials();
                }
                else
                {
                    ShowMessage("VENDOR CREDENTIALS NOT ASSIGNED", true);
                }
            }
        }
        catch (Exception ex)
        {
            ShowMessage(ex.Message, true);
        }
    }