Subversion Repository Public Repository

ChrisCompleteCodeTrunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CRMPortal
{
    public partial class SaveCall : System.Web.UI.Page
    {
        public SqlConnection sql = null;
        public ConnectionStringSettings sqlString = ConfigurationManager.ConnectionStrings["actionsql1"];
        public string SalesmanName;
        public DataTable contacts = new DataTable();
        public ArrayList contactList = new ArrayList();
        public bool asa = false;

        protected void Page_Load(object sender, EventArgs e)
        {

            Logic.sqlDisconnect();
            if (!Page.IsPostBack)
            {
                custNameDiv.InnerHtml = Request.Params["custName"];
                CID.Value = Request.Params["cid"];
                UID.Value = Request.Params["uid"];
                PREV.Value = Request.Params["prev"];
                ViewState["CID"] = Request.Params["cid"];
                ViewState["UID"] = Request.Params["uid"];
                ViewState["CMD"] = Request.Params["cmd"];
                ddTimeUsed.Items.Clear();
                ddTimeUsed.Items.Add("");
                tbCallDate.Attributes.Add("readonly", "readonly");
                foreach (string s in Logic.GetEntryTypes())
                    ddTimeUsed.Items.Add(s);
            }
            if (ViewState["CMD"].Equals("customer")) asa = true;

            queryContacts();

            if (!Page.IsPostBack)
            {
                ddContacts.DataSource = contactList;
                ddContacts.DataBind();
            }

            SalesmanName = Logic.getNAMEfromSPID((string)ViewState["UID"]);

        }

        protected void ddTimeUsed_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!ddTimeUsed.SelectedItem.Equals(""))
                btnSave.Visible = true;
            else
                btnSave.Visible = false;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (ddTimeUsed.SelectedItem.Equals("") || ddTimeUsed.SelectedIndex == 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "DataError", "ShowError('Error', 'Please select what the time was used for on this call.');", true);
                return;
            }

            if (tbContactName.Text.Equals(""))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "DataError", "ShowError('Error', 'Please enter a contact for this call.');", true);
                return;
            }

            if (cbAppointment.Checked)
            {
                CultureInfo ci = new CultureInfo("en-US");
                DateTime when = new DateTime();
                try
                {
                    if (!tbCallDate.Text.Equals(""))
                    {
                        when = DateTime.Parse(tbCallDate.Text, ci);
                    }
                    if (when.Year < 2000 || when.Year > 2050)
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "FollowupDateError", "ShowError('Invalid Followup Date', 'Followup date is incorrect. Please select another date.');", true);
                        tbCallDate.Text = "";
                        return;
                    }
                }
                catch
                {
                    try
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "FollowupDateError", "ShowError('Invalid Followup Date', 'Followup date is incorrect. Please select another date.');", true);
                        return;
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("PostExec: " + ex.Message);
                    }
                    return;
                }
                Thread.Sleep(100);
                EWS ews = new EWS();
                System.Threading.Thread.Sleep(100);
                ews.makeCallAppointment(Request.LogonUserIdentity.User, System.Web.HttpUtility.HtmlDecode(custNameDiv.InnerHtml), "Contact: " + tbContactName.Text + "   Phone: " + tbContactPhone.Text, when);
                Logic.saveNote("SALES CALL FOLLOWUP APPOINTMENT CREATED FOR " + SalesmanName + " ON " + when.ToShortDateString(), CID.Value, SalesmanName, "Appointment", asa);
            }



            Logic.saveCall(tbNote.Text, int.Parse(ViewState["UID"].ToString()), int.Parse(ViewState["CID"].ToString()), tbContactName.Text, tbContactPhone.Text, ddTimeUsed.SelectedItem.ToString(), DateTime.Now, asa);



            Response.Redirect(PREV.Value);
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect(PREV.Value);
        }

        public DataTable GetCustomer()
        {
            sqlConnect();
            string query = "";
            if (asa)
                query = "SELECT TOP 1 * FROM Customers WHERE ASAID = '" + ViewState["CID"] + "'";
            else
                query = "SELECT TOP 1 * FROM Prospects WHERE ID = '" + ViewState["CID"] + "'";
            SqlCommand cmd = new SqlCommand(query, sql);
            SqlDataReader reader = cmd.ExecuteReader();
            DataTable cust = new DataTable();
            cust.Load(reader);
            reader.Close();
            sqlDisconnect();
            return cust;
        }

        public void queryContacts()
        {
            DataTable cust = GetCustomer();
            if (cust.Rows.Count == 0 && asa)
            {
                Logic.convertASAtoCUST((string)ViewState["CID"]);
                cust = GetCustomer();
            }

            contacts = new DataTable();
            contacts.Columns.Add(new DataColumn("Name", "".GetType()));
            contacts.Columns.Add(new DataColumn("Phone", "".GetType()));

            DataRow c1 = contacts.NewRow();
            c1["Name"] = cust.Rows[0]["ContactName"].ToString();
            c1["Phone"] = cust.Rows[0]["ContactNumber"].ToString();
            c1["CellPhone"] = cust.Rows[0]["ContactCellNumber"].ToString();

            DataRow c2 = contacts.NewRow();
            c2["Name"] = cust.Rows[0]["Contact2Name"].ToString();
            c2["Phone"] = cust.Rows[0]["Contact2Number"].ToString();
            c2["CellPhone"] = cust.Rows[0]["Contact2CellNumber"].ToString();

            DataRow c3 = contacts.NewRow();
            c3["Name"] = cust.Rows[0]["Contact3Name"].ToString();
            c3["Phone"] = cust.Rows[0]["Contact3Number"].ToString();
            c3["CellPhone"] = cust.Rows[0]["Contact3CellNumber"].ToString();

            contacts.Rows.Add(c1);
            contacts.Rows.Add(c2);
            contacts.Rows.Add(c3);

            contactList.Clear();
            contactList.Add("Select a Contact");
            contactList.Add(c1["Name"]);
            contactList.Add(c2["Name"]);
            contactList.Add(c3["Name"]);
        }

        public void sqlConnect()
        {
            sql = new SqlConnection(sqlString.ConnectionString);
            sql.Open();
        }

        public void sqlDisconnect()
        {
            try
            {
                sql.Close();
            }
            catch { }
        }

        protected void ddContacts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddContacts.SelectedIndex == 0)
            {

            }
            else
            {
                tbContactName.Text = contacts.Rows[ddContacts.SelectedIndex - 1]["Name"].ToString();
                tbContactPhone.Text = contacts.Rows[ddContacts.SelectedIndex - 1]["Phone"].ToString();
            }
        }

        protected void btnSaveFollowup_Click(object sender, EventArgs e)
        {


        }
    }
}

Commits for ChrisCompleteCodeTrunk/ATCCRMPortal/CRMPortal/SaveCall.aspx.cs

Diff revisions: vs.
Revision Author Commited Message
1 BBDSCHRIS picture BBDSCHRIS Wed 22 Aug, 2018 20:08:03 +0000