// update
 public static string Update(PackingWeight_List _PackingWeight_List, List<PackingWeight_List_B> _PackingWeight_List_B)
 {
     if (UpdatePackingWeight_List(_PackingWeight_List) == "4")
     {
         UpdateCollection(_PackingWeight_List_B, _PackingWeight_List.ID, _PackingWeight_List.UpdatedBy);
         return "4";
     }
     else
     {
         return "1";
     }
 }
        private static string UpdatePackingWeight_List(PackingWeight_List _PackingWeight_List)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            //Have to wite the stored procedure
            command.CommandText = "sp_update_PackingWeight_List";

            DbParameter param;

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

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

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

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

            param = command.CreateParameter();
            param.ParameterName = "@UpdatedBy";
            param.Value = _PackingWeight_List.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(PackingWeight_List _PackingWeight_List, List<PackingWeight_List_B> _PackingWeight_List_B)
        {
            int ID = InsertPackingWeight_List(_PackingWeight_List);

            if (ID > 0)
            {
                InsertPackingWeightCollection(_PackingWeight_List_B, ID, _PackingWeight_List.CreatedBy);
                return "0";
            }
            else
            {
                return "1";
            }
        }
        public string Submit(PackingWeight_List _Packing_List, List<PackingWeight_List_B> _Packing_List_B)
        {
            string msg = "";

            if (_Packing_List.ID == null)
            {
                _Packing_List.CreatedBy = Session["User"].ToString();
                msg = Packing_List_DA.Insert(_Packing_List, _Packing_List_B);

            }
            else
            {
                _Packing_List.UpdatedBy = Session["User"].ToString();
                msg = Packing_List_DA.Update(_Packing_List, _Packing_List_B);
            }

            return msg;
        }
        public PackingWeight_List Get_Packing_List(int ID)
        {
            // Customer Detail
            PackingWeight_List _Packing_List = new PackingWeight_List();

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

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

            return _Packing_List;
        }
        private static int InsertPacking_List(PackingWeight_List _Packing_List)
        {
            DbCommand command = Catalog_Access.CreateCommand();
            //Have to write the stored procedure
            command.CommandText = "sp_insert_Packing_List";

            DbParameter param;

            #region

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

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

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

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

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

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

            param = command.CreateParameter();
            param.ParameterName = "@BLDate";
            param.Value = _Packing_List.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 = "@CreatedBy";
            param.Value = _Packing_List.CreatedBy;
            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);

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

            return Return;
        }
        public PackingWeight_List Get_PackingWeight_List(int ID)
        {
            // Customer Detail
            PackingWeight_List _PackingWeight_List = new PackingWeight_List();

            DataTable dt = PackingWeight_List_DA.Get_PackingWeight_List(ID);
            //_PackingWeight_List.Customer_ID = int.Parse(dt.Rows[0]["Customer_ID"].ToString());
            _PackingWeight_List.Custom_Invoice_ID = int.Parse(dt.Rows[0]["Custom_Invoice_ID"].ToString());
            _PackingWeight_List.FromEDateString = Convert.ToDateTime(dt.Rows[0]["FromEDate"].ToString()).ToString("MM/dd/yyyy");
            _PackingWeight_List.FromENo = dt.Rows[0]["FromENo"].ToString();

            return _PackingWeight_List;
        }