· 7 years ago · Apr 09, 2018, 04:06 PM
1protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
2 {
3 grid.EditIndex = e.NewEditIndex;
4 grid.DataBind();
5 }
6
7protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
8{
9 grid.EditIndex = e.NewEditIndex;
10 grid.DataSource = GetDataSource();
11 grid.DataBind();
12}
13
14protected void gridview_RowEditing(object sender, GridViewEditEventArgs e)
15{
16 gridview.EditIndex = e.NewEditIndex;
17 Loadyourgridfunction();
18}
19loadyourgridfunction()
20{
21 gridview.datasource= dataset;
22 gridview.databind();
23}
24
25public static class CommonFunctions
26{
27 # region "Variable Declaration"
28
29 static string LOG_FILE = AppDomain.CurrentDomain.BaseDirectory + "Cachecallback.txt";
30
31 #endregion
32
33 #region "Functions"
34 public static string RadioButtonChecked(RadioButton RbYes, RadioButton RbNo)
35 {
36 string strStatus = "";
37 if (RbYes.Checked == true)
38 {
39 strStatus = "Yes";
40
41 }
42 if (RbNo.Checked == true)
43 {
44 strStatus = "No";
45 }
46 return strStatus;
47 }
48 public static string Encrypt(string TextToBeEncrypted)
49 {
50 RijndaelManaged RijndaelCipher = new RijndaelManaged();
51 string Password = "CSC";
52 byte[] PlainText = System.Text.Encoding.Unicode.GetBytes(TextToBeEncrypted);
53 byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
54 PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
55 //Creates a symmetric encryptor object.
56 ICryptoTransform Encryptor = RijndaelCipher.CreateEncryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
57 MemoryStream memoryStream = new MemoryStream();
58 //Defines a stream that links data streams to cryptographic transformations
59 CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, CryptoStreamMode.Write);
60 cryptoStream.Write(PlainText, 0, PlainText.Length);
61 //Writes the final state and clears the buffer
62 cryptoStream.FlushFinalBlock();
63 byte[] CipherBytes = memoryStream.ToArray();
64 memoryStream.Close();
65 cryptoStream.Close();
66 string EncryptedData = Convert.ToBase64String(CipherBytes);
67 EncryptedData = EncryptedData.Replace("+", "*plus*").Replace("&", "*amp*");
68 return EncryptedData;
69
70 }
71
72
73 public static int DeletedTotalDre(string strTableName, string strColumnName, string Value, SqlTransaction SqlTra, SqlConnection Con)
74 {
75 ExecuteProcedures EX = new ExecuteProcedures(3, MasterCommonStrings.ConnectionString);
76 EX.Parameters.Add("@TableName", SqlDbType.VarChar, 8000, strTableName);
77 EX.Parameters.Add("@ColumnName", SqlDbType.VarChar, 8000, strColumnName);
78 EX.Parameters.Add("@ColumnValue", SqlDbType.VarChar, 8000, Value);
79 int i = Convert.ToInt32(EX.InvokeProcedure("Proc_Erp_Trn_Deleted_Transction_Total_Dre", SqlTra, ValueDataType.Number, Con));
80 return i;
81
82 }
83
84 public static bool Ischecked(CheckBox Chkbox)
85 {
86 bool Status = false;
87 if (Chkbox.Checked == true)
88 {
89 Status = true;
90 }
91 else
92 {
93 Status = false;
94 }
95 return Status;
96 }
97 public static string Decrypt(string TextToBeDecrypted)
98 {
99 RijndaelManaged RijndaelCipher = new RijndaelManaged();
100 string Password = "CSC";
101 byte[] EncryptedData = Convert.FromBase64String(TextToBeDecrypted.Replace("*plus*", "+").Replace("*amp*", "&"));
102 byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
103 //Making of the key for decryption
104 PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
105 //Creates a symmetric Rijndael decryptor object.
106 ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
107 MemoryStream memoryStream = new MemoryStream(EncryptedData);
108 //Defines the cryptographics stream for decryption.THe stream contains decrpted data
109 CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
110 byte[] PlainText = new byte[EncryptedData.Length];
111 int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
112 memoryStream.Close();
113 cryptoStream.Close();
114 //Converting to string
115 string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
116 DecryptedData = DecryptedData;
117 return DecryptedData;
118 }
119 public static void Enable_Btn_For_Add(Button btnAdd,Button btnCancel,Button btnDelete,Button btnEdit,Button btnUpdate,Button btnexit,Button btnfind,Button btnprint)
120 {
121 btnAdd.Enabled = true;
122 btnEdit.Enabled = true;
123 btnexit.Enabled = true;
124 btnfind.Enabled = true;
125 btnUpdate.Enabled = false;
126 btnDelete.Enabled = false;
127 btnCancel.Enabled = false;
128 btnprint.Enabled = false;
129
130
131 }
132 public static void Enable_Btn_For_Find(Button btnAdd, Button btnCancel, Button btnDelete, Button btnEdit, Button btnUpdate, Button btnexit, Button btnfind, Button btnprint)
133 {
134 btnAdd.Enabled = false ;
135 btnEdit.Enabled = true;
136 btnexit.Enabled = true;
137 btnfind.Enabled = true;
138 btnUpdate.Enabled = false;
139 btnDelete.Enabled = true;
140 btnCancel.Enabled = true;
141 btnprint.Enabled = true ;
142
143 }
144 public static void Enable_Btn_Audit(Button btnAdd, Button btnCancel, Button btnDelete, Button btnEdit, Button btnUpdate, Button btnexit, Button btnfind, Button btnprint)
145 {
146 btnAdd.Visible = false;
147 btnEdit.Visible = false;
148 btnexit.Visible = false;
149 btnfind.Visible = false;
150 btnUpdate.Visible = false;
151 btnDelete.Visible = false;
152 btnCancel.Visible = false;
153 btnprint.Visible = false;
154
155 }
156 public static void Enable_Btn_For_Update(Button btnAdd, Button btnCancel, Button btnDelete, Button btnEdit, Button btnUpdate, Button btnexit, Button btnfind)
157 {
158 btnEdit.Enabled = false;
159 btnAdd.Enabled = true;
160 btnfind.Enabled = true;
161 btnUpdate.Enabled = false;
162 btnDelete.Enabled = false;
163 btnCancel.Enabled = false;
164 btnexit.Enabled = true;
165
166
167 }
168 public static void Enable_Btn_For_Find(Button btnAdd, Button btnCancel, Button btnDelete, Button btnEdit, Button btnUpdate, Button btnexit, Button btnfind)
169 {
170 btnAdd.Enabled = true;
171 btnEdit.Enabled = true;
172 btnexit.Enabled = true;
173 btnfind.Enabled = true;
174 btnUpdate.Enabled = false;
175 btnDelete.Enabled = true;
176 btnCancel.Enabled = true;
177
178 }
179 public static void Enable_Btn_For_Edit(Button btnAdd, Button btnCancel, Button btnDelete, Button btnEdit, Button btnUpdate, Button btnexit, Button btnfind)
180 {
181 btnEdit.Enabled = false;
182 btnAdd.Enabled = false;
183 btnfind.Enabled = true;
184 btnUpdate.Enabled = true;
185 btnDelete.Enabled = true;
186 btnCancel.Enabled = true;
187 btnexit.Enabled = true;
188
189
190 }
191
192 public static string UploadFile(FileUpload fp,string DisplayPrefixPath,string PrefixPath)
193 {
194 string image1="";
195
196 if (fp.HasFile)
197 {
198 image1 = GetUniqueKeys() + DateTime.Now.ToString("ddMMMyyyyHHmmss") + Path.GetExtension(fp.FileName).ToString(); //Session.ses Path.GetFileName(fp.FileName).ToString();
199 fp.SaveAs(HttpContext.Current.Server.MapPath(PrefixPath + image1));
200 image1 = DisplayPrefixPath + image1;
201 }
202
203 return image1;
204 }
205
206 public static string UploadFile(FileUpload fp, string PrefixPath)
207 {
208 string image1 = "";
209
210 if (fp.HasFile)
211 {
212 image1 = GetUniqueKeys() + DateTime.Now.ToString("ddMMMyyyyHHmmss") + Path.GetExtension(fp.FileName).ToString(); //Session.ses Path.GetFileName(fp.FileName).ToString();
213 fp.SaveAs(HttpContext.Current.Server.MapPath(PrefixPath + image1));
214 image1 = PrefixPath + image1;
215 }
216
217 return image1;
218 }
219
220 public static bool DeleteFile(string FilePath)
221 {
222 FileInfo fp = null;
223
224 try
225 {
226 fp = new FileInfo(HttpContext.Current.Server.MapPath(FilePath));
227 if (fp.Exists == true)
228 {
229 fp.Delete();
230 }
231 return true;
232 }
233 catch
234 {
235 return false;
236 }
237 finally
238 {
239 fp = null;
240 }
241 }
242
243 public static string[] SplitString(string StringToSplit,SplitChar Char)
244 {
245 string[] arr;
246 char Split;
247 switch (Char)
248 {
249 case SplitChar.Comma:
250 Split = (char)44;
251 break;
252
253 case SplitChar.SemiColon:
254 Split = (char)59;
255 break;
256
257 case SplitChar.BackSlash:
258 Split = (char)92;
259 break;
260
261 case SplitChar.FrontSlash:
262 Split = (char)47;
263 break;
264
265 case SplitChar.Dot:
266 Split = (char)46;
267 break;
268
269 case SplitChar.Colon:
270 Split = (char)58;
271 break;
272
273 default :
274 Split = (char)44;
275 break;
276 }
277 arr = StringToSplit.Split(Split);
278 return arr;
279 }
280
281 public static string GetUniqueKeys()
282 {
283 int maxSize = 8;
284
285 char[] chars = new char[62];
286 string a;
287 a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
288 chars = a.ToCharArray();
289 int size = maxSize;
290 byte[] data = new byte[1];
291 RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider();
292 crypto.GetNonZeroBytes(data);
293 size = maxSize;
294 data = new byte[size];
295 crypto.GetNonZeroBytes(data);
296 StringBuilder result = new StringBuilder(size);
297 foreach (byte b in data)
298 { result.Append(chars[b % (chars.Length - 1)]); }
299 return result.ToString();
300 }
301
302 public static string EncodeHTML(string HTML)
303 {
304 return HttpUtility.HtmlEncode(HTML);
305 }
306
307 public static string DecodeHTML(string HTML)
308 {
309 return HttpUtility.HtmlDecode(HTML);
310 }
311
312 public static object GetDbNull(string strValue)
313 {
314 if (strValue == "")
315 {
316 return DBNull.Value;
317 }
318 else
319 {
320 return strValue;
321 }
322 }
323
324 public static string Format_Date(string Date)
325 {
326 string strDate = "";
327 if (Date != "")
328 {
329 try
330 {
331 strDate = Convert.ToDateTime(Date).ToString("dd/MMM/yyyy");
332 }
333 catch
334 {
335
336 }
337 }
338 return strDate;
339 }
340
341 public static string Get_Date_Change(string Date)
342 {
343 string strDate = "";
344 if (Date != "")
345 {
346 try
347 {
348 strDate = Convert.ToDateTime(Date).ToString("dd/MM/yyyy");
349 }
350 catch
351 {
352
353 }
354 }
355 return strDate;
356 }
357
358 public static string Convert_MM_DD_YYYY(string Box) //===BY Yogesh Bodke
359 {
360 string str = Box;
361 string mm, dd, yy;
362
363 int len = Box.Length;
364
365 if (len == 10)
366 {
367 string[] str1 = str.Split(new Char[] { '/' });
368 dd = str1[0];
369 mm = str1[1];
370 yy = str1[2];
371 Box = mm + "/" + dd + "/" + yy;
372 // DateTime bb = Convert.ToDateTime(Box);
373 }
374 return Box;
375
376 }
377 public static string Get_Date_Change_New(string Date)
378 {
379 string strDate = Date.Substring(3, 2) + "/" + Date.Substring(0, 2) +"/"+ Date.Substring(6, 4);
380 if (Date != "")
381 {
382 try
383 {
384 strDate = Convert.ToDateTime(strDate).ToString("MM/dd/yyyy");
385
386 }
387 catch
388 {
389
390 }
391 }
392 return strDate;