Monday, 28 November 2016

change printer from c# , print via coding in asp.net , print without dialog box in asp.net c#

using System.Drawing.Printing;
using System.Drawing;
using System.Windows.Forms;


  PrintDocument pdoc = null;


    protected void Page_Load(object sender, EventArgs e)
    {
     
        print();
    }

 public void print()
    {
        PrintDialog pd = new PrintDialog();
        pdoc = new PrintDocument();
        pdoc.PrinterSettings.PrinterName = "Samsung SCX-3200 Series";

        PrinterSettings ps = new PrinterSettings();
        Font font = new Font("Courier New", 15);


        PaperSize psize = new PaperSize("Custom", 100, 200);
        //ps.DefaultPageSettings.PaperSize = psize;



        pd.Document = pdoc;
        pd.Document.DefaultPageSettings.PaperSize = psize;
        //pdoc.DefaultPageSettings.PaperSize.Height =320;
        pdoc.DefaultPageSettings.PaperSize.Height = 400;

        pdoc.DefaultPageSettings.PaperSize.Width = 314;

        pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);

       // pdoc.Print();

        DialogResult result = pd.ShowDialog();
        if (result == DialogResult.OK)
        {
            PrintPreviewDialog pp = new PrintPreviewDialog();
            pp.Document = pdoc;
            result = pp.ShowDialog();
            if (result == DialogResult.OK)
            {
                pdoc.Print();
            }
        }

    }



void pdoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics graphics = e.Graphics;
            Font font = new Font("Courier New", 10);
            float fontHeight = font.GetHeight();
            int startX = 50;
            int startY = 55;
            int Offset = 40;
            graphics.DrawString("Welcome to MSST", new Font("Courier New", 14), new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 20;
            graphics.DrawString("Ticket No:" + your.TicketNo, new Font("Courier New", 14), new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 20;
            graphics.DrawString("Ticket Date :" + your.ticketDate, new Font("Courier New", 12), new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 20;
            String underLine = "------------------------------------------";
            graphics.DrawString(underLine, new Font("Courier New", 10), new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 20;
            String Source= this.source;
            graphics.DrawString("From "+yourSource+" To "+yourDestination, new Font("Courier New", 10), new SolidBrush(Color.Black), startX, startY + Offset);

            Offset = Offset + 20;
            String Grosstotal = "Total Amount to Pay = " + this.amount;

            Offset = Offset + 20;
            underLine = "------------------------------------------";
            graphics.DrawString(underLine, new Font("Courier New", 10), new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 20;

            graphics.DrawString(Grosstotal , new Font("Courier New", 10), new SolidBrush(Color.Black), startX, startY + Offset);
            Offset = Offset + 20;
            String DrawnBy = this.drawnBy;
            graphics.DrawString("Conductor - "+yourDrawnBy, new Font("Courier New", 10), new SolidBrush(Color.Black), startX, startY + Offset);





        }

Tuesday, 13 September 2016

Eazypay Payment Gateway Integration in ASP.NET

This is to send request to payment gateway server

   ASEKEY  & merchantid will be provided by BANK after submitting return URL to bank

string redirecturl = "";  // this is to check what url is coming before encryption
            string encryptredirecturl = "";

            string ASEKEY = "xxxxxxxxxxxxxxxxxxxx";

            string Reference_no, sub_merchant_id, pgamount, Mobile_No, city, name;

            Reference_no ="your value";
            sub_merchant_id ="your value";
            pgamount = 000;
            Mobile_No = "your value";;
            city ="your value";
            name = "your value";


            redirecturl += "https://eazypay.icicibank.com/EazyPG?";
            redirecturl += "merchantid=xxxxx";
            redirecturl += "&mandatory fields=" + Reference_no + "|" + sub_merchant_id + "|" + pgamount + "|" + Mobile_No + "|456";
            redirecturl += "&optional fields=" + city + "|" + name;
            redirecturl += "&returnurl=http://yourwebsite.com/eazypayreturn.aspx";
            redirecturl += "&Reference No=" + Reference_no;
            redirecturl += "&submerchantid=" + sub_merchant_id;
            redirecturl += "&transaction amount=" + pgamount;
            redirecturl += "&paymode=9";


            encryptredirecturl += "https://eazypay.icicibank.com/EazyPG?";
            encryptredirecturl += "merchantid=xxxxx";
            encryptredirecturl += "&mandatory fields=" + encryptFile(Reference_no + "|" + sub_merchant_id + "|" + pgamount + "|" + Mobile_No + "|456", ASEKEY);
            encryptredirecturl += "&optional fields=" + encryptFile(city + "|" + name, ASEKEY);
            encryptredirecturl += "&returnurl=" + encryptFile("http://yourwebsite.com/eazypayreturn.aspx", ASEKEY);
            encryptredirecturl += "&Reference No=" + encryptFile(Reference_no, ASEKEY);
            encryptredirecturl += "&submerchantid=" + encryptFile(sub_merchant_id, ASEKEY);
            encryptredirecturl += "&transaction amount=" + encryptFile(pgamount, ASEKEY);
            encryptredirecturl += "&paymode=" + encryptFile("9", ASEKEY);


            Response.Redirect(encryptredirecturl);

-----------------------------------------------------------------------------------------
 public static string encryptFile(string textToEncrypt, string key)
        {
            RijndaelManaged rijndaelCipher = new RijndaelManaged();
            rijndaelCipher.Mode = CipherMode.ECB;
            rijndaelCipher.Padding = PaddingMode.PKCS7;
            rijndaelCipher.KeySize = 0x80;
            rijndaelCipher.BlockSize = 0x80;
            byte[] pwdBytes = Encoding.UTF8.GetBytes(key);
            byte[] keyBytes = new byte[0x10];
            int len = pwdBytes.Length;
            if (len > keyBytes.Length)
            {
                len = keyBytes.Length;
            }
            Array.Copy(pwdBytes, keyBytes, len);
            rijndaelCipher.Key = keyBytes;
            rijndaelCipher.IV = keyBytes;
            ICryptoTransform transform = rijndaelCipher.CreateEncryptor();
            byte[] plainText = Encoding.UTF8.GetBytes(textToEncrypt);
            return Convert.ToBase64String(transform.TransformFinalBlock(plainText,
            0, plainText.Length));
        }

************************************************************

After coming back to return url , get response parameters and their vales 

 foreach (string key in HttpContext.Current.Request.Form.AllKeys)
            {
                string value = HttpContext.Current.Request.Form[key];

               

                if (value == "E000")
                {
                    //Success
 

                }
                else
                {
                    //Error

                  
                }
            }

Wednesday, 28 January 2015

authorize.net return url,x_relay_url,x_receipt_link_url issue solution, how to get back to main site after payment , how to return back to main site after payment

 how to get back to main site after payment , how to return back to main site after payment.


This code is in mvc4
----------------------------------------

This is View

@model JobPortal.db.tbl_Plans

@*@{
    Layout = null;
}
*@
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>SendPayment</title>
</head>
<body>
    <form id="simForm" name="simForm" method='post' action='https://secure.authorize.net/gateway/transact.dll'>
        @{

            string itm = "" + @Model.tbl_PackageCategory.PackageCategoryName + "<|>SeekZilla<|>Employer Plan<|>1<|>" + @Model.PlanCost.ToString("F") + "<|>";
    //string itm ="item1<|>golf balls<|><|>2<|>18.95<|>Y";
        }
        <input id="HiddenValue" type="hidden" value="Initial Value" />

        <input type='hidden' name='x_line_item' id='x_line_item' value='@itm' />

        <input type='hidden' name='x_login' id='x_login' value="@TempData["loginID"]" />
        <input type='hidden' name='x_amount' id='x_amount' value="@Model.PlanCost.ToString("F")" />
        <input type='hidden' name='x_description' id='x_description' value="Sample Transaction" />
        <input type='hidden' name='x_invoice_num' id='x_invoice_num' value="@DateTime.Now.ToString(" yyyymmddhhmmss")" />
        <input type='hidden' name='x_fp_sequence' id='x_fp_sequence' value="@TempData["sequence"]" />
        <input type='hidden' name='x_fp_timestamp' id='x_fp_timestamp' value="@TempData["timeStamp"]" />
        <input type='hidden' name='x_fp_hash' id='x_fp_hash' value="@TempData["fingerprint"]" />
        <input type='hidden' name='x_test_request' id='x_test_request' value="false" />

        <input type='hidden' name='x_show_form' value='PAYMENT_FORM' />

        <input type=HIDDEN name="x_receipt_link_method" value="LINK">
        <input type=HIDDEN name="x_receipt_link_text" value="Dont Close it, Dont go Back just Click here to  confirm Payment and return to Seekzilla">
       
        @*<input type=hidden name="x_relay_url" value="http://seekzilla.com/Employee/Plan/ReturnSuccess?empid=@WebSecurity.CurrentUserId&planid=@Model.PlanId&PlanCost=@Model.PlanCost">*@
        <input type=HIDDEN name="x_u" value="http://seekzilla.com/Employee/Plan/ReturnSuccess?empid=@WebSecurity.CurrentUserId&planid=@Model.PlanId&PlanCost=@Model.PlanCost">
        <input type=hidden name="x_relay_url" value="http://seekzilla.com/Home/DPMResponse">
        <input type=hidden name="x_receipt_link_url" value="http://seekzilla.com/Home/DPMResponse">
        <input type='hidden' name='x_cancel_url' value='http://seekzilla.com/Employee/Plan/ReturnCancel?empid=@WebSecurity.CurrentUserId&planid=@Model.PlanId' />

        @*<input type='submit' id='buttonLabel' value="Submit Payment" />*@
    </form>



        <h4>Redirecting to Authorize payment... </h4>
        <script language="javascript">
            document.simForm.submit();
        </script>
</body>
</html>


------------------------------------------------

so just set ur return url like that

  <input type=HIDDEN name="x_u" value="http://seekzilla.com/Employee/Plan/ReturnSuccess?empid=@WebSecurity.CurrentUserId&planid=@Model.PlanId&PlanCost=@Model.PlanCost">


and in controller or code user that function 
----------------------------------



        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult DPMResponse(FormCollection post)
        {
            var response = new SIMResponse(post);

            // First order of business - validate that it was Authorize.Net 
            // that posted this using the MD5 hash that was passed back to us
            var isValid = response.Validate("123456", "647h2FaTEJR6");

            // If it's not valid - just send them to the home page. 
            if (!isValid)
                return Redirect("/");
            // The URL to redirect to MUST be absolute
            var returnUrl = post["x_u"].ToString();// "http://seekzilla.com/Home/DPMReceipt?m=" + response.Message; 

            return Content(string.Format("<html><head><script type='text/javascript' charset='utf-8'>window.location='{0}';</script><noscript><meta http-equiv='refresh' content='1;url={0}'></noscript></head><body></body></html>", returnUrl));
        }



so final what is happening
-----------------------------

payment gateway return on  DPMResponse and then we get ur url from formcollection and just redirect on it.


one more thing

u set default return url from authorization control panel like

    <input type=hidden name="x_receipt_link_url" value="http://seekzilla.com/Home/DPMResponse">


Friday, 23 January 2015

Authorize.net integration Error , The merchant login ID or password is invalid or the account is inactive.Integrate Authorize.net Payment Geteway in asp.net c# mvc4

found these two lines in their Gateway class:
 problem? The problem is that even in “test” mode, you’re supposed to use the https://secure* URL. I’m like, “whatever” and changed the code to this:
   
Authorize.net payment integration code in asp.net with c sharp(#) mvc4
-------------------Controller Code-------------------------------------- public ActionResult SendPayment(int id=0) { if (id != null && id != 0) { var advpla = db.tbl_Advertisement.Where(o => o.AdverisementId == id).SingleOrDefault(); string loginID = ConfigurationManager.AppSettings["loginID"].ToString(); string transactionKey = ConfigurationManager.AppSettings["transactionKey"].ToString(); string amount = String.Format("{0:0.00}", advpla.TotalCost); Random random = new Random(); string sequence = (random.Next(0, 1000)).ToString(); string timeStamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(); string fingerprint = HMAC_MD5(transactionKey, loginID + "^" + sequence + "^" + timeStamp + "^" + amount + "^"); TempData["amt"] = amount; TempData["loginID"] = loginID; TempData["sequence"] = sequence; TempData["timeStamp"] = timeStamp; TempData["fingerprint"] = fingerprint; return View(advpla); } return View(); } string HMAC_MD5(string key, string value) { // The first two lines take the input values and convert them from strings to Byte arrays byte[] HMACkey = (new System.Text.ASCIIEncoding()).GetBytes(key); byte[] HMACdata = (new System.Text.ASCIIEncoding()).GetBytes(value); // create a HMACMD5 object with the key set HMACMD5 myhmacMD5 = new HMACMD5(HMACkey); //calculate the hash (returns a byte array) byte[] HMAChash = myhmacMD5.ComputeHash(HMACdata); //loop through the byte array and add append each piece to a string to obtain a hash string string fingerprint = ""; for (int i = 0; i < HMAChash.Length; i++) { fingerprint += HMAChash[i].ToString("x").PadLeft(2, '0'); } return fingerprint; } ------------------------------End------------------------------------------------ ---------------------------------------View Code--------------------------------- <body> <form id="simForm" name="simForm" method='post' action='https://secure.authorize.net/gateway/transact.dll'> @{ string itm = "" + @Model.PackageName + "<|>SeekZilla<|>Advertisement Plan<|>1<|>" + @Model.TotalCost.ToString("F") + "<|>"; } <input id="HiddenValue" type="hidden" value="Initial Value" /> <input type='hidden' name='x_line_item' id='x_line_item' value='@itm' /> <input type='hidden' name='x_login' id='x_login' value="@TempData["loginID"]" /> <input type='hidden' name='x_amount' id='x_amount' value="@Model.TotalCost.ToString("F")" /> <input type='hidden' name='x_description' id='x_description' value="Sample Transaction" /> <input type='hidden' name='x_invoice_num' id='x_invoice_num' value="@DateTime.Now.ToString(" yyyymmddhhmmss")" /> <input type='hidden' name='x_fp_sequence' id='x_fp_sequence' value="@TempData["sequence"]" /> <input type='hidden' name='x_fp_timestamp' id='x_fp_timestamp' value="@TempData["timeStamp"]" /> <input type='hidden' name='x_fp_hash' id='x_fp_hash' value="@TempData["fingerprint"]" /> <input type='hidden' name='x_test_request' id='x_test_request' value="false" /> <input type='hidden' name='x_show_form' value='PAYMENT_FORM' /> <input type=HIDDEN name="x_receipt_link_method" value="LINK"> <input type=HIDDEN name="x_receipt_link_text" value="Dont Close it, Dont go Back just Click here to confirm Payment and return to Seekzilla"> <input type=hidden name="x_receipt_link_url" value="http://seekzilla.com/Employee/Advertisement/ReturnSuccess?empid=@WebSecurity.CurrentUserId&AdverisementId=@Model.AdverisementId"> <input type='hidden' name='x_cancel_url' value='http://seekzilla.com/Employee/Advertisement/ReturnCancel?empid=@WebSecurity.CurrentUserId&AdverisementId=@Model.AdverisementId' /> </form> <h4>Redirecting to paypal... </h4> <script language="javascript"> document.simForm.submit(); </script> </body> ----------------------End View Code-------------------------------------------


Monday, 27 October 2014

sql server 2008 r2 is not installing in windows 8.1 or in windows 64 bit

http://www.smattie.com/2012/03/16/fixed-an-issue-installing-sql-server-2008r2/



see that link and follow all the steps



FIXED AN ISSUE *INSTALLING* SQL SERVER 2008R2

As you will remember, I had an issue trying to *remove* SQL Server 2008r2 as noted here. What I failed to tell you was what my REAL issue was… I could not successfully install SQL Server 2008r2 and I kept getting this error:
So I used my tip again to remove the new installation that I attempted last night, which works great, but it still prevented me from installing it. Then I decided to look at the registry and I was surprised… my switch that I corrected last time was set back to zero!! (As seen below)
I made the change back to 1 to prevent switch back and tried the install again. (HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\AppCompat\sbEnable = 1)
It failed again, but this time the registry stayed the same, so I had to remove it and then I went looking into the computer policy to see what might be causing the issue. First I opened it by typing gpedit.msc:
Then I went looking at Computer Configuration, Administrative Templates, Windows Components and Application Compatibility
SO I went through each one and re-read this article to understand the SwitchBack Compatibility engine better. Simply put, switchback is a mechanism that provides generic compatibility mitigations to older applications by providing older behavior to old applications and new behavior to new applications. It should also be noted that switchback is on by default. I turned it off, as seen below:
Behold it worked and just in time for SQL Saturday in Vancouver, BC in Canada. ;)

Tuesday, 12 August 2014

Making a SQL Server Database Read-Only and Write-Only



Making a SQL Server Database Read-Only
There are many situations where it is important that users are unable to modify the contents of a database. For example, if data is to be migrated to another server or for reporting purposes. This tip explains how to set a database to a read-only mode.
ALTER DATABASE Command
The ALTER DATABASE command allows a database administrator to modify SQL Server databases and their files and filegroups. This includes permitting the changing of database configuration options.
Setting a Database to Read-Only
When you need to ensure that the data is a database is not modified by any users or automated processes, it is useful to set the database into a read-only mode. Once read-only, the data can be read normally but any attempts to create, updated or delete table rows is disallowed. This makes the read-only mode ideal when preparing for data migration, performing data integrity checking or when the data is only required for historical reporting purposes.
To make a database read-only, the following command is used:
ALTER DATABASE database-name SET READ_ONLY
Setting a Database to Read-Write
If the read-only requirements for the database are temporary, you will need to reset the configuration option following any procedures undertaken. This is achieved with a small modification to the ALTER DATABASE statement to indicate that the database should return to a writeable mode.
ALTER DATABASE database-name SET READ_WRITE

run asp.net web application from pendrive using iis server , run website from pendrive, run website from pendrive using iis

run an asp.net website or web application from pen drive using iis server .

please follow these steps

1) configure iis in computer

2) copy web application and database in pendrive

3) connect application from iis as well as attach database mdf file in sql server

4) set connection string in web config using sql server name

5) only one issue will come , that will be like , when u will remove pen drive and reconnect it again then it will not work and will give error.

reason of error : actually what happend when u remove the pendrive and reconnect it then sql server  does not recognize the sql server database files from that path,

so we need to detach the database from sql server then reattach it for make it work.

but its very time consuming task to do it mannualy so what we will do is

we will put a code in our application start up that will do this by code.

means we will detach the database file from c# code.

 try
            {
                SqlConnection sqlConnection1 = new SqlConnection("Server=COMPUTER-001;Database=master;Integrated Security=true");
                SqlCommand cmd = new SqlCommand();


                cmd.CommandText = "ALTER DATABASE EasyInventory  SET SINGLE_USER WITH ROLLBACK IMMEDIATE   EXEC sp_detach_db 'EasyInventory'";
                cmd.CommandType = CommandType.Text;
                cmd.Connection = sqlConnection1;

                sqlConnection1.Open();

                cmd.ExecuteNonQuery();
                // Data is accessible through the DataReader object here.

                sqlConnection1.Close();


                string fullPath = "D:\\NewEasyInventory\\Database\\EasyInventory.mdf";
                DirectoryInfo dInfo = new DirectoryInfo(fullPath);
                DirectorySecurity dSecurity = dInfo.GetAccessControl();
                dSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
                dInfo.SetAccessControl(dSecurity);

                string fullPath2 = "D:\\NewEasyInventory\\Database\\EasyInventory_log.ldf"; ;
                DirectoryInfo dInfo2 = new DirectoryInfo(fullPath2);
                DirectorySecurity dSecurity2 = dInfo2.GetAccessControl();
                dSecurity2.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
                dInfo2.SetAccessControl(dSecurity2);
            }

            catch (Exception ex)
            {
            }


here we have two codes,

one is to detach the sql server database file

second is to give everyone permission on database mdf and ldf files in pendrive.

so u need to set the correct path of mdf and ldf files on ur pen drive

for further help reply.

thanks