Exemplo n.º 1
0
 //*/
 public int Update(string TableName)
 {
     new OleDbCommandBuilder(adapter);
     return(adapter.Update(dataset, TableName));
 }
Exemplo n.º 2
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to update a DataSet
        ///    </Description>
        ///    <Inputs>
        ///        DataSet
        ///    </Inputs>
        ///    <Outputs>
        ///
        ///    </Outputs>
        ///    <Returns>
        ///
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///    </Authors>
        ///    <History>
        ///       Monday, December 27, 2004
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************

        public void UpdateDataSet(DataSet pData)
        {
            const string        METHOD_NAME = THIS + ".UpdateDataSet()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + sys_TableGroupTable.TABLEGROUPID_FLD + ","
                         + sys_TableGroupTable.CODE_FLD + ","
                         + sys_TableGroupTable.TABLEGROUPNAME_FLD + ","
                         + sys_TableGroupTable.GROUPORDER_FLD;


                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                pData.EnforceConstraints = false;
                odadPCS.Update(pData, sys_TableGroupTable.TABLE_NAME);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                }
                else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                }

                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }

            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 3
0
        // Sauvegarde tous les changements effectué dans le dataset
        public void SaveDataSet(string tableName, DataSet dataSet)
        {
            if (dataSet.HasChanges() == false)
            {
                return;
            }

            switch (connType)
            {
            case ConnectionType.DATABASE_MSSQL:
            {
                try
                {
                    var conn    = new SqlConnection(connString);
                    var adapter = new SqlDataAdapter("SELECT * from " + tableName, conn);
                    var builder = new SqlCommandBuilder(adapter);

                    adapter.DeleteCommand = builder.GetDeleteCommand();
                    adapter.UpdateCommand = builder.GetUpdateCommand();
                    adapter.InsertCommand = builder.GetInsertCommand();

                    lock (dataSet)         // lock dataset to prevent changes to it
                    {
                        adapter.ContinueUpdateOnError = true;
                        DataSet changes = dataSet.GetChanges();
                        adapter.Update(changes, tableName);
                        PrintDatasetErrors(changes);
                        dataSet.AcceptChanges();
                    }

                    conn.Close();
                }
                catch (Exception ex)
                {
                    throw new DatabaseException("Can not save table " + tableName, ex);
                }

                break;
            }

            case ConnectionType.DATABASE_ODBC:
            {
                try
                {
                    var conn    = new OdbcConnection(connString);
                    var adapter = new OdbcDataAdapter("SELECT * from " + tableName, conn);
                    var builder = new OdbcCommandBuilder(adapter);

                    adapter.DeleteCommand = builder.GetDeleteCommand();
                    adapter.UpdateCommand = builder.GetUpdateCommand();
                    adapter.InsertCommand = builder.GetInsertCommand();

                    DataSet changes;
                    lock (dataSet)         // lock dataset to prevent changes to it
                    {
                        adapter.ContinueUpdateOnError = true;
                        changes = dataSet.GetChanges();
                        adapter.Update(changes, tableName);
                        dataSet.AcceptChanges();
                    }

                    PrintDatasetErrors(changes);

                    conn.Close();
                }
                catch (Exception ex)
                {
                    throw new DatabaseException("Can not save table ", ex);
                }

                break;
            }

            case ConnectionType.DATABASE_MYSQL:
            {
                return;
            }

            case ConnectionType.DATABASE_OLEDB:
            {
                try
                {
                    var conn    = new OleDbConnection(connString);
                    var adapter = new OleDbDataAdapter("SELECT * from " + tableName, conn);
                    var builder = new OleDbCommandBuilder(adapter);

                    adapter.DeleteCommand = builder.GetDeleteCommand();
                    adapter.UpdateCommand = builder.GetUpdateCommand();
                    adapter.InsertCommand = builder.GetInsertCommand();

                    DataSet changes;
                    lock (dataSet)         // lock dataset to prevent changes to it
                    {
                        adapter.ContinueUpdateOnError = true;
                        changes = dataSet.GetChanges();
                        adapter.Update(changes, tableName);
                        dataSet.AcceptChanges();
                    }

                    PrintDatasetErrors(changes);

                    conn.Close();
                }
                catch (Exception ex)
                {
                    throw new DatabaseException("Can not save table", ex);
                }
                break;
            }
            }
        }
Exemplo n.º 4
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to update a DataSet
        ///    </Description>
        ///    <Inputs>
        ///        DataSet
        ///    </Inputs>
        ///    <Outputs>
        ///
        ///    </Outputs>
        ///    <Returns>
        ///
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///    </Authors>
        ///    <History>
        ///       Tuesday, February 07, 2006
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************

        public void SaveDeliveryHour(DataTable pdtbData)
        {
            const string        METHOD_NAME = THIS + ".SaveDeliveryHour()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + PO_VendorDeliveryScheduleTable.VENDORDELIVERYSCHEDULE_FLD + ","
                         + PO_VendorDeliveryScheduleTable.PARTYID_FLD + ","
                         + PO_VendorDeliveryScheduleTable.CCNID_FLD + ","
                         + PO_VendorDeliveryScheduleTable.DELIVERYTYPE_FLD + ","
                         + PO_VendorDeliveryScheduleTable.DELHOUR_FLD + ","
                         + PO_VendorDeliveryScheduleTable.WEEKLYDAY_FLD + ","
                         + PO_VendorDeliveryScheduleTable.MONTHLYDATE_FLD + ","
                         + PO_VendorDeliveryScheduleTable.COMMENT_FLD + ","
                         + PO_VendorDeliveryScheduleTable.DELMIN_FLD + ","
                         + PO_VendorDeliveryScheduleTable.PRODUCTID_FLD
                         + "  FROM " + PO_VendorDeliveryScheduleTable.TABLE_NAME;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                odadPCS.Update(pdtbData);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors.Count > 1)
                {
                    if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                    {
                        throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                    }
                    else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                    {
                        throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                    }
                }
                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }
            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 5
0
 private void UpdateDB()
 {
     OleDbCommandBuilder cm = new OleDbCommandBuilder(da);
     da.Update(dt);
 }
    // override the 'Save uploaded file' method
    protected override string SaveUploadedFile(string folder, string name, string title, Stream stream)
    {
        Regex regex = new Regex("^" + DatabaseProtocol, RegexOptions.Compiled);

        if (!regex.IsMatch(folder)) // it is the 'file system' gallery command
        {
            // call the base method
            return(base.SaveUploadedFile(folder, name, title, stream));
        }
        string url = regex.Replace(folder, "");

        OleDbConnection connection = new OleDbConnection();

        try
        {
            connection.ConnectionString = ConnectionString;
            connection.Open();
            int folderId = findFolderId(connection, url);
            if (folderId >= 0)
            {
                string           sqlString = "Select * from tbImage Where fldFolderId=" + folderId.ToString() + " AND fldName=\"" + name + "\"";
                OleDbDataAdapter eAdapter  = new OleDbDataAdapter(sqlString, connection);
                DataTable        eTable    = new DataTable();
                eAdapter.Fill(eTable);

                // Delete the duplicate if it is present
                if (eTable.Rows.Count > 0)
                {
                    OleDbCommand myComm = new OleDbCommand("DELETE FROM tbImage Where fldFolderId=" + folderId.ToString() + " AND fldName=\"" + name + "\"", connection);
                    myComm.ExecuteNonQuery();
                }

                eAdapter.Dispose();
                eTable.Dispose();

                sqlString = "Select * from tbImage Where fldFolderId=" + folderId.ToString();
                eAdapter  = new OleDbDataAdapter(sqlString, connection);
                eTable    = new DataTable();
                eAdapter.Fill(eTable);

                OleDbCommand cmdInsert = new OleDbCommand("INSERT INTO tbImage (fldName, fldFolderId, fldDescription, fldContent) VALUES(?, ?, ?, ?)", connection);
                cmdInsert.Parameters.Add(new OleDbParameter("fldName", OleDbType.VarChar, 50, "fldName"));
                cmdInsert.Parameters.Add(new OleDbParameter("fldFolderId", OleDbType.Integer, 0, "fldFolderId"));
                cmdInsert.Parameters.Add(new OleDbParameter("fldDescription", OleDbType.VarChar, 100, "fldDescription"));
                cmdInsert.Parameters.Add(new OleDbParameter("fldContent", OleDbType.Binary, 0, "fldContent"));
                eAdapter.InsertCommand = cmdInsert;

                DataRow newRow = eTable.NewRow();
                newRow["fldName"]        = name;
                newRow["fldFolderId"]    = folderId;
                newRow["fldDescription"] = title;
                byte[] content = new byte[stream.Length];
                stream.Read(content, 0, (int)stream.Length);
                newRow["fldContent"] = content;

                eTable.Rows.Add(newRow);
                eAdapter.Update(eTable);

                // Release the Resources
                cmdInsert = null;
                eAdapter.Dispose();
                eTable.Dispose();
            }
        }
        finally
        {
            connection.Close();
            connection.Dispose();
        }
        return(name);
    }
Exemplo n.º 7
0
        public void Save()
        {
            string    dstrSQL;
            DataTable dDT;
            string    dstrName = "";

            try
            {
                File.Copy(Application.StartupPath + @"\system\System.mdb", Application.StartupPath + @"\system\System.mdb.bak", true);

                if (!DBAct.clsDBAct.funBeginTransaction())
                {
                    MessageBox.Show("DB Transaction NG!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                //DataAdapter 생성
                OleDbDataAdapter    dataAdapter    = new OleDbDataAdapter("SELECT * FROM tbUser order by UserLevel", DBAct.clsDBAct.funOleDbConnect());
                OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter);

                //DataAdapter를 이용하여 DB로 업데이트를 한다.
                dataAdapter.SelectCommand.Transaction = DBAct.clsDBAct.funOleDbTransaction();
                dataAdapter.Update((DataTable)pUserBindingSource.DataSource);

                if (!DBAct.clsDBAct.funCommitTransaction())
                {
                    MessageBox.Show("DB Commit Transaction NG!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    DBAct.clsDBAct.funRollbackTransaction();
                    return;
                }

                //DB에 저장이 성공적으로 완료되면 다시 DB에서 Data를 로딩한다.
                //구조체의 내용 갱신
                pInfo.Unit(0).SubUnit(0).RemoveUser();

                //DB로부터 User 정보를 읽어들여 저장한다.
                dstrSQL = "SELECT * FROM tbUser order by UserLevel";
                dDT     = DBAct.clsDBAct.funSelectQuery2(dstrSQL);                      //DataTable을 받아온다.
                if (dDT != null)
                {
                    pInfo.DeleteTable("USER");
                    pInfo.AddDataTable("USER", dDT);

                    foreach (DataRow dr in dDT.Rows)
                    {
                        dstrName = dr["UserID"].ToString();
                        pInfo.Unit(0).SubUnit(0).AddUser(dstrName);

                        pInfo.Unit(0).SubUnit(0).User(dstrName).Level    = Convert.ToInt32(dr["UserLevel"].ToString());
                        pInfo.Unit(0).SubUnit(0).User(dstrName).PassWord = dr["Pass"].ToString();
                        pInfo.Unit(0).SubUnit(0).User(dstrName).Desc     = dr["Description"].ToString();
                    }
                }

                //DBAct.clsDBAct.funDisconnect();     // DB 연결을 끊는다.

                subSaveLastModified(); //최종 수정된 날짜를 Ini파일에 저장한다.

                MessageBox.Show("Data Save Success!", "Jobs Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                pInfo.subLog_Set(InfoAct.clsInfo.LogType.CIM, ex.ToString());
                DBAct.clsDBAct.funRollbackTransaction();
                DBAct.clsDBAct.funDisconnect();     // DB 연결을 끊는다.
                MessageBox.Show("DB Update Fail, Because DB Process Error!", "DB Update Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 8
0
        private void BtnPrint_Click(object sender, EventArgs e)
        {
            if (c标签模板.SelectedIndex < 0)
            {
                MessageBox.Show("请选择一个模板再打印");
                return;
            }

            // 判断,如果数据库有存过一张标签,则不管,否则保存一张标签
            string sql = "select * from 标签 where 生产指令='{0}'";

            System.Data.DataTable dt = new System.Data.DataTable();
            if (!mySystem.Parameter.isSqlOk)
            {
                OleDbDataAdapter    da = new OleDbDataAdapter(String.Format(sql, _s), mySystem.Parameter.connOle);
                OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
                da.Fill(dt);
                if (dt.Rows.Count == 0)
                {
                    DataRow dr = dt.NewRow();
                    dr["生产指令ID"]     = mySystem.Parameter.proInstruID;
                    dr["生产指令"]       = _s;
                    dr["标签类型"]       = c标签模板.SelectedIndex;
                    dr["膜代码"]        = cmb膜代码.SelectedItem;
                    dr["批号中文"]       = tc批号.Text;
                    dr["数量米"]        = tc数量米.Text;
                    dr["数量千克"]       = tc数量KG.Text;
                    dr["日期中文"]       = dc日期.Value;
                    dr["班次中文"]       = (cc班次.SelectedItem.ToString() == "白班" ? "白班" : "夜班");
                    dr["产品名称中文"]     = tc产品名称.Text;
                    dr["产品编码中文"]     = tc产品编码.Text;
                    dr["产品规格中文"]     = tc产品规格.Text;
                    dr["产品批号中文"]     = tc产品批号.Text;
                    dr["生产日期中文"]     = dc生产日期.Value;
                    dr["有效期至中文"]     = dc有效期至.Value;
                    dr["数量中文"]       = tc数量.Text;
                    dr["包装序号中文"]     = tc包装序号.Text;
                    dr["注册证号中文"]     = tc注册证号.Text;
                    dr["毛重中文"]       = tc毛重.Text;
                    dr["箱体规格中文"]     = tc箱体规格.Text;
                    dr["Name_E"]     = teName.Text;
                    dr["Code_E"]     = teCode.Text;
                    dr["Size_E"]     = teSize.Text;
                    dr["Batch_E"]    = teBatch.Text;
                    dr["Mfg_E"]      = deMfg.Value;
                    dr["Expiry_E"]   = deExpiry.Value;
                    dr["Quantity_E"] = teQuantity.Text;
                    dr["Pack_E"]     = tePack.Text;
                    dr["CFDA_E"]     = teCFDA.Text;
                    dr["Gross_E"]    = teGross.Text;
                    dr["Carton_E"]   = teCarton.Text;
                    dt.Rows.Add(dr);
                    da.Update(dt);
                }
            }
            else
            {
                SqlDataAdapter    da = new SqlDataAdapter(String.Format(sql, _s), mySystem.Parameter.conn);
                SqlCommandBuilder cb = new SqlCommandBuilder(da);
                da.Fill(dt);
                if (dt.Rows.Count == 0)
                {
                    DataRow dr = dt.NewRow();
                    dr["生产指令ID"]     = mySystem.Parameter.proInstruID;
                    dr["生产指令"]       = _s;
                    dr["标签类型"]       = c标签模板.SelectedIndex;
                    dr["膜代码"]        = cmb膜代码.SelectedItem;
                    dr["批号中文"]       = tc批号.Text;
                    dr["数量米"]        = tc数量米.Text;
                    dr["数量千克"]       = tc数量KG.Text;
                    dr["日期中文"]       = dc日期.Value;
                    dr["班次中文"]       = (cc班次.SelectedItem.ToString() == "白班" ? "白班" : "夜班");
                    dr["产品名称中文"]     = tc产品名称.Text;
                    dr["产品编码中文"]     = tc产品编码.Text;
                    dr["产品规格中文"]     = tc产品规格.Text;
                    dr["产品批号中文"]     = tc产品批号.Text;
                    dr["生产日期中文"]     = dc生产日期.Value;
                    dr["有效期至中文"]     = dc有效期至.Value;
                    dr["数量中文"]       = tc数量.Text;
                    dr["包装序号中文"]     = tc包装序号.Text;
                    dr["注册证号中文"]     = tc注册证号.Text;
                    dr["毛重中文"]       = tc毛重.Text;
                    dr["箱体规格中文"]     = tc箱体规格.Text;
                    dr["Name_E"]     = teName.Text;
                    dr["Code_E"]     = teCode.Text;
                    dr["Size_E"]     = teSize.Text;
                    dr["Batch_E"]    = teBatch.Text;
                    dr["Mfg_E"]      = deMfg.Value;
                    dr["Expiry_E"]   = deExpiry.Value;
                    dr["Quantity_E"] = teQuantity.Text;
                    dr["Pack_E"]     = tePack.Text;
                    dr["CFDA_E"]     = teCFDA.Text;
                    dr["Gross_E"]    = teGross.Text;
                    dr["Carton_E"]   = teCarton.Text;
                    dt.Rows.Add(dr);
                    da.Update(dt);
                }
            }



            printLable();
            GC.Collect();
        }
Exemplo n.º 9
0
        public void Update(DataSet ds)
        {
            if (workbook == null)
            {
                objDBConn.Open();
                DataTable schemaTable = objDBConn.GetSchema("Tables");
                objDBConn.Close();

                foreach (DataTable dataTable in ds.Tables)
                {
                    foreach (DataColumn col in dataTable.Columns)
                    {
                        if (col.ColumnName.Contains("."))
                        {
                            col.ColumnName = col.ColumnName.Replace(".", "");
                        }
                        if (col.ColumnName.Contains("#"))
                        {
                            col.ColumnName = col.ColumnName.Replace("#", "Number");
                        }
                        if (col.ColumnName.Contains("!"))
                        {
                            col.ColumnName = col.ColumnName.Replace("!", "");
                        }
                        if (col.DataType.Equals(typeof(DateTime)))
                        {
                            foreach (DataRow row in dataTable.Rows)
                            {
                                if (!row.IsNull(col))
                                {
                                    if (((DateTime)row[col]).Ticks.Equals(0))
                                    {
                                        row[col] = DBNull.Value;
                                    }
                                }
                            }
                        }
                    }
                    DataSet tempDS    = new DataSet();
                    string  tableName = dataTable.TableName;

                    DataView view = new DataView(schemaTable);
                    view.RowFilter = "Table_Name='" + tableName + "'";
                    if (view.ToTable().Rows.Count <= 0)
                    {
                        CreateTable(dataTable);
                    }
                    OleDbDataAdapter objDA = (OleDbDataAdapter)objDBFactory.CreateDataAdapter();
                    objDA.SelectCommand = (OleDbCommand)CreateCommand("select * from [" + tableName + "]");
                    objDA.Fill(tempDS, tableName);
                    OleDbCommandBuilder objCB = (OleDbCommandBuilder)objDBFactory.CreateCommandBuilder();
                    objCB.QuotePrefix = "[";
                    objCB.QuoteSuffix = "]";
                    objCB.DataAdapter = objDA;
                    string fieldlist = string.Empty;
                    string valuelist = string.Empty;
                    objDA.Update(ds, tableName);
                }

                //foreach (DataRow schemaRow in schemaTable.Rows)
                //{
                //    DataSet tempDS = new DataSet();

                //    string tableName = schemaRow["Table_Name"].ToString();
                //    OleDbDataAdapter objDA = (OleDbDataAdapter)objDBFactory.CreateDataAdapter();
                //    objDA.SelectCommand = (OleDbCommand)CreateCommand("select * from [" + tableName + "]");
                //    objDA.Fill(tempDS, tableName);
                //    OleDbCommandBuilder objCB = (OleDbCommandBuilder)objDBFactory.CreateCommandBuilder();
                //    objCB.QuotePrefix = "[";
                //    objCB.QuoteSuffix = "]";
                //    objCB.DataAdapter = objDA;
                //    string fieldlist = string.Empty;
                //    string valuelist = string.Empty;
                //    //foreach (DataColumn column in ds.Tables[tableName].Columns)
                //    //{
                //    //    if (string.IsNullOrEmpty(fieldlist))
                //    //        fieldlist = "[" + column.ColumnName + "]";
                //    //    else
                //    //    {
                //    //        fieldlist += ", [" + column.ColumnName + "]";
                //    //    }
                //    //    if (string.IsNullOrEmpty(valuelist))
                //    //        valuelist = "?";
                //    //    else
                //    //    {
                //    //        valuelist += ", ?";
                //    //    }
                //    //}

                //    //foreach (DataRow row in ds.Tables[tableName].Rows)
                //    //{
                //    //    foreach (DataColumn column in ds.Tables[tableName].Columns)
                //    //    {
                //    //        if (string.IsNullOrEmpty(fieldlist))
                //    //            fieldlist = "[" + column.ColumnName + "]";
                //    //        else
                //    //        {
                //    //            fieldlist += ", [" + column.ColumnName + "]";
                //    //        }
                //    //        if (string.IsNullOrEmpty(valuelist))
                //    //            valuelist = "'" + row[column].ToString() + "'";
                //    //        else
                //    //        {
                //    //            valuelist += ", '" + row[column].ToString() + "'";
                //    //        }
                //    //    }

                //    //    DbCommand command = CreateCommand("INSERT INTO [" + tableName + "] (" + fieldlist + ") VALUES (" + valuelist + ")");
                //    //    command.ExecuteNonQuery();
                //    //}
                //    //objDA.InsertCommand = (OleDbCommand) CreateCommand("INSERT INTO [" + tableName + "] (" + fieldlist + ") VALUES (" + valuelist + ")");
                //    //foreach (DataColumn column in ds.Tables[tableName].Columns)
                //    //{

                //    //    objCB.GetInsertCommand().Parameters.Add("@" + column.ColumnName, OleDbType.VarWChar).SourceColumn = column.ColumnName;
                //    //}
                //    objDA.Update(ds, tableName);
                //}
            }
            else
            {
                foreach (DataTable dataTable in ds.Tables)
                {
                    foreach (DataColumn col in dataTable.Columns)
                    {
                        if (col.DataType.Equals(typeof(DateTime)))
                        {
                            foreach (DataRow row in dataTable.Rows)
                            {
                                if (!row.IsNull(col))
                                {
                                    if (((DateTime)row[col]).Ticks.Equals(0))
                                    {
                                        row[col] = DBNull.Value;
                                    }
                                }
                            }
                        }
                    }
                    DataSet tempDS    = new DataSet();
                    string  tableName = dataTable.TableName;

                    CreateWorkSheet(dataTable);



                    //OleDbDataAdapter objDA = (OleDbDataAdapter)objDBFactory.CreateDataAdapter();
                    //objDA.SelectCommand = (OleDbCommand)CreateCommand("select * from [" + tableName + "]");
                    //objDA.Fill(tempDS, tableName);
                    //OleDbCommandBuilder objCB = (OleDbCommandBuilder)objDBFactory.CreateCommandBuilder();
                    //objCB.QuotePrefix = "[";
                    //objCB.QuoteSuffix = "]";
                    //objCB.DataAdapter = objDA;
                    //string fieldlist = string.Empty;
                    //string valuelist = string.Empty;
                    //objDA.Update(ds, tableName);
                }
                System.IO.FileStream file = new System.IO.FileStream(ExcelFilePath, System.IO.FileMode.Create);
                workbook.Write(file);
                file.Close();
            }
        }
Exemplo n.º 10
0
        ///    <summary>
        ///       This method uses to add data to PRO_ComponentScrapDetail
        ///    </summary>
        ///    <Inputs>
        ///        PRO_ComponentScrapDetailVO
        ///    </Inputs>
        ///    <Returns>
        ///       void
        ///    </Returns>
        ///    <History>
        ///       Tuesday, June 07, 2005
        ///    </History>

        public void UpdateDataSet(DataSet pData)
        {
            const string        METHOD_NAME = THIS + ".UpdateDataSet()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + PRO_ComponentScrapDetailTable.COMPONENTSCRAPDETAILID_FLD + ","
                         + PRO_ComponentScrapDetailTable.FROMLOCATIONID_FLD + ","
                         + PRO_ComponentScrapDetailTable.FROMBINID_FLD + ","
                         + PRO_ComponentScrapDetailTable.TOBINID_FLD + ","
                         + PRO_ComponentScrapDetailTable.TOLOCATIONID_FLD + ","
                         + PRO_ComponentScrapDetailTable.SCRAPQUANTITY_FLD + ","
                         + PRO_ComponentScrapDetailTable.COMPONENTSCRAPMASTERID_FLD + ","
                         + PRO_ComponentScrapDetailTable.WORKORDERMASTERID_FLD + ","
                         + PRO_ComponentScrapDetailTable.WORKORDERDETAILID_FLD + ","
                         + PRO_ComponentScrapDetailTable.COMPONENTID_FLD + ","
                         + PRO_ComponentScrapDetailTable.PRODUCTID_FLD + ","
                         + PRO_ComponentScrapDetailTable.LINE_FLD + ","
                         + PRO_ComponentScrapDetailTable.AVAILABLEQUANTITY_FLD + ","
                         + PRO_ComponentScrapDetailTable.SCRAPREASONID_FLD
                         + "  FROM " + PRO_ComponentScrapDetailTable.TABLE_NAME;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                pData.EnforceConstraints = false;
                odadPCS.Update(pData, PRO_ComponentScrapDetailTable.TABLE_NAME);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                }
                else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                }

                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }

            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 11
0
        ///    <summary>
        ///       This method uses to add data to IV_Adjustment
        ///    </summary>
        ///    <Inputs>
        ///        IV_AdjustmentVO
        ///    </Inputs>
        ///    <Returns>
        ///       void
        ///    </Returns>
        ///    <History>
        ///       Thursday, June 23, 2005
        ///    </History>
        public void UpdateDataSet(DataSet pdstData)
        {
            const string        METHOD_NAME = THIS + ".UpdateDataSet()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + IV_AdjustmentTable.POSTDATE_FLD + ","
                         + IV_AdjustmentTable.COMMENT_FLD + ","
                         + IV_AdjustmentTable.PRODUCTID_FLD + ","
                         + IV_AdjustmentTable.STOCKUMID_FLD + ","
                         + IV_AdjustmentTable.CCNID_FLD + ","
                         + IV_AdjustmentTable.LOCATIONID_FLD + ","
                         + IV_AdjustmentTable.BINID_FLD + ","
                         + IV_AdjustmentTable.MASTERLOCATIONID_FLD + ","
                         + IV_AdjustmentTable.ADJUSTQUANTITY_FLD + ","
                         + IV_AdjustmentTable.AVAILABLEQTY_FLD + ","
                         + IV_AdjustmentTable.USEDBYCOSTING_FLD + ","
                         + IV_AdjustmentTable.USERNAME_FLD + ","
                         + IV_AdjustmentTable.TRANSNO_FLD
                         + "  FROM " + IV_AdjustmentTable.TABLE_NAME;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                pdstData.EnforceConstraints = false;
                odadPCS.Update(pdstData, IV_AdjustmentTable.TABLE_NAME);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                }
                else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                }

                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }

            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void UpdateDB1()
        {
            OleDbCommandBuilder comandbuilder = new OleDbCommandBuilder(adRKC);

            adRKC.Update(DGРКЦTable);
        }
Exemplo n.º 13
0
        public static void CreateExcel(System.Data.DataTable dt, List <ObjectItem <string, Type, int> > listColumns, string fileName = null, string idColumn = null)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
            }

            if (!string.IsNullOrEmpty(fileName))
            {
                string extName    = Path.GetExtension(fileName);
                string connString = string.Empty;
                if (extName.Equals(".xlsx"))
                {
                    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0 XML;Data Source=" + fileName + ";";
                }
                else
                {
                    connString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + fileName + ";";
                }
                OleDbConnection conn = new OleDbConnection(connString);
                try
                {
                    conn.Open();
                    int col = dt.Columns.Count;
                    if (col > 3)
                    {
                        if (!String.IsNullOrWhiteSpace(idColumn))
                        {
                            var rr = dt.Select(idColumn + " IS NULL");
                            foreach (DataRow r in rr)
                            {
                                dt.Rows.Remove(r);
                            }
                        }
                        string           tabName = "Test";
                        List <string>    list1   = new List <string>();
                        List <string>    list2   = new List <string>();
                        List <string>    list3   = new List <string>();
                        OleDbDataAdapter ada     = new OleDbDataAdapter();
                        OleDbCommand     cmd     = new OleDbCommand();
                        cmd.Connection    = conn;
                        ada.InsertCommand = cmd;
                        foreach (var oi in listColumns)
                        {
                            string colName = oi.Id;
                            if (dt.Columns.Contains(colName))
                            {
                                if (!cmd.Parameters.Contains("@" + colName))
                                {
                                    OleDbType odType  = GetOleDbType((oi.Name));
                                    String    typeStr = odType.ToString();
                                    list1.Add("[" + colName + "]");
                                    list2.Add("@" + colName);
                                    list3.Add("[" + colName + "] " + GetOleDbTypeString(oi.Name, oi.Tag));
                                    cmd.Parameters.Add("@" + colName, GetOleDbType(oi.Name), oi.Tag, colName);
                                }
                            }
                        }

                        cmd.CommandText = string.Format("CREATE TABLE [{0}]({1})", tabName, string.Join(",", list3.ToArray()));
                        cmd.ExecuteNonQuery();

                        cmd.CommandText      = string.Format("INSERT INTO [{0}] ({1}) VALUES({2})", tabName, string.Join(",", list1.ToArray()), string.Join(",", list2.ToArray()));
                        cmd.UpdatedRowSource = UpdateRowSource.None;
                        int count = ada.Update(dt);
                        if (count > 0)
                        {
                            log.WriteLine("成功");
                        }
                        else
                        {
                            log.WriteLine("失败");
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.WriteLine(ex.Message);
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 14
0
        public override bool UpdateDataTable(string SQLCmd, DataTable NewChangeDT)
        {
            bool result = false;

            if (conn == null)
            {
                conn.Open();
            }
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            OleDbTransaction tr;

            tr = conn.BeginTransaction(IsolationLevel.RepeatableRead);

            try
            {
                OleDbCommand        cm   = new OleDbCommand(SQLCmd, conn);
                OleDbDataAdapter    da   = new OleDbDataAdapter(cm);
                OleDbCommandBuilder cb   = new OleDbCommandBuilder(da);
                DataTable           mydt = new DataTable();
                da.SelectCommand.Transaction = tr;


                da.Update(NewChangeDT);
                tr.Commit();

                result = true;

                return(result);
            }
            catch (Exception ex)
            {
                try
                {
                    MessageBox.Show(ex.ToString());
                    tr.Rollback();
                    if (conn.State.ToString().ToUpper() == "OPEN")
                    {
                        conn.Close();
                    }
                    return(result);
                }
                catch (System.Exception TransactionEx)
                {
                    //Handle Exception
                    MessageBox.Show(TransactionEx.ToString());
                    if (conn.State.ToString().ToUpper() == "OPEN")
                    {
                        conn.Close();
                    }
                    return(result);
                }
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Exemplo n.º 15
0
        public void Save()
        {
            File.Copy(Application.StartupPath + @"\system\System.mdb", Application.StartupPath + @"\system\System.mdb.bak", true);

            string     dstrSQL;
            DataTable  dDT;
            int        dintIndex    = 0;
            int        dintEOV      = 0;
            bool       dbolError    = false;
            SortedList dHT          = new SortedList();
            string     dstrAfterEOV = "";


            try
            {
                //유효성검사
                for (int dintLoop = 0; dintLoop < this.dataGridView1.RowCount; dintLoop++)
                {
                    dintIndex = Convert.ToInt32(this.dataGridView1.Rows[dintLoop].Cells[0].Value);
                    dintEOV   = Convert.ToInt32(this.dataGridView1.Rows[dintLoop].Cells[5].Value);

                    if (dintEOV >= this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOVMin&& dintEOV <= this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOVMax)
                    {
                        if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOID == 8)          //EOID=8이면 VCR Reading Mode임.
                        {
                            if (dintEOV == 0 || dintEOV == 1 || dintEOV == 2 || dintEOV == 3) //VCR Reading Mode는 0,1,2,3 만 값이 있다.
                            {
                            }
                            else
                            {
                                dbolError = true;
                            }
                        }

                        if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOID == 19) //SEM
                        {
                            if (dintEOV == 1)
                            {
                                //pInfo.All.SEM_ON = true;
                                //if (pInfo.All.CommPort.ToUpper() != "NULL") pInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.SerialPortOpen);

                                this.pInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.UDPPortOpen);
                                //SEM Controller에 Start명령을 내린다.
                                this.pInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.SEMControllerStart);
                            }
                            else
                            {
                                //pInfo.All.SEM_ON = false;
                                this.pInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.SEMControllerEnd);

                                this.pInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.UDPPortClose);
                            }
                        }

                        if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOID == 21) //APC
                        {
                            if (dintEOV == 0 || dintEOV == 1)
                            {
                                if (dintEOV == 0)
                                {
                                    pInfo.All.APCUSE = false;
                                }
                                else
                                {
                                    pInfo.All.APCUSE = true;
                                }
                            }
                            else
                            {
                                dbolError = true;
                            }
                        }

                        if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOID == 22) //RPC
                        {
                            if (dintEOV == 0 || dintEOV == 1)
                            {
                                if (dintEOV == 0)
                                {
                                    pInfo.All.RPCUSE = false;
                                }
                                else
                                {
                                    pInfo.All.RPCUSE = true;
                                }
                            }
                            else
                            {
                                dbolError = true;
                            }
                        }
                    }
                    else
                    {
                        dbolError = true;
                    }

                    if (dbolError == true)
                    {
                        dstrErrorMsg = this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).DESC + " 값은 " + this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOVMin
                                       + "~" + this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOVMax + " 이어야 합니다.";
                        MessageBox.Show(dstrErrorMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                //바뀐 EOV 값이 있는지 검사한다.
                for (int dintLoop = 0; dintLoop < this.dataGridView1.RowCount; dintLoop++)
                {
                    //dintIndex = dintLoop + 1;
                    dintIndex = Convert.ToInt32(this.dataGridView1.Rows[dintLoop].Cells[0].Value);
                    dintEOV   = Convert.ToInt32(this.dataGridView1.Rows[dintLoop].Cells[5].Value);
                    if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV != dintEOV)
                    {
                        dstrAfterEOV = dstrAfterEOV + dintIndex.ToString() + ";";              //EOID 저장
                        dHT.Add(dintIndex, this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV); //변경전의 EOID, EOV 저장

                        //if (this.PInfo.funGetEOIDLapseTime(dintIndex) == true) dbolProcessTimeOverChange = true;
                    }
                }

                if (dstrAfterEOV == "")
                {
                    MessageBox.Show("변경된 EOV가 하나도 없습니다.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!DBAct.clsDBAct.funBeginTransaction())
                {
                    MessageBox.Show("DB Transaction NG!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                //DataAdapter 생성
                OleDbDataAdapter    dataAdapter    = new OleDbDataAdapter("SELECT * FROM tbEOID order by Index", DBAct.clsDBAct.funOleDbConnect());
                OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(dataAdapter);

                //DataAdapter를 이용하여 DB로 업데이트를 한다.
                dataAdapter.SelectCommand.Transaction = DBAct.clsDBAct.funOleDbTransaction();
                dataAdapter.Update((DataTable)pEOIDListSource.DataSource);

                if (!DBAct.clsDBAct.funCommitTransaction())
                {
                    MessageBox.Show("DB Commit Transaction NG!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    DBAct.clsDBAct.funRollbackTransaction();
                    return;
                }



                dstrSQL = "SELECT * FROM tbEOID order by index";
                //dDT = DBAct.clsDBAct.funSelectQuery2(dstrSQL);                          //DataTable을 받아온다.
                dDT = DBAct.clsDBAct.funSelectQuery2(dstrSQL);
                if (dDT != null)
                {
                    pInfo.Unit(0).SubUnit(0).RemoveEOID();

                    pInfo.DeleteTable("EOID");
                    pInfo.AddDataTable("EOID", dDT);

                    foreach (DataRow dr in dDT.Rows)
                    {
                        dintIndex = Convert.ToInt32(dr["Index"]);
                        pInfo.Unit(0).SubUnit(0).AddEOID(dintIndex);

                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOID     = Convert.ToInt32(dr["EOID"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOMD     = Convert.ToInt32(dr["EOMD"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOMDMin  = Convert.ToInt32(dr["EOMDMin"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOMDMax  = Convert.ToInt32(dr["EOMDMax"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV      = Convert.ToInt32(dr["EOV"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOVMin   = Convert.ToInt32(dr["EOVMin"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOVMax   = Convert.ToInt32(dr["EOVMax"]);
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).DESC     = dr["Description"].ToString();
                        pInfo.Unit(0).SubUnit(0).EOID(dintIndex).PLCWrite = Convert.ToBoolean(dr["PLCWrite"]);
                    }
                }
                string[] dstrData = dstrAfterEOV.Split(new char[] { ';' });
                if (dstrData.Length > 1)
                {
                    this.pInfo.All.EOIDChangeBYWHO = "2";       //BY OP

                    //HOST로 EOV값 변경 보고
                    this.pInfo.subSendSF_Set(InfoAct.clsInfo.SFName.S6F11RelatedEquipmentParameterEvent, 101, dstrAfterEOV); //마지막 인자는 EOID Index임

                    this.pInfo.All.EOIDChangeBYWHO = "";                                                                     //초기화

                    //변경 이력 로그 저장
                    foreach (DictionaryEntry de in dHT)
                    {
                        dintIndex = Convert.ToInt32(de.Key);        //EOID Index

                        string dstrLog = "";
                        dstrLog = dstrLog + "EOID" + ",";
                        dstrLog = dstrLog + DateTime.Now.ToString("yyyyMMddHHmmss") + ",";
                        dstrLog = dstrLog + "변경" + ",";
                        dstrLog = dstrLog + this.pInfo.All.UserID + ",";
                        dstrLog = dstrLog + this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).DESC + ",";
                        dstrLog = dstrLog + de.Value.ToString() + ",";
                        dstrLog = dstrLog + this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV;

                        this.pInfo.subLog_Set(InfoAct.clsInfo.LogType.Parameter, dstrLog); //로그 출력

                        dstrLog = "";                                                      //초기화


                        //만약 EOID중에 PLC로 변경할 것이 있으면 Write해 준다.
                        if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).PLCWrite == true)
                        {
                            switch (dintIndex)
                            {
                            //case 8:                       //VCR Reading Mode
                            //    this.PInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.VCRReadingMode, this.PInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV);
                            //    break;

                            case 1:                           //APC(Advanced Process Control) MODE
                                this.pInfo.subPLCCommand_Set(InfoAct.clsInfo.PLCCommand.APCMode, this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV);
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            switch (dintIndex)
                            {
                            case 2:                           //MCC Reporting Mode

                                if (this.pInfo.Unit(0).SubUnit(0).EOID(dintIndex).EOV == 1)
                                {
                                    FunINIMethod.funINIReadValue("MCC", "MCCFileUploadUse", "True", this.pInfo.All.SystemINIFilePath);
                                }
                                else
                                {
                                    FunINIMethod.funINIReadValue("MCC", "MCCFileUploadUse", "False", this.pInfo.All.SystemINIFilePath);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }

                subSaveLastModified(); //최종 수정된 날짜를 Ini파일에 저장한다.

                MessageBox.Show("Data Save Success!", "Jobs Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                pInfo.subLog_Set(InfoAct.clsInfo.LogType.CIM, ex.ToString());
                DBAct.clsDBAct.funRollbackTransaction();
                DBAct.clsDBAct.funDisconnect();     // DB 연결을 끊는다.
                MessageBox.Show("DB Update Fail, Because DB Process Error!", "DB Update Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 16
0
        ///    <summary>
        ///       This method uses to add data to MTR_MRPCycleOptionDetail
        ///    </summary>
        ///    <Inputs>
        ///        MTR_MRPCycleOptionDetailVO
        ///    </Inputs>
        ///    <Returns>
        ///       void
        ///    </Returns>
        ///    <History>
        ///       Thursday, July 21, 2005
        ///    </History>

        public void UpdateDataSet(DataSet pdstData)
        {
            const string        METHOD_NAME = THIS + ".UpdateDataSet()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + MTR_MRPCycleOptionDetailTable.MRPCYCLEOPTIONDETAILID_FLD + ","
                         + MTR_MRPCycleOptionDetailTable.ONHAND_FLD + ","
                         + MTR_MRPCycleOptionDetailTable.PURCHASEORDER_FLD + ","
                         + MTR_MRPCycleOptionDetailTable.SALEORDER_FLD + ","
                         + MTR_MRPCycleOptionDetailTable.DEMANDWO_FLD + ","
                         + MTR_MRPCycleOptionDetailTable.MRPCYCLEOPTIONMASTERID_FLD + ","
                         + MTR_MRPCycleOptionDetailTable.MASTERLOCATIONID_FLD
                         + " FROM " + MTR_MRPCycleOptionDetailTable.TABLE_NAME;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                pdstData.EnforceConstraints = false;
                odadPCS.Update(pdstData, MTR_MRPCycleOptionDetailTable.TABLE_NAME);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                }
                else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                }

                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }

            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 17
0
        //审核功能
        public override void CheckResult()
        {
            //保存
            bool isSaved = Save();

            if (isSaved == false)
            {
                return;
            }

            base.CheckResult();

            dt记录.Rows[0]["审核人"]    = mySystem.Parameter.userName;
            dt记录.Rows[0]["审核意见"]   = checkform.opinion;
            dt记录.Rows[0]["审核是否通过"] = checkform.ischeckOk;

            //写待审核表
            DataTable dt_temp = new DataTable("待审核");

            //BindingSource bs_temp = new BindingSource();
            if (!mySystem.Parameter.isSqlOk)
            {
                OleDbDataAdapter    da_temp = new OleDbDataAdapter("select * from 待审核 where 表名='清洁分切运行记录' and 对应ID=" + dt记录.Rows[0]["ID"], mySystem.Parameter.connOle);
                OleDbCommandBuilder cb_temp = new OleDbCommandBuilder(da_temp);
                da_temp.Fill(dt_temp);
                dt_temp.Rows[0].Delete();
                da_temp.Update(dt_temp);
            }
            else
            {
                SqlDataAdapter    da_temp = new SqlDataAdapter("select * from 待审核 where 表名='清洁分切运行记录' and 对应ID=" + dt记录.Rows[0]["ID"], mySystem.Parameter.conn);
                SqlCommandBuilder cb_temp = new SqlCommandBuilder(da_temp);
                da_temp.Fill(dt_temp);
                dt_temp.Rows[0].Delete();
                da_temp.Update(dt_temp);
            }



            //写日志
            string log = "=====================================\n";

            log += DateTime.Now.ToString("yyyy年MM月dd日 hh时mm分ss秒") + "\n" + label角色.Text + ":" + mySystem.Parameter.userName + " 完成审核\n";
            log += "审核结果:" + (checkform.ischeckOk == true ? "通过\n" : "不通过\n");
            log += "审核意见:" + checkform.opinion + "\n";
            dt记录.Rows[0]["日志"] = dt记录.Rows[0]["日志"].ToString() + log;

            Save();

            //修改状态,设置可控性
            if (checkform.ischeckOk)
            {
                _formState = Parameter.FormState.审核通过;
            }                                         //审核通过
            else
            {
                _formState = Parameter.FormState.审核未通过;
            }                                          //审核未通过
            setEnableReadOnly();
            setDataGridViewFormat();
        }
Exemplo n.º 18
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to update a DataSet
        ///    </Description>
        ///    <Inputs>
        ///        DataSet
        ///    </Inputs>
        ///    <Outputs>
        ///
        ///    </Outputs>
        ///    <Returns>
        ///
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///    </Authors>
        ///    <History>
        ///       Thursday, September 29, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************

        public void UpdateDataSet(DataSet pData)
        {
            const string        METHOD_NAME = THIS + ".UpdateDataSet()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + PO_InvoiceDetailTable.INVOICEDETAILID_FLD + ","
                         + PO_InvoiceDetailTable.INVOICELINE_FLD + ","
                         + PO_InvoiceDetailTable.INVOICEMASTERID_FLD + ","
                         + PO_InvoiceDetailTable.INVOICEQUANTITY_FLD + ","
                         + PO_InvoiceDetailTable.UNITPRICE_FLD + ","
                         + PO_InvoiceDetailTable.VAT_FLD + ","
                         + PO_InvoiceDetailTable.VATAMOUNT_FLD + ","
                         + PO_InvoiceDetailTable.IMPORTTAX_FLD + ","
                         + PO_InvoiceDetailTable.IMPORTTAXAMOUNT_FLD + ","
                         + PO_InvoiceDetailTable.INLAND_FLD + ","
                         + PO_InvoiceDetailTable.BEFOREVATAMOUNT_FLD + ","
                         + PO_InvoiceDetailTable.CIFAMOUNT_FLD + ","
                         + PO_InvoiceDetailTable.CIPAMOUNT_FLD + ","
                         + PO_InvoiceDetailTable.NOTE_FLD + ","
                         + PO_InvoiceDetailTable.PRODUCTID_FLD + ","
                         + PO_InvoiceDetailTable.PURCHASEORDERMASTERID_FLD + ","
                         + PO_InvoiceDetailTable.PURCHASEORDERDETAILID_FLD + ","
                         + PO_InvoiceDetailTable.DELIVERYSCHEDULEID_FLD + ","
                         + PO_InvoiceDetailTable.INVOICEUMID_FLD
                         + "  FROM " + PO_InvoiceDetailTable.TABLE_NAME;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                pData.EnforceConstraints = false;
                odadPCS.Update(pData, PO_InvoiceDetailTable.TABLE_NAME);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                }
                else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                }

                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }

            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 19
0
        public bool AddByGroup(DataTable dt1)
        {
            using (OleDbConnection connection = new OleDbConnection(DbHelperOleDb.connectionString))
            {
                try
                {
                    OleDbCommand cmd2 = new OleDbCommand("insert into OrderInfo(OrderNo,Daterecived,SalesmanID,CustomerID,Tel,Provice,City,Area,Address,Reciver,Remark,Contractor,Contractdate,OState,Merchandiser,UserDate,OperUser,ORState,Paream0,Paream1,Paream2,Paream3,Paream4,Paream5,Paream6,Paream7,Paream8) values (@OrderNo,@Daterecived,@SalesmanID,@CustomerID,@Tel,@Provice,@City,@Area,@Address,@Reciver,@Remark,@Contractor,@Contractdate,@OState,@Merchandiser,@UserDate,@OperUser,@ORState,@Paream0,@Paream1,@Paream2,@Paream3,@Paream4,@Paream5,@Paream6,@Paream7,@Paream8)");

                    OleDbDataAdapter adapt = new OleDbDataAdapter("select * from OrderInfo", connection);

                    OleDbCommandBuilder OleDbCmdBud = new OleDbCommandBuilder(adapt);

                    OleDbParameter[] parameters =
                    {
                        new OleDbParameter("@OrderNo",      OleDbType.VarChar,  30),
                        new OleDbParameter("@Daterecived",  OleDbType.Date),
                        new OleDbParameter("@SalesmanID",   OleDbType.Integer,   4),
                        new OleDbParameter("@CustomerID",   OleDbType.Integer,   4),
                        new OleDbParameter("@Tel",          OleDbType.VarChar,  30),
                        new OleDbParameter("@Provice",      OleDbType.VarChar,  30),
                        new OleDbParameter("@City",         OleDbType.VarChar,  30),
                        new OleDbParameter("@Area",         OleDbType.VarChar,  30),
                        new OleDbParameter("@Address",      OleDbType.VarChar, 200),
                        new OleDbParameter("@Reciver",      OleDbType.VarChar,  10),
                        new OleDbParameter("@Remark",       OleDbType.VarChar, 100),
                        new OleDbParameter("@Contractor",   OleDbType.VarChar,  20),
                        new OleDbParameter("@Contractdate", OleDbType.Date),
                        new OleDbParameter("@OState",       OleDbType.Integer,   4),
                        new OleDbParameter("@Merchandiser", OleDbType.Integer,   4),
                        new OleDbParameter("@UserDate",     OleDbType.Date),
                        new OleDbParameter("@OperUser",     OleDbType.VarChar,  20),
                        new OleDbParameter("@ORState",      OleDbType.Integer,   4),
                        new OleDbParameter("@Paream0",      OleDbType.VarChar, 255),
                        new OleDbParameter("@Paream1",      OleDbType.VarChar, 255),
                        new OleDbParameter("@Paream2",      OleDbType.VarChar, 255),
                        new OleDbParameter("@Paream3",      OleDbType.VarChar, 255),
                        new OleDbParameter("@Paream4",      OleDbType.VarChar, 255),
                        new OleDbParameter("@Paream5",      OleDbType.Integer,   4),
                        new OleDbParameter("@Paream6",      OleDbType.Integer,   4),
                        new OleDbParameter("@Paream7",      OleDbType.Integer,   4),
                        new OleDbParameter("@Paream8",      OleDbType.Integer, 4)
                    };

                    adapt.Fill(dt1);
                    adapt.SelectCommand.Parameters.AddRange(parameters);


                    adapt.SelectCommand.Parameters["@OrderNo"].SourceColumn      = "OrderNo";
                    adapt.SelectCommand.Parameters["@Daterecived"].SourceColumn  = "Daterecived";
                    adapt.SelectCommand.Parameters["@SalesmanID"].SourceColumn   = "SalesmanID";
                    adapt.SelectCommand.Parameters["@CustomerID"].SourceColumn   = "CustomerID";
                    adapt.SelectCommand.Parameters["@Tel"].SourceColumn          = "Tel";
                    adapt.SelectCommand.Parameters["@Provice"].SourceColumn      = "Provice";
                    adapt.SelectCommand.Parameters["@City"].SourceColumn         = "City";
                    adapt.SelectCommand.Parameters["@Area"].SourceColumn         = "Area";
                    adapt.SelectCommand.Parameters["@Address"].SourceColumn      = "Address";
                    adapt.SelectCommand.Parameters["@Reciver"].SourceColumn      = "Reciver";
                    adapt.SelectCommand.Parameters["@Remark"].SourceColumn       = "Remark";
                    adapt.SelectCommand.Parameters["@Contractdate"].SourceColumn = "Contractdate";
                    adapt.SelectCommand.Parameters["@OState"].SourceColumn       = "OState";
                    adapt.SelectCommand.Parameters["@Merchandiser"].SourceColumn = "Merchandiser";
                    adapt.SelectCommand.Parameters["@UserDate"].SourceColumn     = "UserDate";
                    adapt.SelectCommand.Parameters["@OperUser"].SourceColumn     = "OperUser";

                    adapt.SelectCommand.Parameters["@ORState"].SourceColumn = "ORState";
                    adapt.SelectCommand.Parameters["@Paream0"].SourceColumn = "Paream0";
                    adapt.SelectCommand.Parameters["@Paream1"].SourceColumn = "Paream1";
                    adapt.SelectCommand.Parameters["@Paream2"].SourceColumn = "Paream2";
                    adapt.SelectCommand.Parameters["@Paream3"].SourceColumn = "Paream3";
                    adapt.SelectCommand.Parameters["@Paream4"].SourceColumn = "Paream4";
                    adapt.SelectCommand.Parameters["@Paream5"].SourceColumn = "Paream5";
                    adapt.SelectCommand.Parameters["@Paream6"].SourceColumn = "Paream6";
                    adapt.SelectCommand.Parameters["@Paream7"].SourceColumn = "Paream7";
                    adapt.SelectCommand.Parameters["@Paream8"].SourceColumn = "Paream8";

                    adapt.UpdateCommand = OleDbCmdBud.GetUpdateCommand();
                    if (dt1 != null)
                    {
                        adapt.Update(dt1);
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
        }
    // override the 'Create new folder' method
    protected override void ExecAddFolderCommand(string sourceUrl, string name)
    {
        Regex regex = new Regex("^" + DatabaseProtocol, RegexOptions.Compiled);

        if (!regex.IsMatch(sourceUrl)) // it is the 'file system' gallery command
        {
            // call the base method
            base.ExecAddFolderCommand(sourceUrl, name);
            return;
        }
        string url = regex.Replace(sourceUrl, "");

        string temp = url;

        if (temp.Substring(temp.Length - 1, 1) == "/")
        {
            temp = temp.Substring(0, temp.Length - 1);
        }
        if (temp.Substring(0, 1) == "/")
        {
            temp = temp.Substring(1, temp.Length - 1);
        }
        string[] folders  = temp.Split(new char[] { '/' });
        int      parentId = 0;

        OleDbConnection connection = new OleDbConnection();

        try
        {
            connection.ConnectionString = ConnectionString;
            connection.Open();
            for (int i = 0; i < folders.Length; i++)
            {
                string folderName = folders[i];
                // inspect for child folders
                string           sqlString = "Select * from tbFolder Where fldFolderId=" + parentId.ToString();
                OleDbDataAdapter eAdapter  = new OleDbDataAdapter(sqlString, connection);

                DataTable eTable = new DataTable();

                eAdapter.Fill(eTable);
                bool found = false;
                // search for the folder
                for (int j = 0; j < eTable.Rows.Count; j++)
                {
                    DataRow row             = eTable.Rows[j];
                    string  childFolderName = (string)row["fldName"];
                    if (childFolderName == folderName)
                    {
                        parentId = (int)row["id"];
                        found    = true;
                        break;
                    }
                }

                // not found - create it
                if (!found)
                {
                    OleDbCommand cmdInsert = new OleDbCommand("INSERT INTO tbFolder (fldName, fldFolderId) VALUES(?, ?)", connection);

                    cmdInsert.Parameters.Add(new OleDbParameter("fldName", OleDbType.VarChar, 100, "fldName"));
                    cmdInsert.Parameters.Add(new OleDbParameter("fldFolderId", OleDbType.Integer, 0, "fldFolderId"));
                    eAdapter.InsertCommand = cmdInsert;

                    // Create a command to get IDENTITY Value
                    cmdGetIdentity = new OleDbCommand("SELECT @@IDENTITY", connection);

                    eAdapter.RowUpdated += new OleDbRowUpdatedEventHandler(HandleRowUpdated);

                    DataRow newRow = eTable.NewRow();
                    newRow["fldName"]     = folderName;
                    newRow["fldFolderId"] = parentId;
                    eTable.Rows.Add(newRow);
                    eAdapter.Update(eTable);

                    parentId = (int)newRow["id"];

                    // Release the Resources
                    cmdGetIdentity = null;
                    cmdInsert      = null;
                }

                eAdapter.Dispose();
                eTable.Dispose();
            }
        }
        finally
        {
            connection.Close();
            connection.Dispose();
        }
    }
Exemplo n.º 21
0
 private void button2_Click(object sender, EventArgs e)
 {
     dta.Update(dts, "doc");
 }
Exemplo n.º 22
0
 // GENEL OLARAK DEĞİŞİKLİKLERİ KAYDETME
 private void btnKaydet_Click(object sender, EventArgs e)
 {
     adaptor.Update(ds.Tables["Depo"]);
     dataGridDoldur("Select * From Depo ORDER BY UrunID");
     MessageBox.Show("Tüm değişiklikler kaydedildi.", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
Exemplo n.º 23
0
        //**************************************************************************
        ///    <Description>
        ///       This method uses to update a DataSet
        ///    </Description>
        ///    <Inputs>
        ///        DataSet
        ///    </Inputs>
        ///    <Outputs>
        ///
        ///    </Outputs>
        ///    <Returns>
        ///
        ///    </Returns>
        ///    <Authors>
        ///       HungLa
        ///    </Authors>
        ///    <History>
        ///       Tuesday, January 25, 2005
        ///    </History>
        ///    <Notes>
        ///    </Notes>
        //**************************************************************************

        public void UpdateDataSet(DataSet pData)
        {
            const string        METHOD_NAME = THIS + ".UpdateDataSet()";
            string              strSql;
            OleDbConnection     oconPCS = null;
            OleDbCommandBuilder odcbPCS;
            OleDbDataAdapter    odadPCS = new OleDbDataAdapter();

            try
            {
                strSql = "SELECT "
                         + MST_WorkCenterCapacityTable.WORKCENTERCAPACITYID_FLD + ","
                         + MST_WorkCenterCapacityTable.EFFECTIVEBEGINDATE_FLD + ","
                         + MST_WorkCenterCapacityTable.LABORHOURSPERDAY_FLD + ","
                         + MST_WorkCenterCapacityTable.EFFECTIVEENDDATE_FLD + ","
                         + MST_WorkCenterCapacityTable.CREWSIZE_FLD + ","
                         + MST_WorkCenterCapacityTable.LABORSHIFT_FLD + ","
                         + MST_WorkCenterCapacityTable.LABOREFFICIENCYFACTOR_FLD + ","
                         + MST_WorkCenterCapacityTable.MACHINEHOURSPERDAY_FLD + ","
                         + MST_WorkCenterCapacityTable.MACHINEQTY_FLD + ","
                         + MST_WorkCenterCapacityTable.MACHINESHIFT_FLD + ","
                         + MST_WorkCenterCapacityTable.MACHINEEFFICIENCYFACTOR_FLD
                         + "  FROM " + MST_WorkCenterCapacityTable.TABLE_NAME;

                Utils utils = new Utils();
                oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
                odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
                odcbPCS = new OleDbCommandBuilder(odadPCS);
                pData.EnforceConstraints = false;
                odadPCS.Update(pData, MST_WorkCenterCapacityTable.TABLE_NAME);
            }
            catch (OleDbException ex)
            {
                if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
                }
                else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
                {
                    throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
                }

                else
                {
                    throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
                }
            }

            catch (InvalidOperationException ex)
            {
                throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
            }
            catch (Exception ex)
            {
                throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
            }

            finally
            {
                if (oconPCS != null)
                {
                    if (oconPCS.State != ConnectionState.Closed)
                    {
                        oconPCS.Close();
                    }
                }
            }
        }
Exemplo n.º 24
0
        void gravaDados()
        {
            OleDbCommandBuilder cb = new OleDbCommandBuilder(daDocs);

            daDocs.Update(tbDocs);
        }
Exemplo n.º 25
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidateInput())
            {
                try
                {
                    var savedRecord = txtISBN.Text;
                    titlesManager.EndCurrentEdit();
                    builderComm = new OleDbCommandBuilder(titlesAdapter);
                    if (AppState == State.Edit)
                    {
                        var titleRow = titlesTable.Select($"ISBN = '{savedRecord}'");

                        if (string.IsNullOrEmpty(txtYearPublished.Text))
                        {
                            titleRow[0]["Year_Published"] = DBNull.Value;
                        }
                        else
                        {
                            titleRow[0]["Year_Published"] = txtYearPublished.Text;
                        }
                        titlesAdapter.Update(titlesTable);
                        txtYearPublished.DataBindings.Add("Text", titlesTable, "Year_Published");
                    }
                    else if (AppState == State.Add)
                    {
                        titlesAdapter.Update(titlesTable);
                        titlesTable.DefaultView.Sort = "Title";
                        var foundRecord = titlesTable.Select($"ISBN = '{savedRecord}'");
                        titlesManager.Position = titlesTable.DefaultView.Find(foundRecord[0]["Title"]);
                        ISBNAuthorsComm        = new OleDbCommand($"SELECT * FROM Title_Author WHERE ISBN = '{txtISBN.Text}'", booksConn);
                        ISBNAuthorsAdapter     = new OleDbDataAdapter(ISBNAuthorsComm);
                        ISBNAuthorsTable       = new DataTable();
                        ISBNAuthorsAdapter.Fill(ISBNAuthorsTable);
                    }

                    builderComm = new OleDbCommandBuilder(ISBNAuthorsAdapter);
                    if (ISBNAuthorsTable.Rows.Count > 0 && AppState == State.Edit)
                    {
                        for (int i = 0; i < ISBNAuthorsTable.Rows.Count; i++)
                        {
                            ISBNAuthorsTable.Rows[i].Delete();
                        }

                        ISBNAuthorsAdapter.Update(ISBNAuthorsTable);
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        if (authorsCombo[i].SelectedIndex != -1)
                        {
                            ISBNAuthorsTable.Rows.Add();
                            ISBNAuthorsTable.Rows[ISBNAuthorsTable.Rows.Count - 1]["ISBN"]  = txtISBN.Text;
                            ISBNAuthorsTable.Rows[ISBNAuthorsTable.Rows.Count - 1]["AU_ID"] =
                                authorsCombo[i].SelectedValue;
                        }
                    }
                    ISBNAuthorsAdapter.Update(ISBNAuthorsTable);

                    MessageBox.Show("Record is saved successfully", "Saving Record",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SetAppState(State.View);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Record Saving Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 26
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     Anhien(true); btnSua.Enabled = true; btnXoa.Enabled = false; txtMaSo.Enabled = false;
     BindingContext[ds, "diem"].EndCurrentEdit();
     da.Update(ds, "diem");
 }
        /// <summary>
        /// Establece una relación entre algún concepto y el término que se quiere asociar como sinónimo
        /// </summary>
        /// <param name="sinonimo">Término con significado similar </param>
        /// <param name="idConcepto">Concepto al que irá ligado el sinónimo</param>
        public void SetNewSinonimo(Sinonimos sinonimo, int idConcepto)
        {
            OleDbConnection  connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["Diccionario"].ToString());
            OleDbDataAdapter dataAdapter;

            DataSet dataSet = new DataSet();
            DataRow dr;

            try
            {
                sinonimo.IdSinonimo = DataBaseUtilities.GetNextIdForUse("Sinonimos", "IdSinonimo", connection);

                string sqlCadena = "SELECT * FROM Sinonimos WHERE IdSinonimo = 0";

                dataAdapter = new OleDbDataAdapter();
                dataAdapter.SelectCommand = new OleDbCommand(sqlCadena, connection);

                dataAdapter.Fill(dataSet, "Sinonimos");

                dr = dataSet.Tables["Sinonimos"].NewRow();
                dr["IdSinonimo"]   = sinonimo.IdSinonimo;
                dr["Sinonimo"]     = sinonimo.Sinonimo;
                dr["SinonimoStr"]  = sinonimo.SinonimoStr;
                dr["Fuente"]       = sinonimo.Fuente;
                dr["FuenteStr"]    = sinonimo.FuenteStr;
                dr["FechaAlta"]    = DateTime.Now;
                dr["FechaAltaInt"] = DateTimeUtilities.DateToInt(DateTime.Now);

                dataSet.Tables["Sinonimos"].Rows.Add(dr);

                dataAdapter.InsertCommand = connection.CreateCommand();

                dataAdapter.InsertCommand.CommandText = "INSERT INTO Sinonimos VALUES (@IdSinonimo,@Sinonimo,@SinonimoStr,@Fuente,@FuenteStr,@FechaAlta,@FechaAltaInt)";
                dataAdapter.InsertCommand.Parameters.Add("@IdSinonimo", OleDbType.Numeric, 0, "IdSinonimo");
                dataAdapter.InsertCommand.Parameters.Add("@Sinonimo", OleDbType.VarChar, 0, "Sinonimo");
                dataAdapter.InsertCommand.Parameters.Add("@SinonimoStr", OleDbType.VarChar, 0, "SinonimoStr");
                dataAdapter.InsertCommand.Parameters.Add("@Fuente", OleDbType.VarChar, 0, "Fuente");
                dataAdapter.InsertCommand.Parameters.Add("@FuenteStr", OleDbType.VarChar, 0, "FuenteStr");
                dataAdapter.InsertCommand.Parameters.Add("@FechaAlta", OleDbType.Date, 0, "FechaAlta");
                dataAdapter.InsertCommand.Parameters.Add("@FechaAltaInt", OleDbType.Numeric, 0, "FechaAltaInt");

                dataAdapter.Update(dataSet, "Sinonimos");
                dataSet.Dispose();
                dataAdapter.Dispose();

                new RelacionesModel().SetNewRelation(idConcepto, sinonimo.IdSinonimo, 2);
            }
            catch (OleDbException ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

                MessageBox.Show("Error ({0}) : {1}" + ex.Source + ex.Message, methodName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ErrorUtilities.SetNewErrorMessage(ex, methodName, 0);
            }
            catch (Exception ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

                MessageBox.Show("Error ({0}) : {1}" + ex.Source + ex.Message, methodName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ErrorUtilities.SetNewErrorMessage(ex, methodName, 0);
            }
            finally
            {
                connection.Close();
            }
        }
Exemplo n.º 28
0
        private void button8_Click(object sender, EventArgs e)
        {
            for (int v = 0; v < MyData.Tables[0].Rows.Count; v++)
            {
                //     MessageBox.Show("run");
                if (this.a0.Text == MyData.Tables[0].Rows[v][0].ToString())
                {
                    string       SQL   = "delete from e24chdl where a0= '" + this.a0.Text + "'";
                    OleDbCommand MyCom = new OleDbCommand(SQL, MyConn);
                    MyCom.ExecuteNonQuery();
                    MyData.Tables[0].Rows.RemoveAt(v);
                    break;
                }
            }

            panel2.Enabled = true;


            /*
             * word  存储开始
             *
             */
            //代码域

            Thread MySaveS = new Thread(new ThreadStart(save));

            MySaveS.Start();

            /*
             * word存储结束
             */
            /*
             * 数据库存储开始
             */
            DataRow NewRow = MyData.Tables[0].NewRow();

            NewRow["a0"]  = a0.Text;
            NewRow["a1"]  = a1.Text;
            NewRow["a2"]  = a2.Text;
            NewRow["a3"]  = a3.Text;
            NewRow["a4"]  = a4.Text;
            NewRow["a5"]  = a5.Text;
            NewRow["a6"]  = a6.Text;
            NewRow["a7"]  = a7.Text;
            NewRow["a8"]  = a8.Text;
            NewRow["a9"]  = a9.Text;
            NewRow["a10"] = a11.Text;
            NewRow["a11"] = a10.Text;
            NewRow["a15"] = a15.Text;
            NewRow["a13"] = a13.Text;
            NewRow["a14"] = a14.Text;

            // NewRow["a15"] = a15.Text;
            NewRow["a16"]    = a16.Text;
            NewRow["a17"]    = a17.Text;
            NewRow["a18"]    = a18.Text;
            NewRow["a19"]    = a19.Text;
            NewRow["a20"]    = a20.Text;
            NewRow["a21"]    = a21.Text;
            NewRow["time_e"] = main.currentTime.Year.ToString() + "-" + main.currentTime.Month.ToString() + "-" + main.currentTime.Day.ToString();


            MyData.Tables[0].Rows.Add(NewRow);

            MyAd.Update(MyData);



            //MessageBox.Show(a13_1.CheckState);



            /*
             * 数据库的存储结束
             *
             * *
             */



            MessageBox.Show("保存成功!!");


            i = MyData.Tables[0].Rows.Count - 1;
            textBox18.Text = (i + 1).ToString();


            panel1.Enabled = false;

            button6.Enabled  = true;
            button7.Enabled  = true;
            button8.Enabled  = false;
            button9.Enabled  = false;
            button10.Enabled = true;
            button11.Enabled = true;
            button12.Enabled = true;
            button13.Enabled = true;
            button14.Enabled = true;

            button16.Enabled = true;
            button17.Enabled = true;

            OleDbDataAdapter MyAd0   = new OleDbDataAdapter("select count(a0)  from e24chdl ", MyConn);
            DataSet          MyData0 = new DataSet();

            MyAd0.Fill(MyData0);

            this.textBox17.Text = MyData.Tables[0].Rows.Count.ToString();
        }
        /// <summary>
        /// Modifica la estructura original del sinónimo
        /// </summary>
        /// <param name="sinonimo">Sinonimo que se modificará</param>
        public void UpdateSinonimo(Sinonimos sinonimo)
        {
            OleDbConnection connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["Diccionario"].ToString());

            OleDbDataAdapter dataAdapter;

            DataSet dataSet = new DataSet();
            DataRow dr;

            try
            {
                string sqlCadena = "SELECT * FROM Sinonimos WHERE IdSinonimo = @IdSinonimo";

                dataAdapter = new OleDbDataAdapter();
                dataAdapter.SelectCommand = new OleDbCommand(sqlCadena, connection);
                dataAdapter.SelectCommand.Parameters.AddWithValue("@IdSinonimo", sinonimo.IdSinonimo);
                dataAdapter.Fill(dataSet, "Sinonimos");

                dr = dataSet.Tables["Sinonimos"].Rows[0];
                dr.BeginEdit();
                dr["Sinonimo"]    = sinonimo.Sinonimo;
                dr["SinonimoStr"] = sinonimo.SinonimoStr;
                dr["Fuente"]      = sinonimo.Fuente;
                dr["FuenteStr"]   = sinonimo.FuenteStr;
                dr.EndEdit();



                dataAdapter.UpdateCommand = connection.CreateCommand();

                dataAdapter.UpdateCommand.CommandText = "UPDATE Sinonimos SET Sinonimo = @Sinonimo, SinonimoStr = @SinonimoStr, " +
                                                        " Fuente = @Fuente, FuenteStr = @FuenteStr WHERE IdSinonimo = @IdSinonimo";
                dataAdapter.UpdateCommand.Parameters.Add("@Sinonimo", OleDbType.VarChar, 0, "Sinonimo");
                dataAdapter.UpdateCommand.Parameters.Add("@SinonimoStr", OleDbType.VarChar, 0, "SinonimoStr");
                dataAdapter.UpdateCommand.Parameters.Add("@Fuente", OleDbType.VarChar, 0, "Fuente");
                dataAdapter.UpdateCommand.Parameters.Add("@FuenteStr", OleDbType.VarChar, 0, "FuenteStr");
                dataAdapter.UpdateCommand.Parameters.Add("@IdSinonimo", OleDbType.Numeric, 0, "IdSinonimo");

                dataAdapter.Update(dataSet, "Sinonimos");
                dataSet.Dispose();
                dataAdapter.Dispose();
            }
            catch (OleDbException ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

                MessageBox.Show("Error ({0}) : {1}" + ex.Source + ex.Message, methodName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ErrorUtilities.SetNewErrorMessage(ex, methodName, 0);
            }
            catch (Exception ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

                MessageBox.Show("Error ({0}) : {1}" + ex.Source + ex.Message, methodName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ErrorUtilities.SetNewErrorMessage(ex, methodName, 0);
            }
            finally
            {
                connection.Close();
            }
        }
Exemplo n.º 30
0
        public void InsertaTemasIusScjn(List <TesisDTO> listaTesis, BackgroundWorker worker)
        {
            OleDbConnection  connection = Conexion.GetAccessDataBaseConnection(idProducto);
            OleDbDataAdapter dataAdapter;

            DataSet dataSet = new DataSet();
            DataRow dr;

            int    currentProgress = 1;
            string sqlCadena       = "SELECT * FROM Tesis WHERE IUS4 = 0";

            try
            {
                connection.Open();

                dataAdapter = new OleDbDataAdapter();
                dataAdapter.SelectCommand = new OleDbCommand(sqlCadena, connection);

                dataAdapter.Fill(dataSet, "Tesis");

                int consec = 1;

                foreach (TesisDTO tesis in listaTesis)
                {
                    dr               = dataSet.Tables["Tesis"].NewRow();
                    dr["Tipo"]       = tesis.Parte;
                    dr["Consec"]     = consec;
                    dr["IUS4"]       = tesis.Ius;
                    dr["ConsecIndx"] = tesis.Volumen;

                    dataSet.Tables["Tesis"].Rows.Add(dr);

                    dataAdapter.InsertCommand             = connection.CreateCommand();
                    dataAdapter.InsertCommand.CommandText = "INSERT INTO Tesis(TIPO,CONSEC,IUS4,CONSECINDX) VALUES(@TIPO,@CONSEC,@IUS4,@CONSECINDX)";
                    dataAdapter.InsertCommand.Parameters.Add("@TIPO", OleDbType.Numeric, 0, "TIPO");
                    dataAdapter.InsertCommand.Parameters.Add("@CONSEC", OleDbType.Numeric, 0, "CONSEC");
                    dataAdapter.InsertCommand.Parameters.Add("@IUS4", OleDbType.Numeric, 0, "IUS4");
                    dataAdapter.InsertCommand.Parameters.Add("@CONSECINDX", OleDbType.Numeric, 0, "CONSECINDX");

                    dataAdapter.Update(dataSet, "Tesis");

                    dataSet.Dispose();
                    dataAdapter.Dispose();
                    consec++;

                    worker.ReportProgress(currentProgress);
                    currentProgress++;
                }
            }
            catch (OleDbException ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                ErrorUtilities.SetNewErrorMessage(ex, methodName + " Exception,MigradorModel", "ChecaPrecedentes");
            }
            catch (Exception ex)
            {
                string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                ErrorUtilities.SetNewErrorMessage(ex, methodName + " Exception,MigradorModel", "ChecaPrecedentes");
            }
            finally
            {
                connection.Close();
            }
        }
Exemplo n.º 31
0
        public int Update(ViewDataSet.品號ViewDataTable table)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();

            adapter.UpdateCommand = UpdateCommand;
            adapter.InsertCommand = InsertCommand;
            adapter.DeleteCommand = DeleteCommand;

            this.Connection.Open();
            OleDbTransaction trans = this.Connection.BeginTransaction();
            adapter.InsertCommand.Transaction = trans;
            adapter.UpdateCommand.Transaction = trans;
            adapter.DeleteCommand.Transaction = trans;

            try
            {
                int count = 0;
                count = adapter.Update(table);
                trans.Commit();
                return count;
            }
            catch (System.Exception ex)
            {
                trans.Rollback();
                throw ex;
            }
            finally
            {
                this.Connection.Close();
            }
        }