protected void updateUser_Click(object sender, EventArgs e) { ReceiptAdapter da = new ReceiptAdapter(); T_Receipt item = new T_Receipt(); item.Code = this.txt_code.Text.Trim(); item.Name = this.txt_name.Text.Trim(); if (string.IsNullOrEmpty(item.Code)) { Label1.Text = "部门代码不能为空"; return; } if (string.IsNullOrEmpty(item.Name)) { Label1.Text = "部门名称不能为空"; return; } if (string.IsNullOrEmpty(HiddenField1.Value)) { //新增 try { da.addReceipt(item); Label1.Text = "新增成功"; init(); GridViewBand(); } catch (Exception ex) { Label1.Text = ex.Message; } } else { //更新 item.Id = Int32.Parse(HiddenField1.Value); try { da.updateReceipt(item); Label1.Text = "保存成功"; init(); GridViewBand(); } catch (Exception ex) { Label1.Text = ex.Message; } } }
private void receiptSave_Click(object sender, EventArgs e) { string name = custName.Text; string telH = custTelH.SelectedText; string telB = custTelB.Text; string year = custYear.SelectedText; string month = custMonth.SelectedText; string day = custDay.SelectedText; string model = carModel.SelectedText; string number = carNum.Text; string cc = CarCC.SelectedText; string caryear = carYear.SelectedText; string staffname = staffName.SelectedText; /*if (name.Equals("") || telB.Equals("") || number.Equals("")) * { * MessageBox.Show("빈칸을 입력하세요", "빈칸", MessageBoxButtons.OK); * ActiveControl = custName; * custName.Focus(); * ActiveControl = custTelB; * custTelB.Focus(); * ActiveControl = carNum; * carNum.Focus(); * return; * } * * if (telH.Equals("")) * { * MessageBox.Show("전화번호 앞자리를 선택하세요", "선택", MessageBoxButtons.OK); * ActiveControl = custTelH; * custTelH.Focus(); * return; * }*/ string[] arrData = new string[] { name, telH, telB, year, month, day, model, number, cc, caryear, staffname }; object[] arrObj = new object[] { custName, custTelH, custTelB, custYear, custMonth, custDay, carModel, carNum, CarCC, carYear, staffName }; string[] arrMsg = new string[] { "빈칸을 입력하세요", "전화번호 앞자리를 선택하세요", "전화번호 뒷자리를 선택하세요", "년도를 선택하세요", "월을 선택하세요", "일을 선택하세요", "차량모델을 선택하세요", "차량번호를 입력하세요", "배기량을 선택하세요", "차량연식을 선택하세요", "담당자를 선택하세요" }; for (int i = 0; i < arrData.Length; i++) { if (arrData[i].Equals("") || arrData[i].Equals("선택")) { MessageBox.Show(arrMsg[i], "빈칸", MessageBoxButtons.OK); ActiveControl = arrObj[i] as Control; ActiveControl.Focus(); return; } } UICheckBox[] checkBox = new UICheckBox[] { chk1, chk2, chk3, chk4, chk5, chk6, chk7, chk8, chk9, chk10 }; List <RepairItem> itemList = new List <RepairItem>(); for (int i = RepairTable.ENGINE_OIL; i < RepairTable.ETC_COST + 1; i++) { if (checkBox[i].Checked) { Console.WriteLine("수리항목 : " + checkBox[i].Text); Console.WriteLine("수리비 : " + RepairTable.fixMoney[i]); itemList.Add(new RepairItem(i, checkBox[i].Text, RepairTable.fixMoney[i])); } } if (itemList.Count == 0) { MessageBox.Show("수리항목을 체크하세요"); return; } //한글 입력 체크 string chkName = Regex.Replace(name, @"[^가-힣]", ""); if (chkName.Length != name.Length) { MessageBox.Show("잘못된 이름형식입니다"); ActiveControl = custName; ActiveControl.Focus(); custName.Text = ""; return; } //자리수 체크 Regex regex = new Regex(@"[가-힣]{3}"); Match m = regex.Match(name); if (m.Success == false) { MessageBox.Show("이름 자리수가 올바르지 않습니다"); ActiveControl = custName; ActiveControl.Focus(); custName.Text = ""; return; } string telAll = telH + telB; if (telAll.Length == 10 || telAll.Length == 11) { Regex regex2 = new Regex(@"01{1}[01]{1}[0-9]{7,8}"); Match m2 = regex2.Match(telAll); if (m2.Success == false) { MessageBox.Show("잘못된 전화번호입니다"); return; } } else { MessageBox.Show("올바른 전화번호 자리수를 입력하세요"); return; } MessageBox.Show("고객명 : " + name + "\n" + "전화번호 : " + (telH + telB) + "\n" + "생년월일 : " + (year + month + day) + "\n" + "차량모델 : " + model + "\n" + "차량번호 : " + number + "\n" + "배기량 : " + cc + "\n" + "차량연식 : " + caryear + "\n" + "담당자 : " + staffname, "고객정보", MessageBoxButtons.OK); /*console.WriteLine("전화번호 : " + (telH + telB)); * console.WriteLine("생년월일 : " + (year + month + day)); * console.WriteLine("차량모델 : " + model); * console.WriteLine("차량번호 : " + number); * console.WriteLine("배기량 : " + cc); * Console.WriteLine("차량연식 : " + caryear); * Console.WriteLine("담당자 : " + staffname);*/ adapter.addReceipt(new Receipt( new Customer(name, telH + telB, year + month + day), new Car(model, number, cc, caryear), DateTime.Now.ToString("yyyy년MM월dd일"), staffname, itemList)); }