Ejemplo n.º 1
0
        public bool NewRow()
        {
            //先将主键值复制回来
            foreach(string key in m_htnewrow.Keys)
            {
                if (m_keyvalue.ContainsKey(key))
                    m_keyvalue[key] = m_htnewrow[key];
            }
            
            NewSubTalbeRecordCommand cmd = new NewSubTalbeRecordCommand();
            cmd.Execute();

            //GernateDefaultValue();//在外面调用,因脚本要干涉这个过程
            SqlDataAdapter adp = m_dbclass.DataAdapter;
            DataTable tbl = m_dbclass.DataTable;

            try
            {
                DataRow newrow = tbl.NewRow();
                newrow.BeginEdit();
                InitNewRowValues(tbl, newrow);
                foreach (string fieldname in m_keyvalue.Keys)
                {
                    bool bIsAutoIncre = false;
                    for (int i = 0; i < m_dbclass.DBPrimaryKey.Length; i++)
                    {
                        if (m_dbclass.DBPrimaryKey[i].ToString().ToLower() == fieldname.ToLower())
                        {
                            bIsAutoIncre = IsAutoIncreamentField(m_dbclass.DBPrimaryKey[i].ToString());
                            break;
                        }
                    }
                    if (!bIsAutoIncre)
                        newrow[fieldname] = m_keyvalue[fieldname];
                }
                FillNewRowDefaultValues(tbl, newrow);

                tbl.Rows.Add(newrow);

                /* remoting
                SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adp);
                adp.InsertCommand = cmdBuilder.GetInsertCommand();
                int val = adp.Update(tbl);
                tbl.AcceptChanges();
                */

                int val = Helper.SaveTable(tbl, m_dbclass.StrSql, MainForm.conn);

                CustomClassCache.DelAllDataTableCache(); //清除缓冲
            }
            catch(Exception ex)
            {
                tbl.RejectChanges();
                Helper.AddLog(ex.Message);
                return false;
            }
            return true;
        }
Ejemplo n.º 2
0
        public bool NewRow()
        {
            //先将主键值复制回来
            foreach (string key in m_htnewrow.Keys)
            {
                if (m_keyvalue.ContainsKey(key))
                {
                    m_keyvalue[key] = m_htnewrow[key];
                }
            }

            NewSubTalbeRecordCommand cmd = new NewSubTalbeRecordCommand();

            cmd.Execute();

            //GernateDefaultValue();//在外面调用,因脚本要干涉这个过程
            SqlDataAdapter adp = m_dbclass.DataAdapter;
            DataTable      tbl = m_dbclass.DataTable;

            try
            {
                DataRow newrow = tbl.NewRow();
                newrow.BeginEdit();
                InitNewRowValues(tbl, newrow);
                foreach (string fieldname in m_keyvalue.Keys)
                {
                    bool bIsAutoIncre = false;
                    for (int i = 0; i < m_dbclass.DBPrimaryKey.Length; i++)
                    {
                        if (m_dbclass.DBPrimaryKey[i].ToString().ToLower() == fieldname.ToLower())
                        {
                            bIsAutoIncre = IsAutoIncreamentField(m_dbclass.DBPrimaryKey[i].ToString());
                            break;
                        }
                    }
                    if (!bIsAutoIncre)
                    {
                        newrow[fieldname] = m_keyvalue[fieldname];
                    }
                }
                FillNewRowDefaultValues(tbl, newrow);

                tbl.Rows.Add(newrow);

                /* remoting
                 * SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adp);
                 * adp.InsertCommand = cmdBuilder.GetInsertCommand();
                 * int val = adp.Update(tbl);
                 * tbl.AcceptChanges();
                 */

                int val = Helper.SaveTable(tbl, m_dbclass.StrSql, MainForm.conn);

                CustomClassCache.DelAllDataTableCache(); //清除缓冲
            }
            catch (Exception ex)
            {
                tbl.RejectChanges();
                Helper.AddLog(ex.Message);
                return(false);
            }
            return(true);
        }