public string Submit(Commercial_Invoice _Commercial_Invoice, List<Commercial_Invoice_B> _Commercial_Invoice_B)
        {
            string msg = "";

            if (_Commercial_Invoice.ID == null)
            {
                _Commercial_Invoice.CreatedBy = Session["User"].ToString();
                msg = Commercial_Invoice_DA.Insert(_Commercial_Invoice, _Commercial_Invoice_B);

            }
            else
            {
                _Commercial_Invoice.UpdatedBy = Session["User"].ToString();
                msg = Commercial_Invoice_DA.Update(_Commercial_Invoice, _Commercial_Invoice_B);
            }

            return msg;
        }
        public Commercial_Invoice Get_Commercial_Invoice_By_Custom_Invoice_ID(int Custom_Invoice_ID)
        {
            // Customer Detail
            Commercial_Invoice _Commercial_Invoice = new Commercial_Invoice();

            DataTable dt = Commercial_Invoice_DA.Get_Commercial_Invoice_By_Custom_Invoice_ID(Custom_Invoice_ID);
            //_Commercial_Invoice.Customer_ID = int.Parse(dt.Rows[0]["Customer_ID"].ToString());
            _Commercial_Invoice.Custom_Invoice_ID = int.Parse(dt.Rows[0]["Custom_Invoice_ID"].ToString());
            _Commercial_Invoice.From = dt.Rows[0]["From"].ToString();
            _Commercial_Invoice.BLDateString = Convert.ToDateTime(dt.Rows[0]["BLDate"].ToString()).ToString("MM/dd/yyyy");
            _Commercial_Invoice.LCNo = dt.Rows[0]["LCNo"].ToString();
            _Commercial_Invoice.NegotiatedExchangeRate = float.Parse(dt.Rows[0]["NegotiatedExchangeRate"].ToString());
            if (dt.Rows[0]["LCDate"].ToString() != "")
                _Commercial_Invoice.LCDateString = Convert.ToDateTime(dt.Rows[0]["LCDate"].ToString()).ToString("MM/dd/yyyy");

            _Commercial_Invoice.Vessel = dt.Rows[0]["Vessel"].ToString();
            _Commercial_Invoice.HBLNo = dt.Rows[0]["HBLNo"].ToString();
            _Commercial_Invoice.ContainerNo = dt.Rows[0]["ContainerNo"].ToString();

            return _Commercial_Invoice;
        }
 // update
 public static string Update(Commercial_Invoice _Commercial_Invoice, List<Commercial_Invoice_B> _Commercial_Invoice_B)
 {
     if (UpdateCommercial_Invoice(_Commercial_Invoice) == "4")
     {
         UpdateCollection(_Commercial_Invoice_B, _Commercial_Invoice.ID, _Commercial_Invoice.UpdatedBy);
         return "4";
     }
     else
     {
         return "1";
     }
 }
        private static string UpdateCommercial_Invoice(Commercial_Invoice _Commercial_Invoice)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            //Have to wite the stored procedure
            command.CommandText = "sp_update_Commercial_Invoice";

            DbParameter param;

            #region
            param = command.CreateParameter();
            param.ParameterName = "@ID";
            param.Value = _Commercial_Invoice.ID;
            param.DbType = DbType.Int32;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Custom_Invoice_ID";
            param.Value = _Commercial_Invoice.Custom_Invoice_ID;
            param.DbType = DbType.Int32;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@From";
            param.Value = _Commercial_Invoice.From;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@LCNo";
            param.Value = _Commercial_Invoice.LCNo;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@NegotiatedExchangeRate";
            param.Value = _Commercial_Invoice.NegotiatedExchangeRate;
            param.DbType = DbType.Decimal;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Vessel";
            param.Value = _Commercial_Invoice.Vessel;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@HBLNo";
            param.Value = _Commercial_Invoice.HBLNo;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@ContainerNo";
            param.Value = _Commercial_Invoice.ContainerNo;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@BLDate";
            param.Value = _Commercial_Invoice.BLDate;
            param.DbType = DbType.Date;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@LCDate";
            param.Value = _Commercial_Invoice.LCDate;
            param.DbType = DbType.Date;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@UpdatedBy";
            param.Value = _Commercial_Invoice.UpdatedBy;
            param.DbType = DbType.String;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@Return";
            param.DbType = DbType.Int32;
            param.Direction = ParameterDirection.Output;
            command.Parameters.Add(param);
            #endregion

            Catalog_Access.ExecuteNonQuery(command);

            string Return = command.Parameters["@Return"].Value.ToString();

            return Return;
        }
        //insert
        public static string Insert(Commercial_Invoice _Commercial_Invoice, List<Commercial_Invoice_B> _Commercial_Invoice_B)
        {
            int ID = InsertCommercial_Invoice(_Commercial_Invoice);

            if (ID > 0)
            {
                InsertPackingWeightCollection(_Commercial_Invoice_B, ID, _Commercial_Invoice.CreatedBy);
                return "0";
            }
            else
            {
                return "1";
            }
        }