private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (txtCarCode.Text == "") { MessageBox.Show("กรุณากรอก รหัสรถยนต์"); return; } if (txtCarName.Text == "") { MessageBox.Show("กรุณากรอก ยี่ห้อรถยนต์"); return; } if (txtCarModel.Text == "") { MessageBox.Show("กรุณากรอก รุ่นรถยนต์"); return; } if (txtCarEngine.Text == "") { MessageBox.Show("กรุณากรอก เครื่องรถยนต์"); return; } if (MessageBox.Show("ยืนยันการบันทึกข้อมูล", "การบันทึกข้อมูล", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { bool complete = false; CarDAL dal = new CarDAL(); if (DataCommon.Exists("CAR_EDIT")) { item = (CarData)DataCommon.Get("CAR_EDIT"); CarData newItem = new CarData(); newItem.CAR_CODE = txtCarCode.Text.ToUpper(); newItem.CAR_ENGINE = txtCarEngine.Text.ToUpper(); newItem.CAR_MODEL = txtCarModel.Text.ToUpper(); newItem.CAR_NAME = txtCarName.Text.ToUpper(); newItem.CAR_REMARK = txtCarRemark.Text; newItem.CAR_STATUS = cbbStatus.Text == "ใช้งาน" ? "A" : "I"; dal.Update(item, newItem); DataCommon.Remove("CAR_EDIT"); complete = true; } else { if (dal.GetItem(txtCarCode.Text, txtCarName.Text, txtCarModel.Text, txtCarEngine.Text) == null) { item = new CarData(); item.CAR_CODE = txtCarCode.Text.ToUpper(); item.CAR_ENGINE = txtCarEngine.Text.ToUpper(); item.CAR_MODEL = txtCarModel.Text.ToUpper(); item.CAR_NAME = txtCarName.Text.ToUpper(); item.CAR_REMARK = txtCarRemark.Text; item.CAR_STATUS = cbbStatus.Text == "ใช้งาน" ? "A" : "I"; new CarDAL().Insert(item); complete = true; } else { MessageBox.Show("รหัสรถยนต์นี้ซ้ำในระบบ กรุณาเปลี่ยนรหัสรถยนต์"); } } if (complete) { MessageBox.Show("บันทึกข้อมูลสำเร็จ"); this.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }