private void btnOK_Click(object sender, EventArgs e)
        {
            ShipInfoMangement shipInfoMangement = new ShipInfoMangement();
            String            name = textBoatName.Text.Trim();

            //连接数据库
            SqlConnection conn = DataBase.Connect();
            SqlDataReader dr   = null;

            String str = "select * from 船只基本资料 where 船只名称 = '" + name + "'";

            try
            {
                if (!DataBase.Inquire(str, conn))
                {
                    MessageBox.Show("船只不存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                DataBase.Inquire(str, conn, ref dr);

                if (dr.Read())
                {
                    textName.Text            = dr["船主姓名"].ToString();
                    textID.Text              = dr["身份证"].ToString();
                    textTel.Text             = dr["联系电话"].ToString();
                    textAddress.Text         = dr["详细住址"].ToString();
                    textBoatName.Text        = dr["船只名称"].ToString();
                    textBoatType.Text        = dr["船舶类型"].ToString();
                    textBoatMaterial.Text    = dr["船体材料"].ToString();
                    textBoatNo.Text          = dr["机型"].ToString();
                    textBoatPort.Text        = dr["船籍港"].ToString();
                    textFactory.Text         = dr["建造厂"].ToString();
                    textBoatSignUpNo.Text    = dr["船舶登记号"].ToString();
                    textBoatInTime.Text      = dr["入户时间"].ToString();
                    textOutTime.Text         = dr["迁出时间"].ToString();
                    textBoatLength.Text      = dr["总长"].ToString();
                    textBoatWidth.Text       = dr["型宽"].ToString();
                    textBoatDepth.Text       = dr["型深"].ToString();
                    textBoatTotalWeight.Text = dr["总吨"].ToString();
                    textBoatWeight.Text      = dr["净吨"].ToString();
                    textBoatPower.Text       = dr["主机功率"].ToString();
                    textBoatCarryWeight.Text = dr["载重吨"].ToString();
                    textBoatSailArea.Text    = dr["航行区域"].ToString();
                    textNote.Text            = dr["备注"].ToString();
                }
                dr.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "显示失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                DataBase.Close(conn);
            }
        }
Beispiel #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            ShipInfoMangement shipInfoMangement = new ShipInfoMangement();

            shipInfoMangement.Name            = textName.Text.Trim();
            shipInfoMangement.ID              = textID.Text.Trim();
            shipInfoMangement.Address         = textAddress.Text;
            shipInfoMangement.Tel             = textTel.Text.Trim();
            shipInfoMangement.BoatCarryWeight = textBoatCarryWeight.Text.Trim();
            shipInfoMangement.BoatDepth       = textBoatDepth.Text.Trim();
            shipInfoMangement.BoatInTime      = textBoatInTime.Text;
            shipInfoMangement.BoatLength      = textBoatLength.Text.Trim();
            shipInfoMangement.BoatMaterial    = textBoatMaterial.Text.Trim();
            shipInfoMangement.BoatNo          = textBoatNo.Text.Trim();
            shipInfoMangement.BoatOutTime     = textOutTime.Text;
            shipInfoMangement.BoatPort        = textBoatPort.Text;
            shipInfoMangement.BoatPower       = textBoatPower.Text;
            shipInfoMangement.BoatSailArea    = textBoatSailArea.Text;
            shipInfoMangement.BoatTotalWeight = textBoatTotalWeight.Text;
            shipInfoMangement.BoatType        = textBoatType.Text;
            shipInfoMangement.BoatWeight      = textBoatWeight.Text.Trim();
            shipInfoMangement.BoatWidth       = textBoatWidth.Text.Trim();
            shipInfoMangement.Factory         = textFactory.Text;
            shipInfoMangement.Note            = textNote.Text;
            shipInfoMangement.BoatName        = textBoatName.Text.Trim();
            shipInfoMangement.BoatSignUpNo    = textBoatSignUpNo.Text.Trim();


            //连接数据库
            SqlConnection conn = DataBase.Connect();

            String str  = "Insert into 船只基本资料 values ('" + shipInfoMangement.Name + "','" + shipInfoMangement.ID + "','" + shipInfoMangement.Tel + "','" + shipInfoMangement.Address + "','" + shipInfoMangement.BoatName + "','" + shipInfoMangement.BoatType + "','" + shipInfoMangement.BoatMaterial + "','" + shipInfoMangement.BoatNo + "','" + shipInfoMangement.BoatPort + "','" + shipInfoMangement.Factory + "','" + shipInfoMangement.BoatSignUpNo + "','" + shipInfoMangement.BoatInTime + "','" + shipInfoMangement.BoatOutTime + "','" + shipInfoMangement.BoatLength + "','" + shipInfoMangement.BoatWidth + "','" + shipInfoMangement.BoatDepth + "','" + shipInfoMangement.BoatTotalWeight + "','" + shipInfoMangement.BoatWeight + "','" + shipInfoMangement.BoatPower + "','" + shipInfoMangement.BoatCarryWeight + "','" + shipInfoMangement.BoatSailArea + "','" + shipInfoMangement.Note + "')";
            String str1 = "select * from 船只基本资料 where 船只名称 = '" + shipInfoMangement.BoatName + "'";

            try
            {
                if (DataBase.Inquire(str1, conn))
                {
                    MessageBox.Show("船只存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (DataBase.Insert(str, conn))
                {
                    MessageBox.Show("录入成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "录入失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                DataBase.Close(conn);
            }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            ShipInfoMangement shipInfoMangement = new ShipInfoMangement();

            shipInfoMangement.Name            = textName.Text.Trim();
            shipInfoMangement.ID              = textID.Text.Trim();
            shipInfoMangement.Address         = textAddress.Text;
            shipInfoMangement.Tel             = textTel.Text.Trim();
            shipInfoMangement.BoatCarryWeight = textBoatCarryWeight.Text.Trim();
            shipInfoMangement.BoatDepth       = textBoatDepth.Text.Trim();
            shipInfoMangement.BoatInTime      = textBoatInTime.Text;
            shipInfoMangement.BoatLength      = textBoatLength.Text.Trim();
            shipInfoMangement.BoatMaterial    = textBoatMaterial.Text.Trim();
            shipInfoMangement.BoatNo          = textBoatNo.Text.Trim();
            shipInfoMangement.BoatOutTime     = textOutTime.Text;
            shipInfoMangement.BoatPort        = textBoatPort.Text;
            shipInfoMangement.BoatPower       = textBoatPower.Text;
            shipInfoMangement.BoatSailArea    = textBoatSailArea.Text;
            shipInfoMangement.BoatTotalWeight = textBoatTotalWeight.Text;
            shipInfoMangement.BoatType        = textBoatType.Text;
            shipInfoMangement.BoatWeight      = textBoatWeight.Text.Trim();
            shipInfoMangement.BoatWidth       = textBoatWidth.Text.Trim();
            shipInfoMangement.Factory         = textFactory.Text;
            shipInfoMangement.Note            = textNote.Text;
            shipInfoMangement.BoatName        = textBoatName.Text.Trim();
            shipInfoMangement.BoatSignUpNo    = textBoatSignUpNo.Text.Trim();


            //连接数据库
            SqlConnection conn = DataBase.Connect();

            String str = "UPDATE 船只基本资料 SET 船主姓名 = '" + shipInfoMangement.Name + "', 身份证 = '" + shipInfoMangement.ID + "', 联系电话 = '" + shipInfoMangement.Tel + "', 详细住址 = '" + shipInfoMangement.Address + "', 船只名称 = '" + shipInfoMangement.BoatName + "', 船舶类型 = '" + shipInfoMangement.BoatType + "', 船体材料 = '" + shipInfoMangement.BoatMaterial + "', 机型 = '" + shipInfoMangement.BoatNo + "', 船籍港 = '" + shipInfoMangement.BoatPort + "', 建造厂 = '" + shipInfoMangement.Factory + "', 船舶登记号 = '" + shipInfoMangement.BoatSignUpNo + "', 入户时间 = '" + shipInfoMangement.BoatInTime + "', 迁出时间 = '" + shipInfoMangement.BoatOutTime + "', 总长 = " + shipInfoMangement.BoatLength + ", 型宽 = " + shipInfoMangement.BoatWidth + ", 型深 = " + shipInfoMangement.BoatDepth + ", 总吨 = " + shipInfoMangement.BoatTotalWeight + ", 净吨 = " + shipInfoMangement.BoatWeight + ", 主机功率 = " + shipInfoMangement.BoatPower + ", 载重吨 = " + shipInfoMangement.BoatCarryWeight + ", 航行区域 = '" + shipInfoMangement.BoatSailArea + "', 备注 = '" + shipInfoMangement.Note + "' WHERE 船只名称 = '" + shipInfoMangement.BoatName + "'";

            try
            {
                if (DataBase.Update(str, conn))
                {
                    MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "修改失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                DataBase.Close(conn);
            }
        }