protected void btnSave_Click(object sender, EventArgs e) { Maticsoft.Model.MailConfig model = new Maticsoft.Model.MailConfig(); model.Mailaddress = txtMailaddress.Text; model.Password = txtPassword.Text; model.POPPort = Convert.ToInt32(txtPOPPort.Text); model.POPServer = txtPOPServer.Text; model.POPSSL = chkPOPSSL.Checked; model.SMTPPort = Convert.ToInt32(txtSMTPPort.Text); model.SMTPServer = txtSMTPServer.Text; model.SMTPSSL = chkSMTPSSL.Checked; model.Username = txtUsername.Text; if (Session["UserInfo"] != null) { User currentUser = (User)Session["UserInfo"]; model.UserID = currentUser.UserID; } Maticsoft.BLL.MailConfig bll = new Maticsoft.BLL.MailConfig(); if (!bll.Exists(model.UserID, model.Mailaddress)) { bll.Add(model); Response.Redirect("mailconfiglist.aspx"); } else { lblInfo.Visible = true; lblInfo.Text = "This account already exists"; } }
/// <summary> /// /// </summary> public List<Maticsoft.Model.MailConfig> DataTableToList(DataTable dt) { List<Maticsoft.Model.MailConfig> modelList = new List<Maticsoft.Model.MailConfig>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Maticsoft.Model.MailConfig model; for (int n = 0; n < rowsCount; n++) { model = new Maticsoft.Model.MailConfig(); if (dt.Rows[n]["ID"].ToString() != "") { model.ID = int.Parse(dt.Rows[n]["ID"].ToString()); } if (dt.Rows[n]["UserID"].ToString() != "") { model.UserID = int.Parse(dt.Rows[n]["UserID"].ToString()); } model.Mailaddress = dt.Rows[n]["Mailaddress"].ToString(); model.Username = dt.Rows[n]["Username"].ToString(); model.Password = dt.Rows[n]["Password"].ToString(); model.SMTPServer = dt.Rows[n]["SMTPServer"].ToString(); if (dt.Rows[n]["SMTPPort"].ToString() != "") { model.SMTPPort = int.Parse(dt.Rows[n]["SMTPPort"].ToString()); } if (dt.Rows[n]["SMTPSSL"].ToString() != "") { model.SMTPSSL = dt.Rows[n]["SMTPSSL"].ToString() == "1" ? true : false; } model.POPServer = dt.Rows[n]["POPServer"].ToString(); if (dt.Rows[n]["POPPort"].ToString() != "") { model.POPPort = int.Parse(dt.Rows[n]["POPPort"].ToString()); } if (dt.Rows[n]["POPSSL"].ToString() != "") { model.POPSSL = dt.Rows[n]["POPSSL"].ToString() == "1" ? true : false; } modelList.Add(model); } } return modelList; }
/// <summary> /// /// </summary> public Maticsoft.Model.MailConfig GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,UserID,Mailaddress,Username,Password,SMTPServer,SMTPPort,SMTPSSL,POPServer,POPPort,POPSSL from Accounts_MailConfig "); strSql.Append(" where ID=@ID "); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4)}; parameters[0].Value = ID; Maticsoft.Model.MailConfig model = new Maticsoft.Model.MailConfig(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["UserID"].ToString() != "") { model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString()); } model.Mailaddress = ds.Tables[0].Rows[0]["Mailaddress"].ToString(); model.Username = ds.Tables[0].Rows[0]["Username"].ToString(); model.Password = ds.Tables[0].Rows[0]["Password"].ToString(); model.SMTPServer = ds.Tables[0].Rows[0]["SMTPServer"].ToString(); if (ds.Tables[0].Rows[0]["SMTPPort"].ToString() != "") { model.SMTPPort = int.Parse(ds.Tables[0].Rows[0]["SMTPPort"].ToString()); } if (ds.Tables[0].Rows[0]["SMTPSSL"].ToString() != "") { model.SMTPSSL = ds.Tables[0].Rows[0]["SMTPSSL"].ToString() == "1" ? true : false; } model.POPServer = ds.Tables[0].Rows[0]["POPServer"].ToString(); if (ds.Tables[0].Rows[0]["POPPort"].ToString() != "") { model.POPPort = int.Parse(ds.Tables[0].Rows[0]["POPPort"].ToString()); } if (ds.Tables[0].Rows[0]["POPSSL"].ToString() != "") { model.POPSSL = ds.Tables[0].Rows[0]["POPSSL"].ToString() == "1" ? true : false; } return model; } else { return null; } }