public void ProcessRequest(HttpContext context)
        {
            SqlConnection conn  = new SqlConnection(strcon);
            long          GRNID = 0;

            try
            {
                if (context.Request.QueryString["objname"] != null)
                {
                    objname = context.Request.QueryString["objname"].ToString();
                }
                if (context.Request.QueryString["oid"] != null)
                {
                    orderID = long.Parse(context.Request.QueryString["oid"]);
                }
                if (context.Request.QueryString["wrid"] != null)
                {
                    WarehouseID = long.Parse(context.Request.QueryString["wrid"]);
                }
                if (context.Request.QueryString["serialno"] != null)
                {
                    serialno = (context.Request.QueryString["serialno"]).ToString();
                }
                if (context.Request.QueryString["uid"] != null)
                {
                    UserID = Convert.ToInt64(context.Request.QueryString["uid"]);
                }
                if (context.Request.QueryString["page"] != null)
                {
                    page = (context.Request.QueryString["page"]).ToString();
                }

                DataSet dsUserDetail = new DataSet();
                dsUserDetail = GetUserDetails(UserID);
                CompanyID    = long.Parse(dsUserDetail.Tables[0].Rows[0]["CompanyID"].ToString());
                CustomerID   = long.Parse(dsUserDetail.Tables[0].Rows[0]["CustomerID"].ToString());

                long PrdID = 0;
                PrdID = GetPrdID(serialno, CompanyID, CustomerID);
                if (PrdID == 0)
                {
                    PrdID = GetPrdIDNew(serialno, CompanyID, CustomerID);
                }
                if (PrdID == 0)
                {
                    PrdID = GetPrdIDNewCode(serialno, CompanyID, CustomerID);
                }

                context.Response.ContentType = "text/plain";
                String jsonString = String.Empty;
                jsonString = "{\n";   /*json Loop Start*/
                jsonString = jsonString + "\"result\":[{\n";
                if (PrdID == 0)
                {
                    jsonString = jsonString + "\"status\": \"failed\",\n";
                    jsonString = jsonString + "\"reason\": \"SKU Not Available\"\n";
                }
                else
                {
                    DataTable dtorder = new DataTable();
                    dtorder = CheckSKUInOrder(PrdID, orderID, objname);
                    if (dtorder.Rows.Count > 0)
                    {
                        DataTable dtsrno = new DataTable();
                        dtsrno = CheckDuplicateSrNo(serialno, CompanyID, CustomerID, page, objname);
                        if (dtsrno.Rows.Count > 0)
                        {
                            jsonString = jsonString + "\"status\": \"failed\",\n";
                            jsonString = jsonString + "\"reason\": \"Serial number already used\"\n";
                        }
                        else
                        {
                            DataTable dtcurcnt = new DataTable();
                            dtcurcnt = GetCurrentCount(orderID, objname, PrdID);
                            decimal grnqty = 0;
                            decimal oqty   = 1;
                            if (dtcurcnt.Rows.Count > 0)
                            {
                                grnqty = Convert.ToDecimal(dtcurcnt.Rows[0]["GRNQty"]);
                                oqty   = Convert.ToDecimal(dtcurcnt.Rows[0]["OQty"]);
                            }
                            if (grnqty >= oqty)
                            {
                                jsonString = jsonString + "\"status\": \"failed\",\n";
                                jsonString = jsonString + "\"reason\": \"You have already reached max count\"\n";
                            }
                            else
                            {
                                iInboundClient Inbound  = new iInboundClient();
                                string         userName = GetUserID(UserID);
                                CustomProfile  profile  = CustomProfile.GetProfile(userName);
                                tGRNHead       GRNHead  = new tGRNHead();
                                GRNHead.ObjectName   = objname;
                                GRNHead.OID          = orderID;
                                GRNHead.GRNDate      = DateTime.Now;
                                GRNHead.ReceivedBy   = UserID;
                                GRNHead.BatchNo      = GEtBatchcode(orderID);
                                GRNHead.CreatedBy    = UserID;
                                GRNHead.Creationdate = DateTime.Now;
                                GRNHead.CustomerID   = CustomerID;
                                GRNHead.CompanyID    = CompanyID;
                                GRNHead.Status       = getStatus(objname);
                                GRNHead.OrderFrom    = "Mobile";
                                GRNID = GetGRNStatus(orderID, objname, UserID);
                                if (GRNID == 0)
                                {
                                    GRNID = Inbound.SavetGRNHead(GRNHead, profile.DBConnection._constr);
                                }
                                if (GRNID > 0)
                                {
                                    int save = SaveGRNDetail(orderID, objname, GRNID, PrdID, 1);
                                    SaveLottable(serialno, objname, GRNID, PrdID, 1, CompanyID, CustomerID, WarehouseID);
                                    string WorkFlow = "", NextObject = "";
                                    int    count = 0;
                                    long   QCID  = 0;
                                    if (objname == "PurchaseOrder")
                                    {
                                        WorkFlow   = "Inbound";
                                        NextObject = "QC";
                                    }
                                    if (objname == "Transfer")
                                    {
                                        WorkFlow   = "Transfer";
                                        NextObject = "QC";
                                    }
                                    if (objname == "SalesReturn")
                                    {
                                        WorkFlow   = "Return";
                                        NextObject = "QC";
                                    }
                                    count = GetWorkFlow(profile.Personal.CompanyID, profile.Personal.CustomerId, WorkFlow, NextObject, profile.DBConnection._constr);
                                    if (count == 0)
                                    {
                                        tQualityControlHead QCHead = new tQualityControlHead();
                                        QCHead.CreatedBy    = profile.Personal.UserID;
                                        QCHead.Creationdate = DateTime.Now;
                                        QCHead.ObjectName   = objname;
                                        QCHead.OID          = GRNID;
                                        QCHead.QCDate       = DateTime.Now;
                                        QCHead.QCBy         = profile.Personal.UserID;
                                        QCHead.Remark       = "";
                                        if (objname == "PurchaseOrder")
                                        {
                                            WorkFlow   = "Inbound";
                                            NextObject = "LabelPrinting";
                                        }
                                        if (objname == "Transfer")
                                        {
                                            WorkFlow   = "Transfer";
                                            NextObject = "LabelPrinting";
                                        }
                                        if (objname == "SalesReturn")
                                        {
                                            WorkFlow   = "Return";
                                            NextObject = "LabelPrinting";
                                        }
                                        int count1 = GetWorkFlow(profile.Personal.CompanyID, profile.Personal.CustomerId, WorkFlow, NextObject, profile.DBConnection._constr);

                                        if (objname == "PurchaseOrder")
                                        {
                                            if (count1 == 0)
                                            {
                                                QCHead.Status = 33;
                                            }
                                            else
                                            {
                                                QCHead.Status = 32;
                                            }
                                        }
                                        else if (objname == "Transfer")
                                        {
                                            if (count1 == 0)
                                            {
                                                QCHead.Status = 71;
                                            }
                                            else
                                            {
                                                QCHead.Status = 60;
                                            }
                                        }
                                        else if (objname == "SalesReturn")
                                        {
                                            if (count1 == 0)
                                            {
                                                QCHead.Status = 53;
                                            }
                                            else
                                            {
                                                QCHead.Status = 52;
                                            }
                                        }

                                        QCHead.Company    = profile.Personal.CompanyID;
                                        QCHead.CustomerID = profile.Personal.CustomerId;
                                        QCHead.OrderFrom  = "Mobile";
                                        QCID = GetQCStatus(GRNID, objname, UserID);
                                        if (QCID == 0)
                                        {
                                            QCID = Inbound.SavetQualityControlHead(QCHead, profile.DBConnection._constr);
                                        }
                                        if (QCID > 0)
                                        {
                                            SaveQCDetails(GRNID, QCID, PrdID, 1);
                                            SaveLottableQC(serialno, objname, QCID, PrdID, 1, CompanyID, CustomerID, WarehouseID);
                                        }
                                    }
                                    if (save > 0)
                                    {
                                        jsonString = jsonString + "\"status\": \"success\",\n";
                                        jsonString = jsonString + "\"reason\": \"\"\n";
                                    }
                                    else
                                    {
                                        jsonString = jsonString + "\"status\": \"failed\",\n";
                                        jsonString = jsonString + "\"reason\": \"Server error occured\"\n";
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        jsonString = jsonString + "\"status\": \"failed\",\n";
                        jsonString = jsonString + "\"reason\": \"SKU Not Available In Order\"\n";
                    }
                }

                jsonString = jsonString + "}]\n";
                jsonString = jsonString + "}\n"; /*json Loop End*/
                context.Response.Write(jsonString);
            }
            catch (Exception ex)
            { Login.Profile.ErrorHandling(ex, "scan_serial_and_save", "ProcessRequest"); }
            finally
            { }
        }
        public void ProcessRequest(HttpContext context)
        {
            SqlConnection conn  = new SqlConnection(strcon);
            long          GRNID = 0;

            context.Response.ContentType = "text/plain";
            String jsonString = String.Empty;

            jsonString = "{\n\"save_grn\": [\n";

            try
            {
                DateTime shippingdate         = DateTime.Now;
                DateTime expecteddeliverydate = DateTime.Now;
                if (context.Request.QueryString["userid"] != null)
                {
                    uid = long.Parse(context.Request.QueryString["userid"]);
                }
                else if (context.Request.Form["userid"] != null)
                {
                    uid = long.Parse(context.Request.Form["userid"]);
                }
                if (context.Request.QueryString["oid"] != null)
                {
                    oid = long.Parse(context.Request.QueryString["oid"]);
                }
                else if (context.Request.Form["oid"] != null)
                {
                    oid = long.Parse(context.Request.Form["oid"]);
                }
                if (context.Request.QueryString["objectname"] != null)
                {
                    objectname = context.Request.QueryString["objectname"];
                }
                else if (context.Request.Form["objectname"] != null)
                {
                    objectname = context.Request.Form["objectname"];
                }
                if (context.Request.QueryString["batchcode"] != null)
                {
                    batchcode = context.Request.QueryString["batchcode"];
                }
                else if (context.Request.Form["batchcode"] != null)
                {
                    batchcode = context.Request.Form["batchcode"];
                }
                if (context.Request.QueryString["remark"] != null)
                {
                    remark = context.Request.QueryString["remark"];
                }
                else if (context.Request.Form["remark"] != null)
                {
                    remark = context.Request.Form["remark"];
                }
                if (context.Request.QueryString["airwaybill"] != null)
                {
                    airwaybill = context.Request.QueryString["airwaybill"];
                }
                else if (context.Request.Form["airwaybill"] != null)
                {
                    airwaybill = context.Request.Form["airwaybill"];
                }
                if (context.Request.QueryString["shippingtype"] != null)
                {
                    shippingtype = context.Request.QueryString["shippingtype"];
                }
                else if (context.Request.Form["shippingtype"] != null)
                {
                    shippingtype = context.Request.Form["shippingtype"];
                }

                if (context.Request.QueryString["shippingdate"] != null)
                {
                    if (Convert.ToString(context.Request.QueryString["shippingdate"]) == "N/A")
                    {
                    }
                    else
                    {
                        shippingdate = Convert.ToDateTime(context.Request.QueryString["shippingdate"]);
                    }
                }
                else if (context.Request.Form["shippingdate"] != null)
                {
                    if (context.Request.Form["shippingdate"] == "N/A")
                    {
                    }
                    else
                    {
                        shippingdate = Convert.ToDateTime(context.Request.Form["shippingdate"]);
                    }
                }

                if (context.Request.QueryString["expecteddeliverydate"] != null)
                {
                    if (Convert.ToString(context.Request.QueryString["expecteddeliverydate"]) == "N/A")
                    {
                    }
                    else
                    {
                        expecteddeliverydate = Convert.ToDateTime(context.Request.QueryString["expecteddeliverydate"]);
                    }
                }
                else if (context.Request.Form["expecteddeliverydate"] != null)
                {
                    if (context.Request.Form["expecteddeliverydate"] == "N/A")
                    {
                    }
                    else
                    {
                        expecteddeliverydate = Convert.ToDateTime(context.Request.Form["expecteddeliverydate"]);
                    }
                }
                if (context.Request.QueryString["dockno"] != null)
                {
                    dockno = context.Request.QueryString["dockno"];
                }
                else if (context.Request.Form["dockno"] != null)
                {
                    dockno = context.Request.Form["dockno"];
                }
                if (context.Request.QueryString["lrno"] != null)
                {
                    lrno = context.Request.QueryString["lrno"];
                }
                else if (context.Request.Form["lrno"] != null)
                {
                    lrno = context.Request.Form["lrno"];
                }
                if (context.Request.QueryString["intime"] != null)
                {
                    intime = context.Request.QueryString["intime"];
                }
                else if (context.Request.Form["intime"] != null)
                {
                    intime = context.Request.Form["intime"];
                }
                if (context.Request.QueryString["outtime"] != null)
                {
                    outtime = context.Request.QueryString["outtime"];
                }
                else if (context.Request.Form["outtime"] != null)
                {
                    outtime = context.Request.Form["outtime"];
                }
                if (context.Request.QueryString["productdetail"] != null)
                {
                    productdetail = context.Request.QueryString["productdetail"];
                }
                else if (context.Request.Form["productdetail"] != null)
                {
                    productdetail = context.Request.Form["productdetail"];
                }

                if (context.Request.QueryString["other"] != null)
                {
                    udr = context.Request.QueryString["other"];
                }
                else if (context.Request.Form["other"] != null)
                {
                    udr = context.Request.Form["other"];
                }

                //context.Response.ContentType = "text/plain";
                //jsonString = String.Empty;
                long           CustomerID, CompanyID;
                string         DuplicateLottable = "";
                string         userName          = GetUserID(uid);
                CustomProfile  profile           = CustomProfile.GetProfile(userName);
                iInboundClient Inbound           = new iInboundClient();
                tGRNHead       GRNHead           = new tGRNHead();
                GRNHead.CreatedBy    = uid;
                GRNHead.Creationdate = DateTime.Now;
                GRNHead.ObjectName   = objectname;
                GRNHead.OID          = oid;
                GRNHead.ShipID       = "";
                GRNHead.GRNDate      = DateTime.Now;
                GRNHead.ReceivedBy   = uid;
                GRNHead.BatchNo      = batchcode;
                if (remark == "N/A")
                {
                    remark = "";
                }
                GRNHead.Remark = remark;
                if (airwaybill == "N/A")
                {
                    airwaybill = "";
                }
                GRNHead.AirwayBill = airwaybill;
                if (shippingtype == "N/A")
                {
                    shippingtype = "";
                }
                GRNHead.ShippingType = shippingtype;
                GRNHead.CompanyID    = profile.Personal.CompanyID;
                GRNHead.CustomerID   = profile.Personal.CustomerId;
                GRNHead.Status       = getStatus(objectname);
                Status = getStatus(objectname);
                GRNHead.ShippingDate      = shippingdate;
                GRNHead.TransporterRemark = "";
                //GRNHead.TransporterID = ;
                // GRNHead.DockNo = dockno;
                //GRNHead.TruckNo = "";
                if (lrno == "N/A")
                {
                    lrno = "";
                }
                GRNHead.LRNo = lrno;
                if (intime == "N/A")
                {
                    intime = "";
                }
                GRNHead.InTime = intime;
                if (outtime == "N/A")
                {
                    outtime = "";
                }
                GRNHead.OutTime         = outtime;
                GRNHead.ExpDeliveryDate = expecteddeliverydate;
                GRNHead.IsRead          = false;
                GRNHead.Other           = udr;

                //DataTable dtnew = new DataTable();
                //dtnew = GetDatatableDetails("select * from tgrnhead where oid=" + oid + "");
                //if (dtnew.Rows.Count > 0)
                //{
                //    GRNID = Convert.ToInt64(dtnew.Rows[0]["ID"].ToString());
                //}
                //else
                //{
                //    GRNID = Inbound.SavetGRNHead(GRNHead, profile.DBConnection._constr);
                //}
                GRNID = GetGRNStatus(oid, objectname);
                if (GRNID == 0)
                {
                    GRNID = Inbound.SavetGRNHead(GRNHead, profile.DBConnection._constr);
                }

                /* GRNDetail */
                string         mygrnPrdString1 = "select * from SplitString('" + productdetail + "','@')";
                SqlCommand     cmd1            = new SqlCommand();
                SqlDataAdapter da1             = new SqlDataAdapter();
                DataSet        ds1             = new DataSet();
                DataTable      dt1             = new DataTable();
                SqlDataReader  dr1;
                cmd1.CommandType = CommandType.Text;
                cmd1.CommandText = mygrnPrdString1;
                cmd1.Connection  = conn;
                cmd1.Parameters.Clear();
                da1.SelectCommand = cmd1;
                da1.Fill(ds1, "tbl2");
                dt1 = ds1.Tables[0];
                int cntr1 = dt1.Rows.Count;
                if (cntr1 > 0)
                {
                    for (int P = 0; P <= cntr1 - 1; P++)
                    {
                        string productdetail1 = ds1.Tables[0].Rows[P]["part"].ToString().Trim();
                        string prdString, qtystring; long prdID;

                        decimal qty = 0;
                        string  lot1str, lot2str, lot3str, lot1 = "", lot2 = "", lot3 = "";
                        dt.Clear();
                        string mygrnPrdString = "select * from SplitString('" + productdetail1 + "','|')";
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = mygrnPrdString;
                        cmd.Connection  = conn;
                        cmd.Parameters.Clear();
                        da.SelectCommand = cmd;
                        da.Fill(ds, "tbl1");
                        dt = ds.Tables[0];
                        int cntr = dt.Rows.Count;
                        if (cntr > 0)
                        {
                            for (int i = 0; i <= cntr - 1; i++)
                            {
                                prdString = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] spltprdString = prdString.Split(':');
                                prdID     = long.Parse(spltprdString[1]);
                                i         = i + 1;
                                qtystring = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] spltqty = qtystring.Split(':');
                                qty = decimal.Parse(spltqty[1]);
                                if (cntr > 2)
                                {
                                    i       = i + 1;
                                    lot1str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                    string[] lotsplit = lot1str.Split(':');
                                    lot1 = lotsplit[1];
                                    //DuplicateLottable = ChkDuplicateLottable(lot1, profile.Personal.CompanyID, profile.Personal.CustomerId);
                                    DuplicateLottable = "NO";
                                    //if (objectname == "SalesReturn")
                                    //{
                                    //    DuplicateLottable = "No";
                                    //}
                                    //if (DuplicateLottable == "Yes")
                                    //{
                                    //    break;
                                    //}
                                    //else { }
                                }
                                if (cntr > 3)
                                {
                                    i       = i + 1;
                                    lot2str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                    string[] lot2split = lot2str.Split(':');
                                    lot2 = lot2split[1];
                                }
                                if (cntr > 4)
                                {
                                    i       = i + 1;
                                    lot3str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                    string[] lot3split = lot3str.Split(':');
                                    lot3 = lot3split[1];
                                }
                                //i = i + 1;
                                DataSet dsOrder = new DataSet();
                                dsOrder = GetUOMofPrd(oid, objectname, prdID);

                                decimal poqty = 0;
                                long    UOMID = long.Parse(dsOrder.Tables[0].Rows[0]["UOMID"].ToString());

                                if (objectname == "PurchaseOrder")
                                {
                                    poqty = decimal.Parse(dsOrder.Tables[0].Rows[0]["OrderQty"].ToString());
                                }
                                else if (objectname == "Transfer")
                                {
                                    poqty = decimal.Parse(dsOrder.Tables[0].Rows[0]["Qty"].ToString());
                                }
                                else if (objectname == "SalesReturn")
                                {
                                    poqty = decimal.Parse(dsOrder.Tables[0].Rows[0]["OrderQty"].ToString());
                                }
                                decimal totalgrnqty = 0;

                                DataTable dtgrn = new DataTable();
                                dtgrn = GetDatatableDetails("select isnull(sum(grnqty),0) as grnqty from tgrndetail where grnid=" + GRNID + " and prodid=" + prdID + "");
                                if (dtgrn.Rows.Count > 0)
                                {
                                    totalgrnqty = Convert.ToDecimal(dtgrn.Rows[0]["grnqty"].ToString());
                                }
                                decimal ShortQty = 0, ExcessQty = 0; decimal qtyCalculation = 0;
                                // decimal qtyCalculation = poqty - qty;
                                if (totalgrnqty == 0)
                                {
                                    qtyCalculation = poqty - qty;
                                }
                                else
                                {
                                    qtyCalculation = poqty - totalgrnqty;
                                }
                                if (qtyCalculation == 0)
                                {
                                    ShortQty = 0; ExcessQty = 0;
                                }
                                else if (qtyCalculation > 0)
                                {
                                    ShortQty = qtyCalculation; ExcessQty = 0;
                                }
                                else if (qtyCalculation < 0)
                                {
                                    ShortQty = 0; ExcessQty = Math.Abs(qtyCalculation);
                                }

                                SqlCommand     cmdDetail = new SqlCommand();
                                SqlDataAdapter daDetail  = new SqlDataAdapter();
                                DataSet        dsDetail  = new DataSet();
                                DataTable      dtDetail  = new DataTable();
                                // SqlConnection conn = new SqlConnection(strcon);
                                cmdDetail.CommandType = CommandType.StoredProcedure;
                                cmdDetail.CommandText = "SP_MobileInsertGRNDetails";
                                cmdDetail.Connection  = conn;
                                cmdDetail.Parameters.Clear();
                                cmdDetail.Parameters.AddWithValue("GRNID", GRNID);
                                cmdDetail.Parameters.AddWithValue("prdID", prdID);
                                cmdDetail.Parameters.AddWithValue("qty", qty);
                                cmdDetail.Parameters.AddWithValue("poqty", poqty);
                                cmdDetail.Parameters.AddWithValue("ShortQty", ShortQty);
                                cmdDetail.Parameters.AddWithValue("ExcessQty", ExcessQty);
                                cmdDetail.Parameters.AddWithValue("UOMID", UOMID);
                                cmdDetail.Parameters.AddWithValue("lot1", lot1);
                                cmdDetail.Parameters.AddWithValue("lot2", lot2);
                                cmdDetail.Parameters.AddWithValue("lot3", lot3);
                                cmdDetail.Parameters.AddWithValue("obj", objectname);
                                cmdDetail.Parameters.AddWithValue("CompanyId", profile.Personal.CompanyID);
                                cmdDetail.Parameters.AddWithValue("CustomerId", profile.Personal.CustomerId);
                                cmdDetail.Connection.Open();
                                cmdDetail.ExecuteNonQuery();
                                cmdDetail.Connection.Close();
                            }
                        }
                        if (DuplicateLottable == "Yes")
                        {
                            break;
                        }

                        // jsonString = "{\n\"arr_qc_list\":[\n";
                    }
                    updateGRNStatus(GRNID);
                    if (DuplicateLottable == "Yes")
                    {
                        RecordUpdateStatus(GRNID, objectname, Status, oid);
                        jsonString = jsonString + "{\n";
                        jsonString = jsonString + "\"status\": \"failed\",\n";
                        jsonString = jsonString + "\"reason\": \"duplicateserial\"\n";
                        jsonString = jsonString + "}\n";
                        jsonString = jsonString + "]\n}";
                        context.Response.Write(jsonString);
                    }
                    else
                    {
                        RecordUpdateStatus(GRNID, objectname, Status, oid);
                        jsonString = jsonString + "{\n";
                        jsonString = jsonString + "\"status\": \"success\",\n";
                        jsonString = jsonString + "\"reason\": \"\"\n";
                        jsonString = jsonString + "}\n";
                        jsonString = jsonString + "]\n}";
                        context.Response.Write(jsonString);
                    }
                }
            }
            catch (System.Exception ex)
            {
                ErrorLog(ex.ToString(), "Save_GRN");
                Login.Profile.ErrorHandling(ex, "ws-save-grn", "ProcessRequest");
                // throw ex;
                jsonString = jsonString + "{\n";
                jsonString = jsonString + "\"status\": \"failed\",\n";
                jsonString = jsonString + "\"reason\": \"servererror\"\n";
                jsonString = jsonString + "}\n";
                jsonString = jsonString + "]\n}";
                context.Response.Write(jsonString);
            }
            finally
            { }
        }
        public void ProcessRequest(HttpContext context)
        {
            SqlConnection conn  = new SqlConnection(strcon);
            long          GRNID = 0;

            try
            {
                DateTime shippingdate         = DateTime.Now;
                DateTime expecteddeliverydate = DateTime.Now;
                if (context.Request.QueryString["userid"] != null)
                {
                    UserID = long.Parse(context.Request.QueryString["userid"]);
                }
                else if (context.Request.Form["userid"] != null)
                {
                    UserID = long.Parse(context.Request.Form["userid"]);
                }
                if (context.Request.QueryString["oid"] != null)
                {
                    orderID = long.Parse(context.Request.QueryString["oid"]);
                }
                else if (context.Request.Form["oid"] != null)
                {
                    orderID = long.Parse(context.Request.Form["oid"]);
                }
                if (context.Request.QueryString["objectname"] != null)
                {
                    objname = context.Request.QueryString["objectname"];
                }
                else if (context.Request.Form["objectname"] != null)
                {
                    objname = context.Request.Form["objectname"];
                }
                if (context.Request.QueryString["batchcode"] != null)
                {
                    batchcode = context.Request.QueryString["batchcode"];
                }
                else if (context.Request.Form["batchcode"] != null)
                {
                    batchcode = context.Request.Form["batchcode"];
                }
                if (context.Request.QueryString["remark"] != null)
                {
                    remark = context.Request.QueryString["remark"];
                }
                else if (context.Request.Form["remark"] != null)
                {
                    remark = context.Request.Form["remark"];
                }
                if (context.Request.QueryString["airwaybill"] != null)
                {
                    airwaybill = context.Request.QueryString["airwaybill"];
                }
                else if (context.Request.Form["airwaybill"] != null)
                {
                    airwaybill = context.Request.Form["airwaybill"];
                }
                if (context.Request.QueryString["shippingtype"] != null)
                {
                    shippingtype = context.Request.QueryString["shippingtype"];
                }
                else if (context.Request.Form["shippingtype"] != null)
                {
                    shippingtype = context.Request.Form["shippingtype"];
                }

                if (context.Request.QueryString["shippingdate"] != null)
                {
                    if (Convert.ToString(context.Request.QueryString["shippingdate"]) == "N/A")
                    {
                    }
                    else
                    {
                        shippingdate = Convert.ToDateTime(context.Request.QueryString["shippingdate"]);
                    }
                }
                else if (context.Request.Form["shippingdate"] != null)
                {
                    if (context.Request.Form["shippingdate"] == "N/A")
                    {
                    }
                    else
                    {
                        shippingdate = Convert.ToDateTime(context.Request.Form["shippingdate"]);
                    }
                }

                if (context.Request.QueryString["expecteddeliverydate"] != null)
                {
                    if (Convert.ToString(context.Request.QueryString["expecteddeliverydate"]) == "N/A")
                    {
                    }
                    else
                    {
                        expecteddeliverydate = Convert.ToDateTime(context.Request.QueryString["expecteddeliverydate"]);
                    }
                }
                else if (context.Request.Form["expecteddeliverydate"] != null)
                {
                    if (context.Request.Form["expecteddeliverydate"] == "N/A")
                    {
                    }
                    else
                    {
                        expecteddeliverydate = Convert.ToDateTime(context.Request.Form["expecteddeliverydate"]);
                    }
                }
                if (context.Request.QueryString["dockno"] != null)
                {
                    dockno = context.Request.QueryString["dockno"];
                }
                else if (context.Request.Form["dockno"] != null)
                {
                    dockno = context.Request.Form["dockno"];
                }
                if (context.Request.QueryString["lrno"] != null)
                {
                    lrno = context.Request.QueryString["lrno"];
                }
                else if (context.Request.Form["lrno"] != null)
                {
                    lrno = context.Request.Form["lrno"];
                }
                if (context.Request.QueryString["intime"] != null)
                {
                    intime = context.Request.QueryString["intime"];
                }
                else if (context.Request.Form["intime"] != null)
                {
                    intime = context.Request.Form["intime"];
                }
                if (context.Request.QueryString["outtime"] != null)
                {
                    outtime = context.Request.QueryString["outtime"];
                }
                else if (context.Request.Form["outtime"] != null)
                {
                    outtime = context.Request.Form["outtime"];
                }
                if (context.Request.QueryString["other"] != null)
                {
                    udr = context.Request.QueryString["other"];
                }
                else if (context.Request.Form["other"] != null)
                {
                    udr = context.Request.Form["other"];
                }

                context.Response.ContentType = "text/plain";
                String jsonString = String.Empty;
                jsonString = "{\n";   /*json Loop Start*/
                jsonString = jsonString + "\"result\":[{\n";

                iInboundClient Inbound      = new iInboundClient();
                string         userName     = GetUserID(UserID);
                CustomProfile  profile      = CustomProfile.GetProfile(userName);
                DataSet        dsUserDetail = new DataSet();
                dsUserDetail = GetUserDetails(UserID);
                CompanyID    = long.Parse(dsUserDetail.Tables[0].Rows[0]["CompanyID"].ToString());
                CustomerID   = long.Parse(dsUserDetail.Tables[0].Rows[0]["CustomerID"].ToString());
                tGRNHead GRNHead = new tGRNHead();
                GRNHead.ObjectName   = objname;
                GRNHead.OID          = orderID;
                GRNHead.GRNDate      = DateTime.Now;
                GRNHead.ReceivedBy   = UserID;
                GRNHead.CreatedBy    = UserID;
                GRNHead.Creationdate = DateTime.Now;
                GRNHead.CustomerID   = CustomerID;
                GRNHead.CompanyID    = CompanyID;
                string WorkFlow = "", NextObject = "";
                int    count = 0;
                if (objname == "PurchaseOrder")
                {
                    WorkFlow   = "Inbound";
                    NextObject = "QC";
                }
                if (objname == "Transfer")
                {
                    WorkFlow   = "Transfer";
                    NextObject = "QC";
                }
                if (objname == "SalesReturn")
                {
                    WorkFlow   = "Return";
                    NextObject = "QC";
                }
                count = GetWorkFlow(profile.Personal.CompanyID, profile.Personal.CustomerId, WorkFlow, NextObject, profile.DBConnection._constr);
                if (objname == "PurchaseOrder")
                {
                    if (count == 0)
                    {
                        GRNHead.Status = 33;
                    }
                    else
                    {
                        GRNHead.Status = 31;
                    }
                }
                if (objname == "Transfer")
                {
                    if (count == 0)
                    {
                        GRNHead.Status = 71;
                    }
                    else
                    {
                        GRNHead.Status = 60;
                    }
                }
                if (objname == "SalesReturn")
                {
                    if (count == 0)
                    {
                        GRNHead.Status = 53;
                    }
                    else
                    {
                        GRNHead.Status = 52;
                    }
                }
                GRNHead.OrderFrom = "Mobile";
                GRNHead.ShipID    = "";
                if (remark == "N/A")
                {
                    remark = "";
                }
                GRNHead.Remark = remark;
                if (airwaybill == "N/A")
                {
                    airwaybill = "";
                }
                GRNHead.AirwayBill = airwaybill;
                if (shippingtype == "N/A")
                {
                    shippingtype = "";
                }
                GRNHead.ShippingType      = shippingtype;
                GRNHead.ShippingDate      = shippingdate;
                GRNHead.TransporterRemark = "";
                if (lrno == "N/A")
                {
                    lrno = "";
                }
                GRNHead.LRNo = lrno;
                if (intime == "N/A")
                {
                    intime = "";
                }
                GRNHead.InTime = intime;
                if (outtime == "N/A")
                {
                    outtime = "";
                }
                GRNHead.OutTime         = outtime;
                GRNHead.ExpDeliveryDate = expecteddeliverydate;
                GRNHead.IsRead          = false;
                GRNHead.Other           = udr;
                GRNHead.IsGRN           = 1;
                DataTable dtgrn = new DataTable();
                dtgrn = GetGRNStatus(orderID, objname, UserID);
                if (dtgrn.Rows.Count > 0)
                {
                    batchcode = dtgrn.Rows[0]["BatchNo"].ToString();
                    GRNID     = Convert.ToInt64(dtgrn.Rows[0]["ID"]);
                }
                GRNHead.ID      = GRNID;
                GRNHead.BatchNo = batchcode;
                UpdateRemQty(orderID, objname);
                GRNID = Inbound.SavetGRNHead(GRNHead, profile.DBConnection._constr);
                if (GRNID > 0)
                {
                    jsonString = jsonString + "\"status\": \"success\",\n";
                    jsonString = jsonString + "\"reason\": \"\"\n";
                }
                else
                {
                    jsonString = jsonString + "\"status\": \"failed\",\n";
                    jsonString = jsonString + "\"reason\": \"Server error occured\"\n";
                }
                jsonString = jsonString + "}]\n";
                jsonString = jsonString + "}\n"; /*json Loop End*/
                context.Response.Write(jsonString);
            }
            catch (Exception ex)
            { Login.Profile.ErrorHandling(ex, "grn_save_grn", "ProcessRequest"); }
            finally
            { }
        }