public static long WMSaveDispatchHead(object objDispatch)
        {
            long result = 0;
            int  RSLT = 0; long DispatchID = 0;

            BrilliantWMS.WMSInbound.iInboundClient   Inbound = new WMSInbound.iInboundClient();
            BrilliantWMS.WMSOutbound.iOutboundClient Outbound = new WMSOutbound.iOutboundClient();
            try
            {
                CustomProfile profile = CustomProfile.GetProfile();
                BrilliantWMS.WMSOutbound.tDispatchHead dh = new WMSOutbound.tDispatchHead();
                Dictionary <string, object>            d  = new Dictionary <string, object>();
                d = (Dictionary <string, object>)objDispatch;
                if (HttpContext.Current.Session["QCID"] != null)
                {
                    int chkJObCart = Inbound.CheckJobCard(Convert.ToInt64(HttpContext.Current.Session["QCID"].ToString()), "Dispatch", profile.DBConnection._constr);
                    if (chkJObCart >= 1)
                    {
                        DataSet dsJCN = new DataSet();
                        dsJCN = Outbound.CheckSelectedSOJobCardNo(Convert.ToInt64(HttpContext.Current.Session["QCID"].ToString()), "Dispatch", profile.DBConnection._constr);
                        if (dsJCN != null && dsJCN.Tables[0].Rows.Count > 0)
                        {
                            string   grpQCID = dsJCN.Tables[0].Rows[0]["OrderNo"].ToString();
                            string[] TotQC   = grpQCID.Split(',');
                            int      QCCnt   = TotQC.Count();
                            for (int p = 0; p <= QCCnt - 1; p++)
                            {
                                dh.CreatedBy         = profile.Personal.UserID;
                                dh.CreationDate      = DateTime.Now;
                                dh.OID               = long.Parse(TotQC[p].ToString());
                                dh.DispatchDate      = Convert.ToDateTime(d["DispatchDate"]);
                                dh.DispatchBy        = Convert.ToInt64(d["DispatchBy"].ToString());
                                dh.Remark            = d["Remark"].ToString();
                                dh.AirwayBill        = d["AirwayBill"].ToString();
                                dh.ShippingType      = d["ShippingType"].ToString();
                                dh.CompanyID         = profile.Personal.CompanyID;
                                dh.Status            = Convert.ToInt64(d["Status"].ToString());
                                dh.ShippingDate      = Convert.ToDateTime(d["ShippingDate"].ToString());
                                dh.TransporterName   = d["TransporterName"].ToString();
                                dh.TransporterRemark = d["TransporterRemark"].ToString();
                                dh.ExpDeliveryDate   = Convert.ToDateTime(d["ExpDeliveryDate"].ToString());
                                dh.ObjectName        = "SalesOrder";

                                DispatchID = Outbound.SavetDispatchHead(dh, profile.DBConnection._constr);

                                if (DispatchID > 0)
                                {
                                    RSLT = Outbound.FinalSaveDispatchDetail(long.Parse(TotQC[p].ToString()), HttpContext.Current.Session.SessionID, ObjectName, DispatchID, profile.Personal.UserID.ToString(), Convert.ToInt16(dh.Status), "SalesOrder", profile.DBConnection._constr);
                                    if (RSLT == 1 || RSLT == 2)
                                    {
                                        result = DispatchID;
                                    }
                                    else if (RSLT == 0)
                                    {
                                        result = 0;
                                    }
                                    iUC_AttachDocumentClient DocumentSourceClient = new iUC_AttachDocumentClient();//Document Save
                                    DocumentSourceClient.FinalSaveToDBtDocument(HttpContext.Current.Session.SessionID, DispatchID, profile.Personal.UserID.ToString(), ObjectName + "Document", HttpRuntime.AppDomainAppPath.ToString(), profile.DBConnection._constr);
                                }
                            }
                            Outbound.ClearTempDataFromDBDispatch(HttpContext.Current.Session.SessionID, profile.Personal.UserID.ToString(), ObjectName, profile.DBConnection._constr);
                        }
                    }
                    else
                    {
                        dh.CreatedBy         = profile.Personal.UserID;
                        dh.CreationDate      = DateTime.Now;
                        dh.OID               = long.Parse(HttpContext.Current.Session["QCID"].ToString());
                        dh.DispatchDate      = Convert.ToDateTime(d["DispatchDate"]);
                        dh.DispatchBy        = Convert.ToInt64(d["DispatchBy"].ToString());
                        dh.Remark            = d["Remark"].ToString();
                        dh.AirwayBill        = d["AirwayBill"].ToString();
                        dh.ShippingType      = d["ShippingType"].ToString();
                        dh.CompanyID         = profile.Personal.CompanyID;
                        dh.Status            = Convert.ToInt64(d["Status"].ToString());
                        dh.ShippingDate      = Convert.ToDateTime(d["ShippingDate"].ToString());
                        dh.TransporterName   = d["TransporterName"].ToString();
                        dh.TransporterRemark = d["TransporterRemark"].ToString();
                        dh.ExpDeliveryDate   = Convert.ToDateTime(d["ExpDeliveryDate"].ToString());
                        dh.ObjectName        = "SalesOrder";

                        DispatchID = Outbound.SavetDispatchHead(dh, profile.DBConnection._constr);

                        if (DispatchID > 0)
                        {
                            RSLT = Outbound.FinalSaveDispatchDetail(long.Parse(HttpContext.Current.Session["QCID"].ToString()), HttpContext.Current.Session.SessionID, ObjectName, DispatchID, profile.Personal.UserID.ToString(), Convert.ToInt16(dh.Status), "SalesOrder", profile.DBConnection._constr);
                            if (RSLT == 1 || RSLT == 2)
                            {
                                result = DispatchID;
                            }
                            else if (RSLT == 0)
                            {
                                result = 0;
                            }
                            iUC_AttachDocumentClient DocumentSourceClient = new iUC_AttachDocumentClient();//Document Save
                            DocumentSourceClient.FinalSaveToDBtDocument(HttpContext.Current.Session.SessionID, DispatchID, profile.Personal.UserID.ToString(), ObjectName + "Document", HttpRuntime.AppDomainAppPath.ToString(), profile.DBConnection._constr);
                        }
                        Outbound.ClearTempDataFromDBDispatch(HttpContext.Current.Session.SessionID, profile.Personal.UserID.ToString(), ObjectName, profile.DBConnection._constr);
                    }
                }
                else if (HttpContext.Current.Session["TRID"] != null)
                {
                    int chkJObCart = Inbound.CheckJobCard(Convert.ToInt64(HttpContext.Current.Session["TRID"].ToString()), "Transfer", profile.DBConnection._constr);
                    if (chkJObCart >= 1)
                    {
                        DataSet dsJCN = new DataSet();
                        dsJCN = Outbound.CheckSelectedSOJobCardNo(Convert.ToInt64(HttpContext.Current.Session["TRID"].ToString()), "Transfer", profile.DBConnection._constr);
                        if (dsJCN != null && dsJCN.Tables[0].Rows.Count > 0)
                        {
                            string   grpQCID = dsJCN.Tables[0].Rows[0]["OrderNo"].ToString();
                            string[] TotQC   = grpQCID.Split(',');
                            int      QCCnt   = TotQC.Count();
                            for (int p = 0; p <= QCCnt - 1; p++)
                            {
                                dh.CreatedBy         = profile.Personal.UserID;
                                dh.CreationDate      = DateTime.Now;
                                dh.OID               = long.Parse(TotQC[p].ToString());
                                dh.DispatchDate      = Convert.ToDateTime(d["DispatchDate"]);
                                dh.DispatchBy        = Convert.ToInt64(d["DispatchBy"].ToString());
                                dh.Remark            = d["Remark"].ToString();
                                dh.AirwayBill        = d["AirwayBill"].ToString();
                                dh.ShippingType      = d["ShippingType"].ToString();
                                dh.CompanyID         = profile.Personal.CompanyID;
                                dh.Status            = Convert.ToInt64(d["Status"].ToString());
                                dh.ShippingDate      = Convert.ToDateTime(d["ShippingDate"].ToString());
                                dh.TransporterName   = d["TransporterName"].ToString();
                                dh.TransporterRemark = d["TransporterRemark"].ToString();
                                dh.ExpDeliveryDate   = Convert.ToDateTime(d["ExpDeliveryDate"].ToString());
                                dh.ObjectName        = "Transfer";

                                DispatchID = Outbound.SavetDispatchHead(dh, profile.DBConnection._constr);

                                if (DispatchID > 0)
                                {
                                    RSLT = Outbound.FinalSaveDispatchDetail(long.Parse(TotQC[p].ToString()), HttpContext.Current.Session.SessionID, ObjectName, DispatchID, profile.Personal.UserID.ToString(), Convert.ToInt16(dh.Status), "Transfer", profile.DBConnection._constr);
                                    if (RSLT == 1 || RSLT == 2)
                                    {
                                        result = DispatchID;
                                    }
                                    else if (RSLT == 0)
                                    {
                                        result = 0;
                                    }
                                    iUC_AttachDocumentClient DocumentSourceClient = new iUC_AttachDocumentClient();//Document Save
                                    DocumentSourceClient.FinalSaveToDBtDocument(HttpContext.Current.Session.SessionID, DispatchID, profile.Personal.UserID.ToString(), ObjectName + "Document", HttpRuntime.AppDomainAppPath.ToString(), profile.DBConnection._constr);
                                }
                            }
                            Outbound.ClearTempDataFromDBDispatch(HttpContext.Current.Session.SessionID, profile.Personal.UserID.ToString(), ObjectName, profile.DBConnection._constr);
                        }
                    }
                    else
                    {
                        dh.CreatedBy         = profile.Personal.UserID;
                        dh.CreationDate      = DateTime.Now;
                        dh.OID               = long.Parse(HttpContext.Current.Session["TRID"].ToString());
                        dh.DispatchDate      = Convert.ToDateTime(d["DispatchDate"]);
                        dh.DispatchBy        = Convert.ToInt64(d["DispatchBy"].ToString());
                        dh.Remark            = d["Remark"].ToString();
                        dh.AirwayBill        = d["AirwayBill"].ToString();
                        dh.ShippingType      = d["ShippingType"].ToString();
                        dh.CompanyID         = profile.Personal.CompanyID;
                        dh.Status            = Convert.ToInt64(d["Status"].ToString());
                        dh.ShippingDate      = Convert.ToDateTime(d["ShippingDate"].ToString());
                        dh.TransporterName   = d["TransporterName"].ToString();
                        dh.TransporterRemark = d["TransporterRemark"].ToString();
                        dh.ExpDeliveryDate   = Convert.ToDateTime(d["ExpDeliveryDate"].ToString());
                        dh.ObjectName        = "Transfer";

                        DispatchID = Outbound.SavetDispatchHead(dh, profile.DBConnection._constr);

                        if (DispatchID > 0)
                        {
                            RSLT = Outbound.FinalSaveDispatchDetail(long.Parse(HttpContext.Current.Session["TRID"].ToString()), HttpContext.Current.Session.SessionID, ObjectName, DispatchID, profile.Personal.UserID.ToString(), Convert.ToInt16(dh.Status), "Transfer", profile.DBConnection._constr);
                            if (RSLT == 1 || RSLT == 2)
                            {
                                result = DispatchID;
                            }
                            else if (RSLT == 0)
                            {
                                result = 0;
                            }
                            iUC_AttachDocumentClient DocumentSourceClient = new iUC_AttachDocumentClient();//Document Save
                            DocumentSourceClient.FinalSaveToDBtDocument(HttpContext.Current.Session.SessionID, DispatchID, profile.Personal.UserID.ToString(), ObjectName + "Document", HttpRuntime.AppDomainAppPath.ToString(), profile.DBConnection._constr);
                        }
                        Outbound.ClearTempDataFromDBDispatch(HttpContext.Current.Session.SessionID, profile.Personal.UserID.ToString(), ObjectName, profile.DBConnection._constr);
                    }
                }
            }
            catch (System.Exception ex) { Login.Profile.ErrorHandling(ex, "DispatchDetail.aspx", "WMSaveDispatchHead"); result = 0; }
            finally { Outbound.Close(); }
            return(result);
        }