public static string AjaxItemsApplyToSel(string AssessedFreight, string assessedInsurance, string ValuationMethod, string TransID, string itemID, string DeclaredUnitFOB, string AssessedUnitFOB, string ValuationNotes)
        {
            Valuation Val = new Valuation();
            if (Val.SaveValuationItemsApplyToSel(AssessedFreight, assessedInsurance, ValuationMethod, TransID, itemID, DeclaredUnitFOB, AssessedUnitFOB, ValuationNotes)) { /*Val.errorMessage += "Saved";*/ } else { Val.errorMessage += "Error"; }

            return Val.errorMessage;
        }
        public static string AjaxSaveQuery(string SubmissionID, string VersionNo, /*string DeptCode, string DeptPriorStatus,*/ string QueryType)
        {
            Valuation val = new Valuation();
            if (val.validate(QueryType))
            {
                if (DeptPriorStatus >= 1) { Query.Log(Convert.ToInt32(SubmissionID), Convert.ToInt16(VersionNo), Convert.ToInt16(DeptCode), Convert.ToInt32(DeptPriorStatus), Convert.ToInt32(QueryType)); val.errorMessage = "Saved"; }

                //this.Close();
                val.errorMessage = "Error";
            }
            return val.errorMessage;
        }
        public static string AjaxCallToUpdateGrid(string value)
        {
            string returnValue = "";
            Valuation val = new Valuation();

            try
            {
                val.RegistrationValidate(value);
                val.updateGrid();
            }catch(Exception ex)
            {
                returnValue = ex.Message.ToString();
            }
            return returnValue + " Val" + value;
        }
        public static string AjaxSendToIU(string remarks,string submissionID, string versionNo, string importID,string valuationID)
        {
            //string returnValue = "";
            ValuationHeader valHeader = new ValuationHeader();
            Valuation val = new Valuation();
            try {
                valHeader.setSubmission(Convert.ToInt32(submissionID));
                valHeader.PartitionDate = valHeaderPartittionDate;
                valHeader.ImportID = Convert.ToInt32(importID);
                valHeader.VersionNo = Convert.ToInt16(versionNo);
                valHeader.Remarks = remarks;
                valHeader.setValuationID(Convert.ToInt32(valuationID));

                if (valHeader.SendToIU(Convert.ToInt16(GlobalFunctions.gLoginUserCode), remarks)) { val.errorMessage = "Saved"; } else { val.errorMessage = "Error"; }
            }
            catch(Exception ex)
            {
                val.errorMessage = ex.Message.ToString();
            }
            return val.errorMessage;
        }
        public static string ValuationSave(string ValuationMethod,string DeclaredUnitFOB,string AssessedUnitFOB, string AssessedFreight, string itemID, string assessedInsurance, string Remarks,string importID, string VersionNo,string TransID, string DeclareQuantity)
        {
            Valuation val = new Valuation();
                ValuationHeader valHeader = new ValuationHeader();
                ValuationItems valItem = new ValuationItems();

               // string errorMessage = "";
            try
            {  // valHeader.ValuationID = ValuationID;
                valHeader.setValuationID(ValuationID);
                //GlobalFunctions.gLoginUserCode =  Convert.ToInt16(Session["genFlux_login_UCode"].ToString());
                if (val.SaveValidate(ValuationMethod, AssessedUnitFOB, DeclaredUnitFOB))
                {
                    long selectedItem;
                    int dRowIndex;
                    Nullable<Decimal> AssFreight;
                    Nullable<Decimal> AssInsurance;
                    //DataGridViewRow row = dgvLineItems.CurrentRow;

                    selectedItem = Convert.ToInt32(itemID);
                    //dRowIndex = row.Index;
                    if (AssessedFreight.Length == 0) AssFreight = null; else AssFreight = System.Convert.ToDecimal(AssessedFreight);
                    if (assessedInsurance.Length == 0) AssInsurance = null; else AssInsurance = System.Convert.ToDecimal(assessedInsurance);

                    valHeader.Pulled = Pulled;
                    valHeader.Status = Status;
                    valHeader.ImportID = Convert.ToInt32(importID);
                    valHeader.VersionNo = Convert.ToInt32(VersionNo);

                    valHeader.FreightAssessed = AssFreight;
                    valHeader.InsAssessed = AssInsurance;

                    if (valHeader.ValuationID == null || valHeader.ValuationID == 0)
                    {
                        valHeader.ImportID = Convert.ToInt32(importID);
                        valHeader.PartitionDate = valHeaderPartittionDate;
                        valHeader.Status = 1;
                        valHeader.Pulled = false;
                        valHeader.Remarks = Remarks;
                        valHeader.DraftUserID = GlobalFunctions.gLoginUserCode;
                        valHeader.VersionNo = Convert.ToInt16(VersionNo);
                        valHeader.Create(GlobalFunctions.gLoginUserCode) ;
                    }
                    else
                    {
                        //if (valHeader.FreightAssessed != AssFreight || (valHeader.InsAssessed != AssInsurance))
                        //{
                        //valHeader.FreightAssessed = AssFreight;
                        //valHeader.InsAssessed = AssInsurance;
                        //}
                        valHeader.Remarks = Remarks;
                        valHeader.Update(GlobalFunctions.gLoginUserCode);

                    }

                    valItem.VersionNo = Convert.ToInt16(VersionNo);
                    if (string.IsNullOrEmpty(TransID.ToString().Trim()))
                    {
                        valItem.ValuationID = valHeader.ValuationID;
                        valItem.ItemID = selectedItem;
                        valItem.PartitionDate = valHeaderPartittionDate;
                        valItem.ValMethod = System.Convert.ToInt32(ValuationMethod);
                        if ((Convert.ToInt16(ValuationMethod) == 852/*Val Method 1*/) || (Convert.ToInt16(ValuationMethod) == 854 /*Val Method 1D*/))
                        {
                            valItem.AssessedUnitFOB = System.Convert.ToDecimal(DeclaredUnitFOB);
                            //val.errorMessage = "ValItem Save";
                        }
                        else
                        {
                            valItem.AssessedUnitFOB = System.Convert.ToDecimal(AssessedUnitFOB);
                            //val.errorMessage = "ValItem Save Not";
                        }
                        valItem.DraftUserID = GlobalFunctions.gLoginUserCode;
                        //valItem.Notes = txtValNotes.Text;
                        valItem.Create(GlobalFunctions.gLoginUserCode);

                       //row.Cells["TransID"].Value = valItem.TransID;

                        val.errorMessage = valItem.TransID.ToString();
                    }
                    else
                    {
                        valItem.TransID = Convert.ToInt32(TransID);
                        valItem.ValuationID = valHeader.ValuationID;
                        valItem.ItemID = selectedItem;
                        valItem.PartitionDate = valHeaderPartittionDate;
                        valItem.ValMethod = System.Convert.ToInt16(ValuationMethod);
                        if ((Convert.ToInt16(ValuationMethod) == 852/*Val Method 1*/) || (Convert.ToInt16(ValuationMethod) == 854))
                        {
                            valItem.AssessedUnitFOB = System.Convert.ToDecimal(DeclaredUnitFOB);
                            val.errorMessage = "ValItem Update";
                        }
                        else
                        {
                            valItem.AssessedUnitFOB = System.Convert.ToDecimal(AssessedUnitFOB);
                            val.errorMessage = "ValItem Update";
                        }
                        valItem.DraftUserID = GlobalFunctions.gLoginUserCode;
                       // valItem.Notes = txtValNotes.Text;
                        valItem.Update(GlobalFunctions.gLoginUserCode);
                        val.errorMessage = valItem.TransID.ToString();
                    }

                    // Update row here
                    Decimal AssUnitFOB = (AssessedUnitFOB.Trim().Length == 0 ? 0 : System.Convert.ToDecimal(AssessedUnitFOB));
                    Decimal Qty = (DeclareQuantity.Trim().Length == 0 ? 0 : System.Convert.ToDecimal(DeclareQuantity));
                    Decimal AssFOB = AssUnitFOB * Qty;

                    /*
                    row.Cells["ValMethod"].Value = cboValMethod.SelectedValue;
                    row.Cells["ValuationNotes"].Value = txtValNotes.Text;
                    row.Cells["AssessedUnitFOB"].Value = valItem.AssessedUnitFOB.Value;
                    dgvLineItems.UpdateCellValue(row.Cells["AssessedUnitFOB"].ColumnIndex, row.Cells["AssessedUnitFOB"].RowIndex);
                    // Compute Total Assessed FOB and Total Assessed Value
                    ComputeTotalAssessedFOBandValue();

                    // Move to next row available
                    if (dRowIndex < dgvLineItems.Rows.Count - 1)
                    {
                       //dgvLineItems.CurrentCell = dgvLineItems.Rows[dRowIndex + 1].Cells["LineNo"];
                    }
                    */
                    //val.errorMessage = "Saved".Trim();
                    //Debug: val.errorMessage = "ValMethod=> " + valItem.ValMethod + " DeclUnitFOB =>" + DeclaredUnitFOB + " AssessedUnitFOB=>" + valItem.AssessedUnitFOB + " AssFriehgt=> " + valHeader.FreightAssessed + " ItemID=>" + valItem.ItemID + " AssInsurance=>" + valHeader.InsAssessed + " Remarks=>" + valHeader.Remarks + " ImportID=>" + valHeader.ImportID + " VersionNo=>" + valHeader.VersionNo + " TransID=>" + valItem.TransID + " Valitem.ValID=>" + valItem.ValuationID + " User=>" + GlobalFunctions.gLoginUserCode + "error =>" + val.errorMessage;
                    //val.populateGrid();
                }
                //errorMessage = "ValMethod=> " + ValuationMethod + " DeclUnitFOB =>" + DeclaredUnitFOB + " AssessedUnitFOB=>" + AssessedUnitFOB + " AssFriehgt=> " + AssessedFreight + " ItemID=>" + itemID + " AssInsurance=>" + assessedInsurance + " Remarks=>" + Remarks + " ImportID=>" + importID + " VersionNo=>" + VersionNo + " TransID=>" + TransID + " DeclQtty=>" + DeclareQuantity + " User=>" + GlobalFunctions.gLoginUserCode;
                return val.errorMessage;
            }

            catch (Exception ex)
            {
              val. errorMessage += ex.Message.ToString();
               return Status +" "+ val.errorMessage;
            }
        }