-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
338 lines (309 loc) · 16.5 KB
/
Program.cs
File metadata and controls
338 lines (309 loc) · 16.5 KB
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Globalization;
using TaavoniUT3SMSManager.Model;
using System.Runtime.InteropServices;
namespace TaavoniUT3SMSManager
{
class Program
{
static Thread mRecievrThread;
static TaavoniUT3SMSManager.Model.DatabaseDataContext m_model = new Model.DatabaseDataContext();
static String signature = "تعاونی شماره 3 کارکنان دانشگاه تهران";
static void Main(string[] args)
{
// Console.WriteLine(GetUserPayment(Guid.Parse("2756e071-03c5-47cd-ad93-f51bff32b3d1")).Item2);
mRecievrThread = new Thread(() => { ThreadHandler(); });
new Thread(() => { CalcUserRanks(); }).Start();
mRecievrThread.Start();
mRecievrThread.Join();
//GetRankList();
}
public static void GetRankList()
{
try
{
{
var unsortRankList = (from p in m_model.MembersProfiles
select new
{
FirstName = p.FirstName,
LastName = p.LastName,
userId = p.MemberID,
NationalityCode = p.InternationalCode,
Point = CalculateUserPoint((Guid)p.MemberID)
}).ToList();
var rankList = unsortRankList.OrderByDescending(P => P.Point);
List<RankModel> Result = new List<RankModel>();
for (int i = 0; i < rankList.Count(); i++)
{
var x = rankList.ElementAt(i);
Result.Add(new RankModel
{
FirstName = x.FirstName,
LastName = x.LastName,
UserId = (Guid)x.userId,
UserName = x.NationalityCode,
Point = x.Point,
Rank = i + 1
});
}
foreach (var x in Result)
Console.WriteLine(x.UserName + " : " + x.Point + " : " + x.Rank);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static void CalcUserRanks()
{
while (true)
{
try
{
foreach (var x in m_model.MembersProfiles)
{
if (x.IsDisabled == null || x.IsDisabled == false)
{
x.Point = double.Parse(String.Format("{0}", CalculateUserPoint((Guid)x.MemberID)));
}
else
{
x.Point = 0.0;
}
}
m_model.SubmitChanges();
var rankList = m_model.MembersProfiles.OrderByDescending(P => P.Point);
int index = 0;
foreach (var x in rankList)
{
x.Rank = index;
index++;
}
m_model.SubmitChanges();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Thread.Sleep(30000);
}
}
}
static void ThreadHandler()
{
while (true)
{
try
{
var messages = Utility.SMS.GetFarapayamakMessages(SMSProfile.UserName, SMSProfile.Password, SMSProfile.Number);
if (messages != null)
{
foreach (var msg in messages)
{
Console.WriteLine("From : " + msg.Sender);
Console.WriteLine("Msg : " + msg.Body);
Console.WriteLine("Date : " + msg.SendDate);
if (m_model.MemberContacts.Count(P => P.MobilePhone.Contains(msg.Sender)) > 0)
{
if (msg.Body.Contains("1"))
{
var users = m_model.MemberContacts.Where(P => P.MobilePhone.Contains(msg.Sender));
foreach (Model.MemberContact u in users)
{
var user = m_model.MembersProfiles.Single(P => P.MemberID.Equals(u.MemberID));
var point = CalculateUserPoint((Guid)u.MemberID);
var rank = GetRankForUser((Guid)u.MemberID);
var result = "عضو محترم " + user.FirstName + " " + user.LastName + " " + "امتیاز شما تا به امروز " + point + " و رتبه شما " + rank + " می باشد.";
result += signature;
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
}
else if (msg.Body.Contains("2"))
{
var users = m_model.MemberContacts.Where(P => P.MobilePhone.Contains(msg.Sender));
foreach (Model.MemberContact u in users)
{
var user = m_model.MembersProfiles.Single(P => P.MemberID.Equals(u.MemberID));
var point = GetUserPayment((Guid)u.MemberID).Item2;
var count = GetUserPayment((Guid)u.MemberID).Item1;
var result = "عضو محترم " + user.FirstName + " " + user.LastName + " " + "پرداخت شما تا به امروز " + point + " و تعداد دفعات پرداخت " + count + " می باشد.";
result += signature;
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
}
else if (msg.Body.Contains("3"))
{
var Result = "تلفن 88966770 و 88966849 " + "\r\n";
Result += "ایمیل: taavoniut3@ut.ac.ir \r\n";
Result += "نشانی وبلاگ: taavoniut3.blogfa.ir \r\n";
Result += "پایگاه اطلاع رسانی: taavoniut3.ir \r\n";
Result += signature;
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, Result, SMSProfile.Number, smsProvider);
}
else if (msg.Body.Contains("4"))
{
var result = "";
result += "نشانی تعاونی: بلوار کشاورز، خیابان وصال، کوچه شاهد، پلاک 8، طبقه دوم. \r\n";
result += "نشانی پروژه: اتوبان تهران- کرج، اتوبان آزادگان شمال، کوهک، نسیم شانزدهم، جنب پروژه آفتاب 22 مجلس شورای اسلامی \r\n";
result += signature;
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
else if (msg.Body.Contains("5"))
{
var result = "(شماره حساب 135718548 و حساب شبای 520180000000000135718548 نزد بانک تجارت شعبه اردیبهشت، کد 187";
result += signature;
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
else if (msg.Body.Contains("6"))
{
var result = "مشخصات مدیرعامل تعاونی: محمود حدادیان، به شماره همر ه 09194458649" + "و ایمیل mhaddadi@ut.ac.ir";
result += signature;
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
else
{
var result = "راهنمای پیامک : \r\n";
result += "1.آگاهی از امتیاز و رتبه عضو\r\n";
result += "2.جمع پرداخت و دفعات واریز.\r\n";
result += "3.اطلاعات تماس با تعاونی\r\n";
result += "4.نشانی پروژه و نشانی تعاونی \r\n";
result += "5.شماره حساب تعاونی و شبای آن \r\n";
result += "6. نام مدیرعامل و شماره همراه آن \r\n";
result += "برای استفاده از هر منو شماره ردیف آن را به همین شماره پیامک کنید";
TaavoniUT3SMSManager.Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
}
else
{
var result = "شما از اعضای تعاونی نمیباشید. برای عضویت با شماره 88966770 تماس حاصل فرمایید. تعاونی شماره 3 کارکنان دانشگاه تهران";
Utility.SMS.SendSMS(msg.Sender, SMSProfile.UserName, SMSProfile.Password, result, SMSProfile.Number, smsProvider);
}
}
System.Threading.Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
public static int GetRankForUser(Guid userId)
{
System.Globalization.PersianCalendar jc = new System.Globalization.PersianCalendar();
String tempdate = jc.GetYear((DateTime)DateTime.Now) + ":" + jc.GetMonth((DateTime)DateTime.Now) + ":" + jc.GetDayOfMonth((DateTime)DateTime.Now);
var unsortRankList = (from p in m_model.MembersProfiles
select new
{
FirstName = p.FirstName,
LastName = p.LastName,
userId = p.MemberID,
NationalityCode = p.InternationalCode,
Point = CalculateUserPoint((Guid)p.MemberID),
Date = p.CreateDate != null ? p.CreateDate : tempdate,
IsApproved = p.aspnet_User.aspnet_Membership.IsApproved
}).ToList();
var rankList = unsortRankList.OrderByDescending(P => P.Point);
List<RankModel> Result = new List<RankModel>();
for (int i = 0; i < rankList.Count(); i++)
{
var x = rankList.ElementAt(i);
Result.Add(new RankModel
{
FirstName = x.FirstName,
LastName = x.LastName,
UserId = (Guid)x.userId,
UserName = x.NationalityCode,
Point = x.Point,
Rank = i + 1,
IsApproved = x.IsApproved,
Date = x.Date
});
}
return Result.Single(P => P.UserId.Equals(userId)).Rank;
}
private static double CalculateUserPoint(Guid userId)
{
TaavoniUT3SMSManager.Model.Payment p = new Model.Payment();
try
{
double result = 0;
if (m_model.Payments.Count(P => P.MemberID.Equals(userId)) <= 0)
{
result = 0;
return result;
}
else
{
var payments = m_model.Payments.Where(P => P.MemberID.Equals(userId));
PersianCalendar persian = new PersianCalendar();
foreach (var x in payments)
{
p = x;
String[] dates = x.DateOfPayment.Split(new char[] { '/' });
DateTime tempDateTime = new DateTime(int.Parse(dates[0]), int.Parse(dates[1]), int.Parse(dates[2]), persian);
DateTime tempNowDate = GetPersianDateInstance(DateTime.Now);
double days = (tempNowDate - tempDateTime).TotalDays;
double moneyWeight = double.Parse(x.Fee) / 100000.0;
result += days * moneyWeight;
}
return Math.Round(result / 100.00, 2); ;
}
}
catch (Exception ex)
{
Console.WriteLine(p.ID);
return 0;
}
}
private static Tuple<int, double> GetUserPayment(Guid userId)
{
try
{
Tuple<int, double> result = Tuple.Create(0, 0.0);
if (m_model.Payments.Count(P => P.MemberID.Equals(userId)) <= 0)
{
return result;
}
else
{
var payments = m_model.Payments.Where(P => P.MemberID.Equals(userId));
double tmpResult = 0;
foreach (var x in payments)
{
String[] dates = x.DateOfPayment.Split(new char[] { '/' });
DateTime tempDateTime = new DateTime(int.Parse(dates[0]), int.Parse(dates[1]), int.Parse(dates[2]));
DateTime tempNowDate = GetPersianDateInstance(DateTime.Now);
tmpResult += double.Parse(x.Fee);
}
return new Tuple<int, double>(payments.Count(), tmpResult);
}
}
catch (Exception ex)
{
return Tuple.Create(0, 0.0);
}
}
public static String GetPersianDate(DateTime now)
{
System.Globalization.PersianCalendar jc = new System.Globalization.PersianCalendar();
String tempdate = jc.GetYear(now) + ":" + jc.GetMonth(now) + ":" + jc.GetDayOfMonth(now);
return tempdate;
}
public static DateTime GetPersianDateInstance(DateTime now)
{
System.Globalization.PersianCalendar jc = new System.Globalization.PersianCalendar();
String tempdate = jc.GetYear(now) + ":" + jc.GetMonth(now) + ":" + jc.GetDayOfMonth(now);
return new DateTime(jc.GetYear(now), jc.GetMonth(now), jc.GetDayOfMonth(now), jc);
}
public static string smsProvider = "FARAPAYAMAK";
}
}