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
            { }
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            SqlConnection conn = new SqlConnection(strcon);

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

            jsonString = "{\n\"save_qc\": [\n";
            try
            {
                long           uid           = long.Parse(context.Request.QueryString["userid"]);
                long           oid           = long.Parse(context.Request.QueryString["oid"]);
                string         objectname    = context.Request.QueryString["objectname"];
                string         productdetail = context.Request.QueryString["productdetail"];
                string         remark        = context.Request.QueryString["remark"];
                string         userName      = GetUserID(uid);
                CustomProfile  profile       = CustomProfile.GetProfile(userName);
                iInboundClient Inbound       = new iInboundClient();
                int            count1        = Workflow(profile.Personal.CompanyID, profile.Personal.CustomerId, objectname);
                long           status        = 0;
                if (count1 > 0)
                {
                    status = getStatus(objectname);
                }
                else
                {
                    status = 33;
                }
                long   CustomerID, CompanyID, reasonid;
                string lottable1;
                string lot1 = "", lot2 = "", lot3 = "";
                long   QCID = 0;
                /* QualityControlHead */
                tQualityControlHead QCHead = new tQualityControlHead();
                QCHead.ObjectName   = objectname;
                QCHead.OID          = oid;
                QCHead.QCDate       = DateTime.Now;
                QCHead.QCBy         = uid;
                QCHead.Remark       = remark;
                QCHead.CreatedBy    = uid;
                QCHead.Creationdate = DateTime.Now;
                QCHead.Status       = status;
                QCHead.Company      = profile.Personal.CompanyID;
                QCHead.CustomerID   = profile.Personal.CustomerId;
                DataTable dtnew = new DataTable();
                dtnew = GetDatatableDetails(" select * from tQualityControlHead where oid=" + oid + "");
                if (dtnew.Rows.Count > 0)
                {
                    QCID = Convert.ToInt64(dtnew.Rows[0]["ID"].ToString());
                }
                else
                {
                    QCID = Inbound.SavetQualityControlHead(QCHead, profile.DBConnection._constr);
                }

                /* QualityControlDetail */

                SqlCommand     cmd1 = new SqlCommand();
                SqlDataAdapter da1  = new SqlDataAdapter();
                DataSet        ds1  = new DataSet();
                cmd1.CommandType = CommandType.Text;
                cmd1.CommandText = "select * from  SplitString('" + productdetail + "','@')";
                cmd1.Connection  = conn;
                cmd1.Parameters.Clear();
                da1.SelectCommand = cmd1;
                da1.Fill(ds1, "tbl1");
                int cntr1 = 0;
                cntr1 = ds1.Tables[0].Rows.Count;
                if (ds1.Tables[0].Rows.Count > 0)
                {
                    for (int p = 0; p <= cntr1 - 1; p++)
                    {
                        string  prdString, qtystring; long prdID, oqty, uomid;
                        decimal qty = 0, grnqty = 0, qcqty = 0, rejectqty = 0;
                        string  lot1str, lot2str, lot3str, serialno, lot4str, lot5str, lot6str;
                        string  mygrnPrdString = "select * from SplitString('" + ds1.Tables[0].Rows[p]["part"].ToString() + "','|')";
                        ds.Clear();
                        dt.Clear();
                        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++)
                            {
                                //     ID QCID    ProdID OQty    GRNQty QCQty   RejectedQty ExcessQty   Status Reason  Company CustomerID  UOMID PackingStyle    ReasonID

                                //ProdID
                                prdString = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] spltprdString = prdString.Split(':');
                                prdID = long.Parse(spltprdString[1]);
                                i     = i + 1;

                                //qty=OQty
                                qtystring = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] spltqty = qtystring.Split(':');
                                qty = decimal.Parse(spltqty[1]);
                                i   = i + 1;

                                //GRNqty
                                DataSet dsqty = new DataSet();
                                // dsqty = GetAllDetails(oid, prdID, objectname);
                                grnqty = GetQtyAllDetails(oid, prdID, objectname);
                                // grnqty = decimal.Parse(dsqty.Tables[0].Rows[0]["GRNQty"].ToString());


                                //QCQTY=acceptedqty
                                lot1str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] lotsplit = lot1str.Split(':');
                                qcqty = decimal.Parse(lotsplit[1]);
                                i     = i + 1;

                                //RejectedQty=rejectedqty
                                lot2str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] lot2split = lot2str.Split(':');
                                rejectqty = decimal.Parse(lot2split[1]);
                                i         = i + 1;

                                //reasoncode=ReasonID
                                lot3str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                string[] lot3split = lot3str.Split(':');
                                reasonid = long.Parse(lot3split[1]);

                                //serial number if avaliable
                                if (cntr > 5)
                                {
                                    i       = i + 1;
                                    lot4str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                    string[] lotsplit4 = lot4str.Split(':');
                                    lot1 = lotsplit4[1];
                                }
                                if (cntr > 6)
                                {
                                    i       = i + 1;
                                    lot5str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                    string[] lotsplit4 = lot5str.Split(':');
                                    lot2 = lotsplit4[1];
                                }
                                if (cntr > 7)
                                {
                                    i       = i + 1;
                                    lot6str = ds.Tables[0].Rows[i]["part"].ToString().Trim();
                                    string[] lotsplit4 = lot6str.Split(':');
                                    lot3 = lotsplit4[1];
                                }


                                DataSet dsOrder = new DataSet();
                                dsOrder = GetUOMofPrd(oid, objectname, prdID);
                                decimal poqty = 0;
                                long    UOMID = long.Parse(dsOrder.Tables[0].Rows[0]["UOMID"].ToString());
                                //long UOMID = 16;
                                SqlCommand     cmdDetail = new SqlCommand();
                                SqlDataAdapter daDetail  = new SqlDataAdapter();
                                DataSet        dsDetail  = new DataSet();
                                DataTable      dtDetail  = new DataTable();;
                                cmdDetail.CommandType = CommandType.StoredProcedure;
                                cmdDetail.CommandText = "SP_MobileInsertQCDetails";
                                cmdDetail.Connection  = conn;
                                cmdDetail.Parameters.Clear();
                                cmdDetail.Parameters.AddWithValue("QCID", QCID);
                                cmdDetail.Parameters.AddWithValue("ProdID", prdID);
                                cmdDetail.Parameters.AddWithValue("OQty", qty);
                                cmdDetail.Parameters.AddWithValue("GRNQty", grnqty);
                                cmdDetail.Parameters.AddWithValue("QCQty", qcqty);
                                cmdDetail.Parameters.AddWithValue("RejectedQty", rejectqty);
                                cmdDetail.Parameters.AddWithValue("UOMID", UOMID);
                                cmdDetail.Parameters.AddWithValue("ReasonID", reasonid);
                                cmdDetail.Connection.Open();
                                cmdDetail.ExecuteNonQuery();
                                cmdDetail.Connection.Close();
                                SaveQCLottable(lot1, profile.Personal.CompanyID, profile.Personal.CustomerId, prdID, QCID, lot2, lot3);
                            }
                        }
                    }
                    //Upadte status from tgrnhead and tpurchasehead
                    int count = 0;
                    count = Workflow(profile.Personal.CompanyID, profile.Personal.CustomerId, objectname);
                    if (count > 0)
                    {
                        RecordUpdateStatus(oid, 32, objectname);
                    }
                    else
                    {
                        RecordUpdateStatus(oid, 33, objectname);
                    }

                    jsonString = jsonString + "{\n";
                    jsonString = jsonString + "\"status\": \"success\"\n";
                    jsonString = jsonString + "}\n";
                    jsonString = jsonString + "]\n}";
                    context.Response.Write(jsonString);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
                jsonString = jsonString + "{\n";
                jsonString = jsonString + "\"status\": \"failed\"\n";
                jsonString = jsonString + "}\n";
                jsonString = jsonString + "]\n}";
                context.Response.Write(jsonString);
            }
        }