private static bool InsertDataFileIntoDB(Byte[] Data, string VersionID, string Notes)
        {
            bool result      = true;
            long SegmentSz   = 8000;
            long numSegments = Data.Length / SegmentSz;

            if (Data.Length % SegmentSz > 0)
            {
                numSegments++;
            }

            Byte[] segData = new Byte[SegmentSz];
            //long idx = 0;
            long MaxSegID = GetMaxSegmentID();
            long idx      = MaxSegID;
            long i        = 0;
            long j        = 0;

            while (i < Data.Length)
            {
                try
                {
                    SegmentDataOBJ segObj = new SegmentDataOBJ();
                    //xet du lieu Segment thu idx
                    long k = 0; //so byte cua segment (do dai cua segment idx)
                    while (k < SegmentSz && i < Data.Length)
                    {
                        segData[k] = Data[i];
                        i++;
                        k++;
                    }
                    idx++;

                    segObj.SegmentID   = idx.ToString();
                    segObj.SegmentName = "Ver" + VersionID + "_Seg" + (idx - MaxSegID).ToString();
                    segObj.Data        = segData;
                    segObj.Length      = k;
                    segObj.VersionID   = VersionID;
                    segObj.Notes       = Notes;

                    InsertSegmentData(segObj);
                }
                catch (Exception ex)
                {
                    result = false;
                }
            }


            return(result);
        }
        public static List <SegmentDataOBJ> GetAllSegmentData(string VersionID)
        {
            List <SegmentDataOBJ> lst = new List <SegmentDataOBJ>();

            try
            {
                DataTable dt = new DataTable();

                string sSql = "SELECT * FROM SegmentData WHERE VersionID=" + VersionID + "  ORDER BY SegmentID ASC";

                dt = DataProvider.GetData(sSql);

                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        SegmentDataOBJ segObj = new SegmentDataOBJ();
                        segObj.SegmentID   = dt.Rows[i]["SegmentID"].ToString();
                        segObj.SegmentName = dt.Rows[i]["SegmentName"].ToString();
                        segObj.Data        = (byte[])dt.Rows[i]["Data"];
                        segObj.Length      = long.Parse(dt.Rows[i]["Length"].ToString());
                        segObj.VersionID   = dt.Rows[i]["VersionID"].ToString();
                        segObj.Date        = dt.Rows[i]["Date"].ToString();
                        segObj.Notes       = dt.Rows[i]["Notes"].ToString();

                        lst.Add(segObj);
                    }
                }
                else
                {
                    lst = null;
                }
            }
            catch (Exception ex)
            {
                lst = null;
            }

            return(lst);
        }
        public static bool InsertSegmentData(SegmentDataOBJ segObj)
        {
            bool result;

            try
            {
                string     sSql = "INSERT INTO SegmentData(SegmentID, SegmentName, Data, Length, VersionID, Date, Notes) VALUES(@SegmentID, @SegmentName, @Data, @Length, @VersionID, GETDATE(), @Notes)";
                SqlCommand cmd  = new SqlCommand(sSql);
                cmd.Parameters.Add("@SegmentID", SqlDbType.VarChar).Value   = segObj.SegmentID;
                cmd.Parameters.Add("@SegmentName", SqlDbType.VarChar).Value = segObj.SegmentName;
                cmd.Parameters.Add("@Data", SqlDbType.Binary).Value         = segObj.Data;
                cmd.Parameters.Add("@Length", SqlDbType.Int).Value          = segObj.Length;
                cmd.Parameters.Add("@VersionID", SqlDbType.VarChar).Value   = segObj.VersionID;
                cmd.Parameters.Add("@Notes", SqlDbType.VarChar).Value       = segObj.Notes;

                result = DataProvider.ExecuteQuery(cmd);
            }
            catch (Exception ex)
            {
                result = false;
            }

            return(result);
        }
Example #4
0
 public static bool InsertSegmentData(SegmentDataOBJ segObj)
 {
     return(SegmentDataMOD.InsertSegmentData(segObj));
 }