Convert
How do I use Convert
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: ClassBLL.cs
Copy
213 public string TinhDiemTB(string MaSV, string MaHK)
214 {
215 SqlConnection con = da.GetConnect();
216 con.Open();
217 //view tc
218 string sql1 = " select 'sotinchi'=sum(SoTC) " +
219 " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
220 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD and MaSV='"+MaSV+"' and MaHK='"+MaHK+"' " +
221 " group by MaSV ";
222 SqlCommand cmd1 = new SqlCommand(sql1, con);
223 string tc = cmd1.ExecuteScalar().ToString();
224 // view diem10
225 string sql2 = " select 'cuoiky'=sum(DiemTk10*SoTC) " +
226 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
227 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='"+MaSV+"' and MaHK='"+MaHK+"' " +
228 " group by MaSV ";
229 SqlCommand cmd2 = new SqlCommand(sql2, con);
230 string diem10 = cmd2.ExecuteScalar().ToString();
231 //view diem4
232 string sql3 = " select 'cuoiky'=sum(DiemTk4*SoTC) " +
233 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
234 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='"+MaSV+"' and MaHK='"+MaHK+"' " +
235 " group by MaSV ";
236 SqlCommand cmd3 = new SqlCommand(sql3, con);
237 string diem4 = cmd3.ExecuteScalar().ToString();
238
239
240 string ketqua="";
241 ketqua = Convert.ToDouble(diem10) / Convert.ToDouble(tc) + "," + Convert.ToDouble(diem4) / Convert.ToDouble(tc) ;
242 return ketqua;
243 }
File name: ClassBLL.cs
Copy
244 public string TinhDiemTB(string MaSV)
245 {
246 SqlConnection con = da.GetConnect();
247 con.Open();
248 //view tc
249 string sql1 = " select 'sotinchi'=sum(SoTC) " +
250 " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
251 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD and MaSV='" + MaSV + "'" +
252 " group by MaSV ";
253 SqlCommand cmd1 = new SqlCommand(sql1, con);
254 string tc = cmd1.ExecuteScalar().ToString();
255 // view diem10
256 string sql2 = " select 'cuoiky'=sum(DiemTk10*SoTC) " +
257 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
258 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='" + MaSV + "'" +
259 " group by MaSV ";
260 SqlCommand cmd2 = new SqlCommand(sql2, con);
261 string diem10 = cmd2.ExecuteScalar().ToString();
262 //view diem4
263 string sql3 = " select 'cuoiky'=sum(DiemTk4*SoTC) " +
264 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
265 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='" + MaSV + "'" +
266 " group by MaSV ";
267 SqlCommand cmd3 = new SqlCommand(sql3, con);
268 string diem4 = cmd3.ExecuteScalar().ToString();
269
270
271 string ketqua = "";
272 ketqua = Convert.ToDouble(diem10) / Convert.ToDouble(tc) + "," + Convert.ToDouble(diem4) / Convert.ToDouble(tc);
273 return ketqua;
274 }
File name: FormHocPhan.cs
Copy
25 private void btnThem_Click(object sender, EventArgs e)
26 {
27 if (txtMaHP.Text != "")
28 {
29 if (business.Proc_Insert("Insert_HocPhan", txtMaHP.Text))
30 {
31 string sql = "'" + txtMaHP.Text + "','" + txtTenHP.Text + "'," + Convert.ToInt32(txtSoTC.Text) + "," + Convert.ToInt32(txtSoTietTH.Text) + "," + Convert.ToInt32(txtSoTietLT.Text) + "," + Convert.ToInt32(txtPhanTramDQT.Text) + "," + Convert.ToInt32(txtPhanTramDT.Text) + "";
32 business.Insert("HocPhan",sql);
33 FormHocPhan_Load(sender,e);
34 }
35 else
36 {
37 MessageBox.Show("Mã Học Phần đã tồn tại");
38 }
39 }
40 }
File name: FormHocPhan.cs
Copy
53 private void btnSua_Click(object sender, EventArgs e)
54 {
55 string sql = "TenHP='" + txtTenHP.Text + "',SoTC=" + Convert.ToInt32(txtSoTC.Text) + ",SoTietTH=" + Convert.ToInt32(txtSoTietTH.Text) + ",SoTietLT=" + Convert.ToInt32(txtSoTietLT.Text) + ",PhanTramDQT=" + Convert.ToInt32(txtPhanTramDQT.Text) + ",PhanTramDT=" + Convert.ToInt32(txtPhanTramDT.Text) + " where MaHP='"+txtMaHP.Text+"'";
56 business.Update("HocPhan", sql);
57 FormHocPhan_Load(sender, e);
58 }
File name: FormQuanLyDiem.cs
Copy
60 private void btnLuu_Click(object sender, EventArgs e)
61 {
62 string MaSV = txtMaSV.Text;
63 string MaNhomHP = cmbMaNhomHP.SelectedValue.ToString();
64 double DiemThi = Convert.ToDouble(txtDiemThi.Text);
65 double DiemQT = Convert.ToDouble(txtDiemQuaTrinh.Text);
66 string sql = "MaSV='" + MaSV + "'";
67 business.Delete("KetQua", sql);
68 sql = "'"+MaSV+"','"+MaNhomHP+"',"+DiemQT+","+DiemThi+",'','',''";
69 business.Insert("KetQua", sql);
70 btnLoc_Click(sender, e);
71 }
File name: FormThongKe.cs
Copy
69 private void btnLoc_Click(object sender, EventArgs e)
70 {
71
72 if (cmbThongKeTheo.SelectedIndex != -1)
73 {
74 if (cmbThongKeTheo.SelectedIndex == 0)
75 {
76 if (Convert.ToInt32(cmbMa.SelectedIndex) != -1)
77 {
78 dgvThongKe.DataSource= business.ThongKeLop(cmbMaHK.SelectedValue.ToString(),cmbMa.SelectedValue.ToString(),Convert.ToInt32(cmbXepLoai.SelectedIndex));
79 }
80 }
81 else
82 {
83 if (Convert.ToInt32(cmbMa.SelectedIndex) != -1)
84 {
85 dgvThongKe.DataSource = business.ThongKeKhoiLop(cmbMaHK.SelectedValue.ToString(), cmbMa.SelectedValue.ToString(), Convert.ToInt32(cmbXepLoai.SelectedIndex));
86 }
87 }
88 }
89 }
File name: FormXemDiemLop.cs
Copy
59 private void btnXem_Click(object sender, EventArgs e)
60 {
61 if (chbXemTatCa.Checked == true)
62 {
63 if (Convert.ToInt32(cmbMaLop.SelectedIndex) != -1)
64 {
65 dgvKetQua.DataSource = business.XemDiemLop(cmbMaLop.SelectedValue.ToString());
66 }
67 }
68 else
69 {
70 if (Convert.ToInt32(cmbMaLop.SelectedIndex) != -1 && Convert.ToInt32(cmbMaHK.SelectedIndex) != -1)
71 {
72 dgvKetQua.DataSource = business.XemDiemLop(cmbMaHK.SelectedValue.ToString(), cmbMaLop.SelectedValue.ToString());
73 }
74 }
75 }
File name: AccountService.cs
Copy
173 private void ParseResult(string result)
174 {
175 if (string.IsNullOrEmpty(result))
176 {
177 this.Message = "Server's response was empty. Please register through account website during this service interruption.";
178 return;
179 }
180
181 Dictionary
182 if (values == null)
183 {
184 this.Message = "Service temporarily unavailable. Please register through account website.";
185 return;
186 }
187
188 int returnCodeInt = -1;
189 string returnCodeString = string.Empty;
190 string message;
191
192 values.TryGetValue("ReturnCode", out returnCodeString);
193 values.TryGetValue("Message", out message);
194 int.TryParse(returnCodeString, out returnCodeInt);
195
196 this.ReturnCode = returnCodeInt;
197 if (returnCodeInt == 0)
198 {
199 // returnCode == 0 means: all ok. message is new AppId
200 this.AppId = message;
201 }
202 else
203 {
204 // any error gives returnCode != 0
205 this.AppId = string.Empty;
206 this.Message = message;
207 }
208 }
File name: PhotonConverter.cs
Copy
18 public static void RunConversion()
19 {
20 //Ask if user has made a backup.
21 int option = EditorUtility.DisplayDialogComplex("Conversion", "Attempt automatic conversion from Unity Networking to Photon Unity Networking \"PUN\"?", "Yes", "No!", "Pick Script Folder");
22 switch (option)
23 {
24 case 0:
25 break;
26 case 1:
27 return;
28 case 2:
29 PickFolderAndConvertScripts();
30 return;
31 default:
32 return;
33 }
34
35 //REAAAALY?
36 bool result = EditorUtility.DisplayDialog("Conversion", "Disclaimer: The code conversion feature is quite crude, but should do it's job well (see the sourcecode). A backup is therefore strongly recommended!", "Yes, I've made a backup: GO", "Abort");
37 if (!result)
38 {
39 return;
40 }
41 Output(EditorApplication.timeSinceStartup + " Started conversion of Unity networking -> Photon");
42
43 //Ask to save current scene (optional)
44 EditorApplication.SaveCurrentSceneIfUserWantsTo();
45
46 EditorUtility.DisplayProgressBar("Converting..", "Starting.", 0);
47
48 //Convert NetworkViews to PhotonViews in Project prefabs
49 //Ask the user if we can move all prefabs to a resources folder
50 bool movePrefabs = EditorUtility.DisplayDialog("Conversion", "Can all prefabs that use a PhotonView be moved to a Resources/ folder? You need this if you use Network.Instantiate.", "Yes", "No");
51
52
53 string[] prefabs = Directory.GetFiles("Assets/", "*.prefab", SearchOption.AllDirectories);
54 foreach (string prefab in prefabs)
55 {
56 EditorUtility.DisplayProgressBar("Converting..", "Object:" + prefab, 0.6f);
57
58 Object[] objs = (Object[])AssetDatabase.LoadAllAssetsAtPath(prefab);
59 int converted = 0;
60 foreach (Object obj in objs)
61 {
62 if (obj != null && obj.GetType() == typeof(GameObject))
63 converted += ConvertNetworkView(((GameObject)obj).GetComponents
64 }
65 if (movePrefabs && converted > 0)
66 {
67 //This prefab needs to be under the root of a Resources folder!
68 string path = prefab.Replace("\\", "/");
69 int lastSlash = path.LastIndexOf("/");
70 int resourcesIndex = path.LastIndexOf("/Resources/");
71 if (resourcesIndex != lastSlash - 10)
72 {
73 if (path.Contains("/Resources/"))
74 {
75 Debug.LogWarning("Warning, prefab [" + prefab + "] was already in a resources folder. But has been placed in the root of another one!");
76 }
77 //This prefab NEEDS to be placed under a resources folder
78 string resourcesFolder = path.Substring(0, lastSlash) + "/Resources/";
79 EnsureFolder(resourcesFolder);
80 string newPath = resourcesFolder + path.Substring(lastSlash + 1);
81 string error = AssetDatabase.MoveAsset(prefab, newPath);
82 if (error != "")
83 Debug.LogError(error);
84 Output("Fixed prefab [" + prefab + "] by moving it into a resources folder.");
85 }
86 }
87 }
88
89 //Convert NetworkViews to PhotonViews in scenes
90 string[] sceneFiles = Directory.GetFiles("Assets/", "*.unity", SearchOption.AllDirectories);
91 foreach (string sceneName in sceneFiles)
92 {
93 EditorApplication.OpenScene(sceneName);
94 EditorUtility.DisplayProgressBar("Converting..", "Scene:" + sceneName, 0.2f);
95
96 int converted2 = ConvertNetworkView((NetworkView[])GameObject.FindObjectsOfType(typeof(NetworkView)), true);
97 if (converted2 > 0)
98 {
99 //This will correct all prefabs: The prefabs have gotten new components, but the correct ID's were lost in this case
100 PhotonViewHandler.HierarchyChange(); //TODO: most likely this is triggered on change or on save
101
102 Output("Replaced " + converted2 + " NetworkViews with PhotonViews in scene: " + sceneName);
103 EditorApplication.SaveScene(EditorApplication.currentScene);
104 }
105
106 }
107
108 //Convert C#/JS scripts (API stuff)
109 List
110
111 EditorUtility.DisplayProgressBar("Converting..", "Scripts..", 0.9f);
112 ConvertScripts(scripts);
113
114 Output(EditorApplication.timeSinceStartup + " Completed conversion!");
115 EditorUtility.ClearProgressBar();
116
117 EditorUtility.DisplayDialog("Completed the conversion", "Don't forget to add \"PhotonNetwork.ConnectWithDefaultSettings();\" to connect to the Photon server before using any multiplayer functionality.", "OK");
118 }
File name: PhotonConverter.cs
Copy
120 public static void PickFolderAndConvertScripts()
121 {
122 string folderPath = EditorUtility.OpenFolderPanel("Pick source folder to convert", Directory.GetCurrentDirectory(), "");
123 if (string.IsNullOrEmpty(folderPath))
124 {
125 EditorUtility.DisplayDialog("Script Conversion", "No folder was selected. No files were changed. Please start over.", "Ok.");
126 return;
127 }
128
129 bool result = EditorUtility.DisplayDialog("Script Conversion", "Scripts in this folder will be modified:\n\n" + folderPath + "\n\nMake sure you have backups of these scripts.\nConversion is not guaranteed to work!", "Backup done. Go!", "Abort");
130 if (!result)
131 {
132 return;
133 }
134
135 List
136 ConvertScripts(scripts);
137
138 EditorUtility.DisplayDialog("Script Conversion", "Scripts are now converted to PUN.\n\nYou will need to update\n- scenes\n- components\n- prefabs and\n- add \"PhotonNetwork.ConnectWithDefaultSettings();\"", "Ok");
139 }
Download file with original file name:Convert
Convert 143 lượt xem
Gõ tìm kiếm nhanh...