Beispiel #1
0
        private bool InsertDataFile(SQLOutboundChanel chn, string fname, DataSet ds, List <string> idList, int count)
        {
            int i = 1;

            foreach (DataTable dt in ds.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    chn.OperationName = fname;
                    OleDbCommand cmd = Program.db.GetCommand();
                    MapingHelper.BuildInsertCmd(chn, dr, cmd);
                    cmd.CommandType = CommandType.Text;

                    Program.Log.Write(string.Format("Insert data into file. {0}/{1}", i++, count));
                    if (!Program.db.ExecCommand(cmd))
                    {
                        return(false);
                    }

                    string id = Convert.ToString(dr["data_id"]);
                    idList.Add(id);
                }
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Write logical:
        /// 1.check PK field whether is existed or not
        /// 2.insert new record where PK is not exist
        /// 3.update record when PK is exist
        /// 4.delete record TODO:???
        ///
        /// Insert logical:
        /// 1.select empty DataSet from 3rd database
        /// 2.insert new record
        /// 3.SqlAdapter.update
        /// </summary>
        /// <param name="ds"></param>
        /// <param name="ch"></param>
        /// <returns></returns>
        private bool WriteTable(DataSet ds, SQLOutboundChanel ch)
        {
            //OleDbCommand cmd = Program.db.GetCommand();

            // ------ 20070419 ------
            string[] data_Id = new string[1];
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                try
                {
                    OleDbCommand cmd = Program.db.GetCommand();

                    if (!RecordIsExist(dr, ch))
                    {
                        MapingHelper.BuildInsertCmd(ch, dr, cmd);
                    }
                    else
                    {
                        MapingHelper.BuildUpdateCmd(ch, dr, cmd);
                    }

                    cmd.CommandType = CommandType.Text;

                    if (Program.db.ExecCommand(cmd))
                    {
                        data_Id[0] = Convert.ToString(dr["data_id"]);
                        OnDataDischarge(data_Id);
                        //TestCase.OnDataDischarge(data_Id); //DEBUG
                    }
                }
                catch (Exception Ex)
                {
                    Program.Log.Write(Ex);
                    Program.Log.Write(LogType.Info, Program.db.ConnectionString);
                    if (!ch.IgnoreDBException)
                    {
                        return(false);
                    }
                }
            }
            return(true);
            // ----------------------


            //try
            //{
            //    string[] data_Id =new string[1];
            //     foreach (DataRow dr in ds.Tables[0].Rows)
            //    {
            //        if (!RecordIsExist(dr, ch))
            //            MapingHelper.BuildInsertCmd(ch, dr, cmd);
            //        else
            //            MapingHelper.BuildUpdateCmd(ch, dr, cmd);

            //        cmd.CommandType = CommandType.Text;

            //        if (Program.db.ExecCommand(cmd))
            //        {
            //            data_Id[0] = Convert.ToString(dr["data_id"]);
            //            OnDataDischarge(data_Id);
            //            //TestCase.OnDataDischarge(data_Id); //DEBUG
            //        }
            //    }
            //    return true;
            //}
            //catch(Exception Ex)
            //{
            //    Program.Log.Write(Ex);
            //    return false;
            //}
        }