protected void btnSave_Click(object sender, EventArgs e) { string userName = this.txtUserName.Text.Trim(); string password = this.txtPassword.Text.Trim(); if (userName.Length == 0) { MessageBox.ShowServerBusyTip(this, "用户名不能为空!"); } else { User user = new User(); if (user.HasUserByUserName(userName)) { MessageBox.ShowServerBusyTip(this, Site.TooltipUserExist); } else if (password.Length == 0) { MessageBox.ShowServerBusyTip(this, "密码不能为空!"); } else if (password.Length > 0x10) { MessageBox.ShowServerBusyTip(this, "密码不能超过16个字符!"); } else { string name = this.txtName.Text.Trim(); if (name.Length == 0) { MessageBox.ShowServerBusyTip(this, "企业名称不能为空!"); } else if (name.Length > 100) { MessageBox.ShowServerBusyTip(this, "企业名称请控制在1~100字符!"); } else if (this.bll.Exists(name)) { MessageBox.ShowServerBusyTip(this, "该企业名称已经被注册,请更换企业名称再操作!"); } else { int enterpriseID = 0; try { Maticsoft.Model.Ms.Enterprise model = new Maticsoft.Model.Ms.Enterprise { Name = name, Introduction = this.txtIntroduction.Text, RegisteredCapital = new int?(Globals.SafeInt(this.txtRegisteredCapital.Text, 0)), TelPhone = this.txtTelPhone.Text, CellPhone = this.txtCellPhone.Text, ContactMail = this.txtContactMail.Text, RegionID = new int?(this.RegionID.Region_iID), Address = this.txtAddress.Text, Remark = this.txtRemark.Text, Contact = this.txtContact.Text, UserName = this.txtUserName.Text }; string text = this.txtEstablishedDate.Text; if (PageValidate.IsDateTime(text)) { model.EstablishedDate = new DateTime?(Globals.SafeDateTime(text, DateTime.Now)); } else { model.EstablishedDate = null; } model.EstablishedCity = new int?(this.RegionEstablishedCity.Region_iID); model.LOGO = this.txtLOGO.Text; model.Fax = this.txtFax.Text; model.PostCode = this.txtPostCode.Text; model.HomePage = this.txtHomePage.Text; model.ArtiPerson = this.txtArtiPerson.Text; model.EnteRank = new int?(Globals.SafeInt(this.dropEnteRank.SelectedValue, 0)); model.EnteClassID = new int?(Globals.SafeInt(this.dropEnteClassID.SelectedValue, 0)); model.CompanyType = new int?(Globals.SafeInt(this.dropCompanyType.SelectedValue, 0)); model.BusinessLicense = this.txtBusinessLicense.Text; model.TaxNumber = this.txtTaxNumber.Text; model.AccountBank = this.txtAccountBank.Text; model.AccountInfo = this.txtAccountInfo.Text; model.ServicePhone = this.txtServicePhone.Text; model.QQ = this.txtQQ.Text; model.MSN = this.txtMSN.Text; model.Status = new int?(Globals.SafeInt(this.radlStatus.SelectedValue, 0)); model.CreatedDate = new DateTime?(DateTime.Now); model.CreatedUserID = new int?(base.CurrentUser.UserID); model.UpdatedDate = new DateTime?(DateTime.Now); model.UpdatedUserID = new int?(base.CurrentUser.UserID); model.Balance = Globals.SafeDecimal(this.txtBalance.Text, (decimal) 0M); model.AgentID = Globals.SafeInt(this.txtAgentID.Text, 0); enterpriseID = this.bll.Add(model); if (enterpriseID > 0) { user.UserName = userName; user.NickName = this.txtName.Text; user.Password = AccountsPrincipal.EncryptPassword(password); user.TrueName = ""; user.Sex = "1"; user.Phone = this.txtCellPhone.Text; user.Email = this.txtContactMail.Text; user.EmployeeID = 0; user.DepartmentID = enterpriseID.ToString(); user.Activity = true; user.UserType = "EE"; user.Style = 1; user.User_dateCreate = DateTime.Now; user.User_iCreator = base.CurrentUser.UserID; user.User_dateValid = DateTime.Now; user.User_cLang = "zh-CN"; int userID = user.Create(); if (userID == -100) { this.bll.Delete(enterpriseID); MessageBox.ShowServerBusyTip(this, Site.TooltipUserExist); } else { UsersExp exp = new UsersExp { UserID = userID, BirthdayVisible = 0, BirthdayIndexVisible = false, ConstellationVisible = 0, ConstellationIndexVisible = false, NativePlaceVisible = 0, NativePlaceIndexVisible = false, RegionId = 0, AddressVisible = 0, AddressIndexVisible = false, BodilyFormVisible = 0, BodilyFormIndexVisible = false, BloodTypeVisible = 0, BloodTypeIndexVisible = false, MarriagedVisible = 0, MarriagedIndexVisible = false, PersonalStatusVisible = 0, PersonalStatusIndexVisible = false, LastAccessIP = "", LastAccessTime = new DateTime?(DateTime.Now), LastLoginTime = DateTime.Now, LastPostTime = new DateTime?(DateTime.Now) }; if (exp.AddUsersExp(exp)) { MessageBox.ShowSuccessTip(this, "添加成功!", "List.aspx"); } else { user.UserID = userID; user.Delete(); exp.DeleteUsersExp(userID); this.bll.Delete(enterpriseID); MessageBox.ShowFailTip(this, "添加失败!"); } } } else { this.bll.Delete(enterpriseID); MessageBox.ShowFailTip(this, "添加失败!"); } } catch (Exception exception) { this.bll.Delete(enterpriseID); throw exception; } } } } }
public Maticsoft.Model.Ms.Enterprise GetModel(int EnterpriseID) { StringBuilder builder = new StringBuilder(); builder.Append("SELECT MsEn.*,AU.UserName AS CreatedUserName,AUser.UserName AS UpdatedUserName FROM Ms_Enterprise MsEn "); builder.Append(" LEFT JOIN Accounts_Users AU ON MsEn.CreatedUserID=AU.UserID "); builder.Append(" LEFT JOIN Accounts_Users AUser ON MsEn.UpdatedUserID=AUser.UserID "); builder.Append(" where EnterpriseID=@EnterpriseID"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@EnterpriseID", SqlDbType.Int, 4) }; cmdParms[0].Value = EnterpriseID; Maticsoft.Model.Ms.Enterprise enterprise = new Maticsoft.Model.Ms.Enterprise(); DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms); if (set.Tables[0].Rows.Count <= 0) { return null; } if ((set.Tables[0].Rows[0]["EnterpriseID"] != null) && (set.Tables[0].Rows[0]["EnterpriseID"].ToString() != "")) { enterprise.EnterpriseID = int.Parse(set.Tables[0].Rows[0]["EnterpriseID"].ToString()); } if ((set.Tables[0].Rows[0]["Name"] != null) && (set.Tables[0].Rows[0]["Name"].ToString() != "")) { enterprise.Name = set.Tables[0].Rows[0]["Name"].ToString(); } if ((set.Tables[0].Rows[0]["Introduction"] != null) && (set.Tables[0].Rows[0]["Introduction"].ToString() != "")) { enterprise.Introduction = set.Tables[0].Rows[0]["Introduction"].ToString(); } if ((set.Tables[0].Rows[0]["RegisteredCapital"] != null) && (set.Tables[0].Rows[0]["RegisteredCapital"].ToString() != "")) { enterprise.RegisteredCapital = new int?(int.Parse(set.Tables[0].Rows[0]["RegisteredCapital"].ToString())); } if ((set.Tables[0].Rows[0]["TelPhone"] != null) && (set.Tables[0].Rows[0]["TelPhone"].ToString() != "")) { enterprise.TelPhone = set.Tables[0].Rows[0]["TelPhone"].ToString(); } if ((set.Tables[0].Rows[0]["CellPhone"] != null) && (set.Tables[0].Rows[0]["CellPhone"].ToString() != "")) { enterprise.CellPhone = set.Tables[0].Rows[0]["CellPhone"].ToString(); } if ((set.Tables[0].Rows[0]["ContactMail"] != null) && (set.Tables[0].Rows[0]["ContactMail"].ToString() != "")) { enterprise.ContactMail = set.Tables[0].Rows[0]["ContactMail"].ToString(); } if ((set.Tables[0].Rows[0]["RegionID"] != null) && (set.Tables[0].Rows[0]["RegionID"].ToString() != "")) { enterprise.RegionID = new int?(int.Parse(set.Tables[0].Rows[0]["RegionID"].ToString())); } if ((set.Tables[0].Rows[0]["Address"] != null) && (set.Tables[0].Rows[0]["Address"].ToString() != "")) { enterprise.Address = set.Tables[0].Rows[0]["Address"].ToString(); } if ((set.Tables[0].Rows[0]["Remark"] != null) && (set.Tables[0].Rows[0]["Remark"].ToString() != "")) { enterprise.Remark = set.Tables[0].Rows[0]["Remark"].ToString(); } if ((set.Tables[0].Rows[0]["Contact"] != null) && (set.Tables[0].Rows[0]["Contact"].ToString() != "")) { enterprise.Contact = set.Tables[0].Rows[0]["Contact"].ToString(); } if ((set.Tables[0].Rows[0]["UserName"] != null) && (set.Tables[0].Rows[0]["UserName"].ToString() != "")) { enterprise.UserName = set.Tables[0].Rows[0]["UserName"].ToString(); } if ((set.Tables[0].Rows[0]["EstablishedDate"] != null) && (set.Tables[0].Rows[0]["EstablishedDate"].ToString() != "")) { enterprise.EstablishedDate = new DateTime?(DateTime.Parse(set.Tables[0].Rows[0]["EstablishedDate"].ToString())); } if ((set.Tables[0].Rows[0]["EstablishedCity"] != null) && (set.Tables[0].Rows[0]["EstablishedCity"].ToString() != "")) { enterprise.EstablishedCity = new int?(int.Parse(set.Tables[0].Rows[0]["EstablishedCity"].ToString())); } if ((set.Tables[0].Rows[0]["LOGO"] != null) && (set.Tables[0].Rows[0]["LOGO"].ToString() != "")) { enterprise.LOGO = set.Tables[0].Rows[0]["LOGO"].ToString(); } if ((set.Tables[0].Rows[0]["Fax"] != null) && (set.Tables[0].Rows[0]["Fax"].ToString() != "")) { enterprise.Fax = set.Tables[0].Rows[0]["Fax"].ToString(); } if ((set.Tables[0].Rows[0]["PostCode"] != null) && (set.Tables[0].Rows[0]["PostCode"].ToString() != "")) { enterprise.PostCode = set.Tables[0].Rows[0]["PostCode"].ToString(); } if ((set.Tables[0].Rows[0]["HomePage"] != null) && (set.Tables[0].Rows[0]["HomePage"].ToString() != "")) { enterprise.HomePage = set.Tables[0].Rows[0]["HomePage"].ToString(); } if ((set.Tables[0].Rows[0]["ArtiPerson"] != null) && (set.Tables[0].Rows[0]["ArtiPerson"].ToString() != "")) { enterprise.ArtiPerson = set.Tables[0].Rows[0]["ArtiPerson"].ToString(); } if ((set.Tables[0].Rows[0]["EnteRank"] != null) && (set.Tables[0].Rows[0]["EnteRank"].ToString() != "")) { enterprise.EnteRank = new int?(int.Parse(set.Tables[0].Rows[0]["EnteRank"].ToString())); } if ((set.Tables[0].Rows[0]["EnteClassID"] != null) && (set.Tables[0].Rows[0]["EnteClassID"].ToString() != "")) { enterprise.EnteClassID = new int?(int.Parse(set.Tables[0].Rows[0]["EnteClassID"].ToString())); } if ((set.Tables[0].Rows[0]["CompanyType"] != null) && (set.Tables[0].Rows[0]["CompanyType"].ToString() != "")) { enterprise.CompanyType = new int?(int.Parse(set.Tables[0].Rows[0]["CompanyType"].ToString())); } if ((set.Tables[0].Rows[0]["BusinessLicense"] != null) && (set.Tables[0].Rows[0]["BusinessLicense"].ToString() != "")) { enterprise.BusinessLicense = set.Tables[0].Rows[0]["BusinessLicense"].ToString(); } if ((set.Tables[0].Rows[0]["TaxNumber"] != null) && (set.Tables[0].Rows[0]["TaxNumber"].ToString() != "")) { enterprise.TaxNumber = set.Tables[0].Rows[0]["TaxNumber"].ToString(); } if ((set.Tables[0].Rows[0]["AccountBank"] != null) && (set.Tables[0].Rows[0]["AccountBank"].ToString() != "")) { enterprise.AccountBank = set.Tables[0].Rows[0]["AccountBank"].ToString(); } if ((set.Tables[0].Rows[0]["AccountInfo"] != null) && (set.Tables[0].Rows[0]["AccountInfo"].ToString() != "")) { enterprise.AccountInfo = set.Tables[0].Rows[0]["AccountInfo"].ToString(); } if ((set.Tables[0].Rows[0]["ServicePhone"] != null) && (set.Tables[0].Rows[0]["ServicePhone"].ToString() != "")) { enterprise.ServicePhone = set.Tables[0].Rows[0]["ServicePhone"].ToString(); } if ((set.Tables[0].Rows[0]["QQ"] != null) && (set.Tables[0].Rows[0]["QQ"].ToString() != "")) { enterprise.QQ = set.Tables[0].Rows[0]["QQ"].ToString(); } if ((set.Tables[0].Rows[0]["MSN"] != null) && (set.Tables[0].Rows[0]["MSN"].ToString() != "")) { enterprise.MSN = set.Tables[0].Rows[0]["MSN"].ToString(); } if ((set.Tables[0].Rows[0]["Status"] != null) && (set.Tables[0].Rows[0]["Status"].ToString() != "")) { enterprise.Status = new int?(int.Parse(set.Tables[0].Rows[0]["Status"].ToString())); } if ((set.Tables[0].Rows[0]["CreatedDate"] != null) && (set.Tables[0].Rows[0]["CreatedDate"].ToString() != "")) { enterprise.CreatedDate = new DateTime?(DateTime.Parse(set.Tables[0].Rows[0]["CreatedDate"].ToString())); } if ((set.Tables[0].Rows[0]["CreatedUserID"] != null) && (set.Tables[0].Rows[0]["CreatedUserID"].ToString() != "")) { enterprise.CreatedUserID = new int?(int.Parse(set.Tables[0].Rows[0]["CreatedUserID"].ToString())); } if ((set.Tables[0].Rows[0]["UpdatedDate"] != null) && (set.Tables[0].Rows[0]["UpdatedDate"].ToString() != "")) { enterprise.UpdatedDate = new DateTime?(DateTime.Parse(set.Tables[0].Rows[0]["UpdatedDate"].ToString())); } if ((set.Tables[0].Rows[0]["UpdatedUserID"] != null) && (set.Tables[0].Rows[0]["UpdatedUserID"].ToString() != "")) { enterprise.UpdatedUserID = new int?(int.Parse(set.Tables[0].Rows[0]["UpdatedUserID"].ToString())); } if ((set.Tables[0].Rows[0]["AgentID"] != null) && (set.Tables[0].Rows[0]["AgentID"].ToString() != "")) { enterprise.AgentID = int.Parse(set.Tables[0].Rows[0]["AgentID"].ToString()); } if ((set.Tables[0].Rows[0]["CreatedUserName"] != null) && (set.Tables[0].Rows[0]["CreatedUserName"].ToString() != "")) { enterprise.CreatedUserName = set.Tables[0].Rows[0]["CreatedUserName"].ToString(); } if ((set.Tables[0].Rows[0]["UpdatedUserName"] != null) && (set.Tables[0].Rows[0]["UpdatedUserName"].ToString() != "")) { enterprise.UpdatedUserName = set.Tables[0].Rows[0]["UpdatedUserName"].ToString(); } if ((set.Tables[0].Rows[0]["Balance"] != null) && (set.Tables[0].Rows[0]["Balance"].ToString() != "")) { enterprise.Balance = decimal.Parse(set.Tables[0].Rows[0]["Balance"].ToString()); } return enterprise; }
public List<Maticsoft.Model.Ms.Enterprise> DataTableToList(DataTable dt) { List<Maticsoft.Model.Ms.Enterprise> list = new List<Maticsoft.Model.Ms.Enterprise>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Ms.Enterprise item = new Maticsoft.Model.Ms.Enterprise(); if ((dt.Rows[i]["EnterpriseID"] != null) && (dt.Rows[i]["EnterpriseID"].ToString() != "")) { item.EnterpriseID = int.Parse(dt.Rows[i]["EnterpriseID"].ToString()); } if ((dt.Rows[i]["Name"] != null) && (dt.Rows[i]["Name"].ToString() != "")) { item.Name = dt.Rows[i]["Name"].ToString(); } if ((dt.Rows[i]["Introduction"] != null) && (dt.Rows[i]["Introduction"].ToString() != "")) { item.Introduction = dt.Rows[i]["Introduction"].ToString(); } if ((dt.Rows[i]["RegisteredCapital"] != null) && (dt.Rows[i]["RegisteredCapital"].ToString() != "")) { item.RegisteredCapital = new int?(int.Parse(dt.Rows[i]["RegisteredCapital"].ToString())); } if ((dt.Rows[i]["TelPhone"] != null) && (dt.Rows[i]["TelPhone"].ToString() != "")) { item.TelPhone = dt.Rows[i]["TelPhone"].ToString(); } if ((dt.Rows[i]["CellPhone"] != null) && (dt.Rows[i]["CellPhone"].ToString() != "")) { item.CellPhone = dt.Rows[i]["CellPhone"].ToString(); } if ((dt.Rows[i]["ContactMail"] != null) && (dt.Rows[i]["ContactMail"].ToString() != "")) { item.ContactMail = dt.Rows[i]["ContactMail"].ToString(); } if ((dt.Rows[i]["RegionID"] != null) && (dt.Rows[i]["RegionID"].ToString() != "")) { item.RegionID = new int?(int.Parse(dt.Rows[i]["RegionID"].ToString())); } if ((dt.Rows[i]["Address"] != null) && (dt.Rows[i]["Address"].ToString() != "")) { item.Address = dt.Rows[i]["Address"].ToString(); } if ((dt.Rows[i]["Remark"] != null) && (dt.Rows[i]["Remark"].ToString() != "")) { item.Remark = dt.Rows[i]["Remark"].ToString(); } if ((dt.Rows[i]["Contact"] != null) && (dt.Rows[i]["Contact"].ToString() != "")) { item.Contact = dt.Rows[i]["Contact"].ToString(); } if ((dt.Rows[i]["UserName"] != null) && (dt.Rows[i]["UserName"].ToString() != "")) { item.UserName = dt.Rows[i]["UserName"].ToString(); } if ((dt.Rows[i]["EstablishedDate"] != null) && (dt.Rows[i]["EstablishedDate"].ToString() != "")) { item.EstablishedDate = new DateTime?(DateTime.Parse(dt.Rows[i]["EstablishedDate"].ToString())); } if ((dt.Rows[i]["EstablishedCity"] != null) && (dt.Rows[i]["EstablishedCity"].ToString() != "")) { item.EstablishedCity = new int?(int.Parse(dt.Rows[i]["EstablishedCity"].ToString())); } if ((dt.Rows[i]["LOGO"] != null) && (dt.Rows[i]["LOGO"].ToString() != "")) { item.LOGO = dt.Rows[i]["LOGO"].ToString(); } if ((dt.Rows[i]["Fax"] != null) && (dt.Rows[i]["Fax"].ToString() != "")) { item.Fax = dt.Rows[i]["Fax"].ToString(); } if ((dt.Rows[i]["PostCode"] != null) && (dt.Rows[i]["PostCode"].ToString() != "")) { item.PostCode = dt.Rows[i]["PostCode"].ToString(); } if ((dt.Rows[i]["HomePage"] != null) && (dt.Rows[i]["HomePage"].ToString() != "")) { item.HomePage = dt.Rows[i]["HomePage"].ToString(); } if ((dt.Rows[i]["ArtiPerson"] != null) && (dt.Rows[i]["ArtiPerson"].ToString() != "")) { item.ArtiPerson = dt.Rows[i]["ArtiPerson"].ToString(); } if ((dt.Rows[i]["EnteRank"] != null) && (dt.Rows[i]["EnteRank"].ToString() != "")) { item.EnteRank = new int?(int.Parse(dt.Rows[i]["EnteRank"].ToString())); } if ((dt.Rows[i]["EnteClassID"] != null) && (dt.Rows[i]["EnteClassID"].ToString() != "")) { item.EnteClassID = new int?(int.Parse(dt.Rows[i]["EnteClassID"].ToString())); } if ((dt.Rows[i]["CompanyType"] != null) && (dt.Rows[i]["CompanyType"].ToString() != "")) { item.CompanyType = new int?(int.Parse(dt.Rows[i]["CompanyType"].ToString())); } if ((dt.Rows[i]["BusinessLicense"] != null) && (dt.Rows[i]["BusinessLicense"].ToString() != "")) { item.BusinessLicense = dt.Rows[i]["BusinessLicense"].ToString(); } if ((dt.Rows[i]["TaxNumber"] != null) && (dt.Rows[i]["TaxNumber"].ToString() != "")) { item.TaxNumber = dt.Rows[i]["TaxNumber"].ToString(); } if ((dt.Rows[i]["AccountBank"] != null) && (dt.Rows[i]["AccountBank"].ToString() != "")) { item.AccountBank = dt.Rows[i]["AccountBank"].ToString(); } if ((dt.Rows[i]["AccountInfo"] != null) && (dt.Rows[i]["AccountInfo"].ToString() != "")) { item.AccountInfo = dt.Rows[i]["AccountInfo"].ToString(); } if ((dt.Rows[i]["ServicePhone"] != null) && (dt.Rows[i]["ServicePhone"].ToString() != "")) { item.ServicePhone = dt.Rows[i]["ServicePhone"].ToString(); } if ((dt.Rows[i]["QQ"] != null) && (dt.Rows[i]["QQ"].ToString() != "")) { item.QQ = dt.Rows[i]["QQ"].ToString(); } if ((dt.Rows[i]["MSN"] != null) && (dt.Rows[i]["MSN"].ToString() != "")) { item.MSN = dt.Rows[i]["MSN"].ToString(); } if ((dt.Rows[i]["Status"] != null) && (dt.Rows[i]["Status"].ToString() != "")) { item.Status = new int?(int.Parse(dt.Rows[i]["Status"].ToString())); } if ((dt.Rows[i]["CreatedDate"] != null) && (dt.Rows[i]["CreatedDate"].ToString() != "")) { item.CreatedDate = new DateTime?(DateTime.Parse(dt.Rows[i]["CreatedDate"].ToString())); } if ((dt.Rows[i]["CreatedUserID"] != null) && (dt.Rows[i]["CreatedUserID"].ToString() != "")) { item.CreatedUserID = new int?(int.Parse(dt.Rows[i]["CreatedUserID"].ToString())); } if ((dt.Rows[i]["UpdatedDate"] != null) && (dt.Rows[i]["UpdatedDate"].ToString() != "")) { item.UpdatedDate = new DateTime?(DateTime.Parse(dt.Rows[i]["UpdatedDate"].ToString())); } if ((dt.Rows[i]["UpdatedUserID"] != null) && (dt.Rows[i]["UpdatedUserID"].ToString() != "")) { item.UpdatedUserID = new int?(int.Parse(dt.Rows[i]["UpdatedUserID"].ToString())); } if ((dt.Rows[i]["AgentID"] != null) && (dt.Rows[i]["AgentID"].ToString() != "")) { item.AgentID = int.Parse(dt.Rows[i]["AgentID"].ToString()); } list.Add(item); } } return list; }