protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //���ؿؼ� SCoprationBB coprationBB = new SCoprationBB(); SCoprationData coprationData = new SCoprationData(); try { coprationData = coprationBB.GetModel(); if (coprationData != null) { this.State = "2"; this.ShowInfo(coprationData); } else { this.State = "1"; } } finally { coprationBB.Dispose(); } } }
protected void btnAdd_Click(object sender, EventArgs e) { SCoprationData model = new SCoprationData(); SCoprationBB coprationBB = new SCoprationBB(); try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; coprationBB.AddRecord(model); this.State = "2"; } else if (this.State == "2") { model = coprationBB.GetModel(); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; coprationBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { coprationBB.Dispose(); } }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(SCoprationData model) { return this.coprationDB.ModifyRecord(model); }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(SCoprationData model) { return this.coprationDB.AddRecord(model); }
private void ShowInfo(SCoprationData model) { this.coperationChiFull.Text = model.coperationChiFull; this.coperationChiShort.Text = model.coperationChiShort; this.coperationEngFull.Text = model.coperationEngFull; this.mark.Text = model.mark; }
private void SetModel(ref SCoprationData model) { model.coperationChiFull = this.coperationChiFull.Text; model.coperationChiShort = this.coperationChiShort.Text; model.coperationEngFull = this.coperationEngFull.Text; model.mark = this.mark.Text; }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public int AddRecord(SCoprationData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into SCopration("); strSql.Append("coperationId,coperationChiFull,coperationChiShort,coperationEngFull,coperationEngShort,addressChi,addressEng,businessAdminstrationNo,customNo,tradeManageNo,enterpriseInOutPortNo,taxNo,businessCheckNo,prensentNm,openAccount1,account1,openAccount2,account2,privince,city,telephon,fax,eMail,postCard,enterpriseNo,webAddress,copBrife,mark,isrtDt,isrtEmpId,updtDt,updtEmpId)"); strSql.Append(" values ("); strSql.Append("@coperationId,@coperationChiFull,@coperationChiShort,@coperationEngFull,@coperationEngShort,@addressChi,@addressEng,@businessAdminstrationNo,@customNo,@tradeManageNo,@enterpriseInOutPortNo,@taxNo,@businessCheckNo,@prensentNm,@openAccount1,@account1,@openAccount2,@account2,@privince,@city,@telephon,@fax,@eMail,@postCard,@enterpriseNo,@webAddress,@copBrife,@mark,@isrtDt,@isrtEmpId,@updtDt,@updtEmpId)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@coperationId", SqlDbType.NVarChar,20), new SqlParameter("@coperationChiFull", SqlDbType.NVarChar,100), new SqlParameter("@coperationChiShort", SqlDbType.NVarChar,50), new SqlParameter("@coperationEngFull", SqlDbType.NVarChar,100), new SqlParameter("@coperationEngShort", SqlDbType.NVarChar,50), new SqlParameter("@addressChi", SqlDbType.NVarChar,100), new SqlParameter("@addressEng", SqlDbType.NVarChar,100), new SqlParameter("@businessAdminstrationNo", SqlDbType.NVarChar,20), new SqlParameter("@customNo", SqlDbType.NVarChar,20), new SqlParameter("@tradeManageNo", SqlDbType.NVarChar,20), new SqlParameter("@enterpriseInOutPortNo", SqlDbType.NVarChar,20), new SqlParameter("@taxNo", SqlDbType.NVarChar,20), new SqlParameter("@businessCheckNo", SqlDbType.NVarChar,20), new SqlParameter("@prensentNm", SqlDbType.NVarChar,20), new SqlParameter("@openAccount1", SqlDbType.NVarChar,50), new SqlParameter("@account1", SqlDbType.NVarChar,50), new SqlParameter("@openAccount2", SqlDbType.NVarChar,50), new SqlParameter("@account2", SqlDbType.NVarChar,50), new SqlParameter("@privince", SqlDbType.NVarChar,10), new SqlParameter("@city", SqlDbType.NVarChar,10), new SqlParameter("@telephon", SqlDbType.NVarChar,20), new SqlParameter("@fax", SqlDbType.NVarChar,20), new SqlParameter("@eMail", SqlDbType.NVarChar,50), new SqlParameter("@postCard", SqlDbType.NVarChar,20), new SqlParameter("@enterpriseNo", SqlDbType.NVarChar,20), new SqlParameter("@webAddress", SqlDbType.NVarChar,50), new SqlParameter("@copBrife", SqlDbType.NVarChar,500), new SqlParameter("@mark", SqlDbType.NVarChar,200), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int) }; parameters[0].Value = model.coperationId; parameters[1].Value = model.coperationChiFull; parameters[2].Value = model.coperationChiShort; parameters[3].Value = model.coperationEngFull; parameters[4].Value = model.coperationEngShort; parameters[5].Value = model.addressChi; parameters[6].Value = model.addressEng; parameters[7].Value = model.businessAdminstrationNo; parameters[8].Value = model.customNo; parameters[9].Value = model.tradeManageNo; parameters[10].Value = model.enterpriseInOutPortNo; parameters[11].Value = model.taxNo; parameters[12].Value = model.businessCheckNo; parameters[13].Value = model.prensentNm; parameters[14].Value = model.openAccount1; parameters[15].Value = model.account1; parameters[16].Value = model.openAccount2; parameters[17].Value = model.account2; parameters[18].Value = model.privince; parameters[19].Value = model.city; parameters[20].Value = model.telephon; parameters[21].Value = model.fax; parameters[22].Value = model.eMail; parameters[23].Value = model.postCard; parameters[24].Value = model.enterpriseNo; parameters[25].Value = model.webAddress; parameters[26].Value = model.copBrife; parameters[27].Value = model.mark; parameters[28].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[29].Value = model.isrtEmpId; parameters[30].Value = model.updtDt == string.Empty ? null : model.updtDt; parameters[31].Value = model.updtEmpId; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// ����һ������ /// </summary> /// <param name="model">model</param> public bool ModifyRecord(SCoprationData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update SCopration set "); strSql.Append("coperationId=@coperationId,"); strSql.Append("coperationChiFull=@coperationChiFull,"); strSql.Append("coperationChiShort=@coperationChiShort,"); strSql.Append("coperationEngFull=@coperationEngFull,"); strSql.Append("coperationEngShort=@coperationEngShort,"); strSql.Append("addressChi=@addressChi,"); strSql.Append("addressEng=@addressEng,"); strSql.Append("businessAdminstrationNo=@businessAdminstrationNo,"); strSql.Append("customNo=@customNo,"); strSql.Append("tradeManageNo=@tradeManageNo,"); strSql.Append("enterpriseInOutPortNo=@enterpriseInOutPortNo,"); strSql.Append("taxNo=@taxNo,"); strSql.Append("businessCheckNo=@businessCheckNo,"); strSql.Append("prensentNm=@prensentNm,"); strSql.Append("openAccount1=@openAccount1,"); strSql.Append("account1=@account1,"); strSql.Append("openAccount2=@openAccount2,"); strSql.Append("account2=@account2,"); strSql.Append("privince=@privince,"); strSql.Append("city=@city,"); strSql.Append("telephon=@telephon,"); strSql.Append("fax=@fax,"); strSql.Append("eMail=@eMail,"); strSql.Append("postCard=@postCard,"); strSql.Append("enterpriseNo=@enterpriseNo,"); strSql.Append("webAddress=@webAddress,"); strSql.Append("copBrife=@copBrife,"); strSql.Append("mark=@mark,"); strSql.Append("isrtDt=@isrtDt,"); strSql.Append("isrtEmpId=@isrtEmpId,"); strSql.Append("updtDt=@updtDt,"); strSql.Append("updtEmpId=@updtEmpId"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@coperationId", SqlDbType.NVarChar,20), new SqlParameter("@coperationChiFull", SqlDbType.NVarChar,100), new SqlParameter("@coperationChiShort", SqlDbType.NVarChar,50), new SqlParameter("@coperationEngFull", SqlDbType.NVarChar,100), new SqlParameter("@coperationEngShort", SqlDbType.NVarChar,50), new SqlParameter("@addressChi", SqlDbType.NVarChar,100), new SqlParameter("@addressEng", SqlDbType.NVarChar,100), new SqlParameter("@businessAdminstrationNo", SqlDbType.NVarChar,20), new SqlParameter("@customNo", SqlDbType.NVarChar,20), new SqlParameter("@tradeManageNo", SqlDbType.NVarChar,20), new SqlParameter("@enterpriseInOutPortNo", SqlDbType.NVarChar,20), new SqlParameter("@taxNo", SqlDbType.NVarChar,20), new SqlParameter("@businessCheckNo", SqlDbType.NVarChar,20), new SqlParameter("@prensentNm", SqlDbType.NVarChar,20), new SqlParameter("@openAccount1", SqlDbType.NVarChar,50), new SqlParameter("@account1", SqlDbType.NVarChar,50), new SqlParameter("@openAccount2", SqlDbType.NVarChar,50), new SqlParameter("@account2", SqlDbType.NVarChar,50), new SqlParameter("@privince", SqlDbType.NVarChar,10), new SqlParameter("@city", SqlDbType.NVarChar,10), new SqlParameter("@telephon", SqlDbType.NVarChar,20), new SqlParameter("@fax", SqlDbType.NVarChar,20), new SqlParameter("@eMail", SqlDbType.NVarChar,50), new SqlParameter("@postCard", SqlDbType.NVarChar,20), new SqlParameter("@enterpriseNo", SqlDbType.NVarChar,20), new SqlParameter("@webAddress", SqlDbType.NVarChar,50), new SqlParameter("@copBrife", SqlDbType.NVarChar,500), new SqlParameter("@mark", SqlDbType.NVarChar,200), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int) }; parameters[0].Value = model.id; parameters[1].Value = model.coperationId; parameters[2].Value = model.coperationChiFull; parameters[3].Value = model.coperationChiShort; parameters[4].Value = model.coperationEngFull; parameters[5].Value = model.coperationEngShort; parameters[6].Value = model.addressChi; parameters[7].Value = model.addressEng; parameters[8].Value = model.businessAdminstrationNo; parameters[9].Value = model.customNo; parameters[10].Value = model.tradeManageNo; parameters[11].Value = model.enterpriseInOutPortNo; parameters[12].Value = model.taxNo; parameters[13].Value = model.businessCheckNo; parameters[14].Value = model.prensentNm; parameters[15].Value = model.openAccount1; parameters[16].Value = model.account1; parameters[17].Value = model.openAccount2; parameters[18].Value = model.account2; parameters[19].Value = model.privince; parameters[20].Value = model.city; parameters[21].Value = model.telephon; parameters[22].Value = model.fax; parameters[23].Value = model.eMail; parameters[24].Value = model.postCard; parameters[25].Value = model.enterpriseNo; parameters[26].Value = model.webAddress; parameters[27].Value = model.copBrife; parameters[28].Value = model.mark; parameters[29].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[30].Value = model.isrtEmpId; parameters[31].Value = model.updtDt == string.Empty ? null : model.updtDt; parameters[32].Value = model.updtEmpId; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
//***************************************************************************** //do it later do it later do it later //***************************************************************************** /// <summary> /// �õ�һ��model /// </summary> /// <returns>model</returns> public SCoprationData GetModel() { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from SCopration"); SCoprationData model = new SCoprationData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["coperationId"] != DBNull.Value) { model.coperationId = Convert.ToString(row["coperationId"]); } if (row["coperationChiFull"] != DBNull.Value) { model.coperationChiFull = Convert.ToString(row["coperationChiFull"]); } if (row["coperationChiShort"] != DBNull.Value) { model.coperationChiShort = Convert.ToString(row["coperationChiShort"]); } if (row["coperationEngFull"] != DBNull.Value) { model.coperationEngFull = Convert.ToString(row["coperationEngFull"]); } if (row["coperationEngShort"] != DBNull.Value) { model.coperationEngShort = Convert.ToString(row["coperationEngShort"]); } if (row["addressChi"] != DBNull.Value) { model.addressChi = Convert.ToString(row["addressChi"]); } if (row["addressEng"] != DBNull.Value) { model.addressEng = Convert.ToString(row["addressEng"]); } if (row["businessAdminstrationNo"] != DBNull.Value) { model.businessAdminstrationNo = Convert.ToString(row["businessAdminstrationNo"]); } if (row["customNo"] != DBNull.Value) { model.customNo = Convert.ToString(row["customNo"]); } if (row["tradeManageNo"] != DBNull.Value) { model.tradeManageNo = Convert.ToString(row["tradeManageNo"]); } if (row["enterpriseInOutPortNo"] != DBNull.Value) { model.enterpriseInOutPortNo = Convert.ToString(row["enterpriseInOutPortNo"]); } if (row["taxNo"] != DBNull.Value) { model.taxNo = Convert.ToString(row["taxNo"]); } if (row["businessCheckNo"] != DBNull.Value) { model.businessCheckNo = Convert.ToString(row["businessCheckNo"]); } if (row["prensentNm"] != DBNull.Value) { model.prensentNm = Convert.ToString(row["prensentNm"]); } if (row["openAccount1"] != DBNull.Value) { model.openAccount1 = Convert.ToString(row["openAccount1"]); } if (row["account1"] != DBNull.Value) { model.account1 = Convert.ToString(row["account1"]); } if (row["openAccount2"] != DBNull.Value) { model.openAccount2 = Convert.ToString(row["openAccount2"]); } if (row["account2"] != DBNull.Value) { model.account2 = Convert.ToString(row["account2"]); } if (row["privince"] != DBNull.Value) { model.privince = Convert.ToString(row["privince"]); } if (row["city"] != DBNull.Value) { model.city = Convert.ToString(row["city"]); } if (row["telephon"] != DBNull.Value) { model.telephon = Convert.ToString(row["telephon"]); } if (row["fax"] != DBNull.Value) { model.fax = Convert.ToString(row["fax"]); } if (row["eMail"] != DBNull.Value) { model.eMail = Convert.ToString(row["eMail"]); } if (row["postCard"] != DBNull.Value) { model.postCard = Convert.ToString(row["postCard"]); } if (row["enterpriseNo"] != DBNull.Value) { model.enterpriseNo = Convert.ToString(row["enterpriseNo"]); } if (row["webAddress"] != DBNull.Value) { model.webAddress = Convert.ToString(row["webAddress"]); } if (row["copBrife"] != DBNull.Value) { model.copBrife = Convert.ToString(row["copBrife"]); } if (row["mark"] != DBNull.Value) { model.mark = Convert.ToString(row["mark"]); } if (row["isrtDt"] != DBNull.Value) { model.isrtDt = Convert.ToString(row["isrtDt"]); } if (row["isrtEmpId"] != DBNull.Value) { model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]); } if (row["updtDt"] != DBNull.Value) { model.updtDt = Convert.ToString(row["updtDt"]); } if (row["updtEmpId"] != DBNull.Value) { model.updtEmpId = Convert.ToInt32(row["updtEmpId"]); } return model; } else { return null; } }