示例#1
0
 public int InsertWorkshop(Workshop workshop)
 {
     using (IDbConnection conn = OpenConnection())
     {
         return(conn.Execute("Insert into tbl_Workshop values "
                             + "(@Id, @Name)",
                             new { Id = workshop.Id, Name = workshop.Name }));
     }
 }
示例#2
0
        private void btn_Add_Click(object sender, RoutedEventArgs e)
        {
            DataAccessLayer db = new DataAccessLayer();

            if (txt_WorkshopName.Text.Trim() == String.Empty)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("请输入车间名称!");
                return;
            }
            else if (db.QueryWorkshopByName(txt_WorkshopName.Text).Count() > 0)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("已存在车间名称:" + txt_WorkshopName + "!");
                return;
            }
            else if (txt_WorkshopId.Text.Trim() == String.Empty)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("请输入车间编号!");
                return;
            }
            else if (db.QueryWorkshopById(int.Parse(txt_WorkshopId.Text)).Count() > 0)
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("已存在车间编号:" + txt_WorkshopId.Text + "!");
                return;
            }
            else
            {
                Workshop ws = new Workshop();
                ws.Name = txt_WorkshopName.Text;
                try
                {
                    ws.Id = int.Parse(txt_WorkshopId.Text);
                }
                catch
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("车间编号必须为数字!");
                    return;
                }
                db.InsertWorkshop(ws);
                wsmPage.FillListView();
                this.Close();
                return;
            }
        }
        private void btn_Modify_Click(object sender, RoutedEventArgs e)
        {
            Workshop modifiedWorkshop = new Workshop();

            if (txt_WorkshopName.Text != OriginWorkshop.Name)
            {
                if (db.QueryWorkshopByName(txt_WorkshopName.Text).Count() > 0)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("已存在车间名称:" + txt_WorkshopName.Text + "!");
                    return;
                }
            }
            if (txt_WorkshopId.Text != OriginWorkshop.Id.ToString())
            {
                if (db.QueryWorkshopById(int.Parse(txt_WorkshopId.Text)).Count() > 0)
                {
                    SystemSounds.Beep.Play();
                    MessageBox.Show("已存在车间编号:" + txt_WorkshopId.Text + "!");
                    return;
                }
            }
            modifiedWorkshop.Name = txt_WorkshopName.Text;
            try
            {
                modifiedWorkshop.Id = int.Parse(txt_WorkshopId.Text);
            }
            catch
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("车间编号必须为数字!");
                return;
            }
            try
            {
                db.DeleteWorkshopById(OriginWorkshop.Id);
            }
            catch
            {
                SystemSounds.Beep.Play();
                MessageBox.Show("更改失败!");
                return;
            }
            db.InsertWorkshop(modifiedWorkshop);
            wsmPage.FillListView();
            this.Close();
        }