Beispiel #1
0
        public ProDataset(string sqlCommandText)
        {
            DBA = new Dbaccess();

            oleConnStr   = Properties.Settings.Default.ConnStr;;
            oleConn      = new OleDbConnection(oleConnStr);
            ProDatSet    = new DataSet();
            PersonTable  = new DataTable("personTable");
            JobCardTable = new DataTable("jobcardTable");
            CorpTable    = new DataTable("corpTable");
            ProDatSet.Tables.Add(PersonTable);
            ProDatSet.Tables.Add(JobCardTable);
            ProDatSet.Tables.Add(CorpTable);

            string sqlstr = "";

            try
            {
                oleConn.Open();
                sqlstr  = "select * from staffs";
                oleComd = new OleDbCommand(sqlstr, oleConn);
                oleAdap = new OleDbDataAdapter(oleComd);
                oleAdap.Fill(ProDatSet, "personTable");
                //oleAdap.Fill(PersonTable);

                sqlstr  = "select * from projects";
                oleComd = new OleDbCommand(sqlstr, oleConn);
                oleAdap = new OleDbDataAdapter(oleComd);
                oleAdap.Fill(ProDatSet, "jobcardTable");

                sqlstr  = "select * from corps";
                oleComd = new OleDbCommand(sqlstr, oleConn);
                oleAdap = new OleDbDataAdapter(oleComd);
                oleAdap.Fill(ProDatSet, "corpTable");
            }
            catch (Exception ex)
            {
                if (oleConn.State == ConnectionState.Open)
                {
                    oleConn.Close();
                }
                System.Windows.Forms.MessageBox.Show(
                    "Execute fail.\nError code::>> " + ex.Message,
                    "Warning!!!",
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 添加一个记录
        /// </summary>
        private void AppendPerson()
        {
            //检查空值
            if (!IsHaveEmpty())
            {
                return;
            }

            dba = new Dbaccess();
            if (Utility.Optype == OpreatType.add) //添加
            {                                     //检查重复
                person = AssignPersonData(OpreatType.add);
                string sql = "select * from staffs where (wWorkerNum = '" + person.WorkerNum +
                             "') or ((wIdtype = '" + person.Idtype +
                             "') and (wIdNumber = '" + person.IdNumber + "'))";
                DataTable thedt = dba.ReadDatas(sql, false);
                if (thedt.Rows.Count >= 1)
                {
                    MessageBox.Show("This employee data already exists in the database.");
                    return;
                }

                //执行 SQL 命令
                if (dba.SavePersonData(person))
                {
                    System.Windows.Forms.MessageBox.Show("Operation Successfuly.");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Operation Fail.\nErrorCode: >> " + dba.ErrorCode);
                }
            }

            if (Utility.Optype == OpreatType.edit)  //编辑
            {
                person = AssignPersonData(OpreatType.edit);
                if (dba.UpdatePersonData(person))
                {
                    System.Windows.Forms.MessageBox.Show("Update Data Successfuly.");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Operation Fail.\nErrorCode: >> " + dba.ErrorCode);
                }
            }
        }
Beispiel #3
0
        private bool AddAndUpdateInfo()
        {
            bool isExecute = false;

            Control[] ctls = new Control[] { txCompanyID, txCompanyName, txCorporate, txContract, txAddress, txCompanyTel };
            //查空
            foreach (Control item in ctls)
            {
                if (item.Text == "")
                {
                    MessageBox.Show("Please fill the necessary projects.");
                    item.Focus();
                    return(false);
                }
            }
            dba = new Dbaccess();
            getCorps();
            try
            {
                //添加信息
                if (Utility.Optype == OpreatType.add)
                {
                    //查重
                    string sqlstr = "";
                    isExecute = dba.SaveCompanyData(corps);
                }
                if (Utility.Optype == OpreatType.edit)
                {
                    isExecute = dba.UpdateCompanyData(corps);
                }

                if (isExecute)
                {
                    MessageBox.Show("Operation successful.\nData had be saved to database.");
                }
                else
                {
                    MessageBox.Show("Operation fail. Error:\n" + dba.ErrorCode);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Operation fail. Error:\n" + ex.Message);
                isExecute = false;
            }

            return(isExecute);
        }
Beispiel #4
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            if (!IsEmptyValue())
            {
                return;
            }
            dba = new Dbaccess();
            if (Utility.Optype == OpreatType.add) //添加
            {                                     //检查重复
                proj = GetProjectData(OpreatType.add);
                string sql = "select * from staffs where (wWorkerNum = '" + proj.ProjectID +
                             "')" /* + or ((wIdtype = '" + person.Idtype +
                                   * "') and (wIdNumber = '" + person.IdNumber + "'))" */;
                DataTable thedt = dba.ReadDatas(sql, false);
                if (thedt.Rows.Count >= 1)
                {
                    MessageBox.Show("This employee data already exists in the database.");
                    return;
                }

                //执行 SQL 命令
                if (dba.SavProjectData(proj))
                {
                    System.Windows.Forms.MessageBox.Show("Operation Successfuly.");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Operation Fail.\nErrorCode: >> " + dba.ErrorCode);
                }
            }

            if (Utility.Optype == OpreatType.edit)  //编辑
            {
                proj = GetProjectData(OpreatType.edit);
                if (dba.UpdateProjectData(proj))
                {
                    System.Windows.Forms.MessageBox.Show("Update Data Successfuly.");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("Operation Fail.\nErrorCode: >> " + dba.ErrorCode);
                }
            }
        }