PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Formularios/frm_proveedor.cs

https://gitlab.com/makintosh/Farmacia
C# | 400 lines | 298 code | 89 blank | 13 comment | 32 complexity | d2769a990891b0b0be397dcf7dde2e7d MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using fabisa.Aplicacion;
  10. using System.Data.OleDb;
  11. namespace fabisa.Formularios
  12. {
  13. public partial class frm_proveedor : Form
  14. {
  15. public frm_proveedor()
  16. {
  17. InitializeComponent();
  18. }
  19. Proveedor obj_prov = new Proveedor();
  20. DataSet dsProveedor;
  21. int flag_guardar=0;
  22. int contadorProveedor = 0;
  23. int totalProveedor = 0;
  24. private void gestionprovee_Load(object sender, EventArgs e)
  25. {
  26. dsProveedor = obj_prov.cargar_proveedor();
  27. totalProveedor = dsProveedor.Tables["prov"].Rows.Count;
  28. habilitar_cajas(false);
  29. btguardar.Enabled = false;
  30. btcancelar.Enabled = false;
  31. //txtruc.Enabled = false;
  32. cargar_proveedor(0);
  33. lbRegistro.Text = "Proveedor "+(contadorProveedor+1)+" de "+totalProveedor;
  34. }
  35. public void cargar_proveedor(int numero)
  36. {
  37. if (dsProveedor.Tables["prov"].Rows.Count > 0)
  38. {
  39. txtruc.Text = dsProveedor.Tables["prov"].Rows[numero][0].ToString();
  40. txtrazon.Text = dsProveedor.Tables["prov"].Rows[numero][1].ToString();
  41. txttel.Text = dsProveedor.Tables["prov"].Rows[numero][2].ToString();
  42. txtdireccion.Text = dsProveedor.Tables["prov"].Rows[numero][3].ToString();
  43. txtciudad.Text = dsProveedor.Tables["prov"].Rows[numero][4].ToString();
  44. }
  45. else
  46. {
  47. btcancelar.Enabled = false;
  48. btguardar.Enabled = false;
  49. btmodificar.Enabled = false;
  50. bteliminar.Enabled = false;
  51. habilitar_botones_navegacion(false);
  52. }
  53. }
  54. /// <summary>
  55. /// Logica de Botones y Cajas de texto.
  56. /// </summary>
  57. /// <param name="t"></param>
  58. private void habilitar_botones_navegacion(bool t)
  59. {
  60. btinicio.Enabled = t;
  61. btsig.Enabled = t;
  62. btatras.Enabled = t;
  63. btfin.Enabled = t;
  64. }
  65. public void limpiar_cajas()
  66. {
  67. txtciudad.Clear();
  68. txtrazon.Clear();
  69. txttel.Clear();
  70. txtdireccion.Clear();
  71. txtruc.Clear();
  72. }
  73. public void habilitar_cajas(Boolean c)
  74. {
  75. txtciudad.ReadOnly = !c;
  76. txtdireccion.ReadOnly = !c;
  77. txtrazon.ReadOnly = !c;
  78. txttel.ReadOnly = !c;
  79. txtruc.ReadOnly = !c;
  80. }
  81. private void habilitar_botones_accion(bool t)
  82. {
  83. btnuevo.Enabled = t;
  84. btguardar.Enabled = !t;
  85. btmodificar.Enabled = t;
  86. bteliminar.Enabled = t;
  87. btbuscar.Enabled = t;
  88. btcancelar.Enabled = !t;
  89. }
  90. private Proveedor prov()
  91. {
  92. Proveedor prov = new Proveedor();
  93. prov.setRuc(txtruc.Text);
  94. prov.setRazon(txtrazon.Text);
  95. prov.setCiudad(txtciudad.Text);
  96. prov.setDireccion(txtdireccion.Text);
  97. prov.setTelefono(txttel.Text);
  98. return prov;
  99. }
  100. //BOTONES
  101. private void btnuevo_Click(object sender, EventArgs e)
  102. {
  103. limpiar_cajas();
  104. txtrazon.Focus();
  105. habilitar_cajas(true);
  106. habilitar_botones_accion(false);
  107. flag_guardar = 1;
  108. }
  109. //guardar /////////////////////////////////////////////////////////////
  110. private void btguardar_Click(object sender, EventArgs e)
  111. {
  112. if (txtruc.Text != "" && txtrazon.Text != "")
  113. {
  114. if (flag_guardar == 1) // guarda
  115. {
  116. obj_prov.guardar(prov());
  117. dsProveedor = obj_prov.cargar_proveedor();
  118. totalProveedor = dsProveedor.Tables["prov"].Rows.Count;
  119. habilitar_botones_navegacion(true);
  120. habilitar_botones_accion(true);
  121. habilitar_cajas(false);
  122. flag_guardar = 0;
  123. }
  124. if (flag_guardar == 0) // modifica
  125. {
  126. obj_prov.actulizar(prov());
  127. dsProveedor = obj_prov.cargar_proveedor();
  128. habilitar_botones_accion(true);
  129. habilitar_botones_navegacion(true);
  130. habilitar_cajas(false);
  131. }
  132. }
  133. else
  134. {
  135. MessageBox.Show("INGRESO DE DATOS INCORRECTO ES NECESARIO QUE ESTEN LLENOS LOS CAMPOS DE RUC Y RAZON SOCIAL","",MessageBoxButtons.OK,MessageBoxIcon.Information);
  136. }
  137. }
  138. private void btmodificar_Click(object sender, EventArgs e)
  139. {
  140. flag_guardar = 0;
  141. habilitar_cajas(true);
  142. txtruc.ReadOnly = true;
  143. habilitar_botones_accion(false);
  144. habilitar_botones_navegacion(false);
  145. }
  146. private void btbuscar_Click(object sender, EventArgs e)
  147. {
  148. frm_buscar_proveedor busprov = new frm_buscar_proveedor();
  149. busprov.ShowDialog();
  150. if (busprov.DialogResult == DialogResult.OK)
  151. {
  152. txtruc.Text = busprov.getProveedor().getRuc();
  153. txtrazon.Text = busprov.getProveedor().getRazon();
  154. txttel.Text = busprov.getProveedor().getTelefono();
  155. txtdireccion.Text = busprov.getProveedor().getDireccion();
  156. txtciudad.Text = busprov.getProveedor().getCiudad();
  157. contadorProveedor = busprov.numero;
  158. lbRegistro.Text = "Proveedor "+(contadorProveedor+1)+" de "+totalProveedor;
  159. }
  160. }
  161. private void btsalir_Click(object sender, EventArgs e)
  162. {
  163. this.Close();
  164. }
  165. private void btcancelar_Click(object sender, EventArgs e)
  166. {
  167. habilitar_cajas(false);
  168. habilitar_botones_navegacion(true);
  169. habilitar_botones_accion(true);
  170. limpiar_cajas();
  171. cargar_proveedor(contadorProveedor);
  172. }
  173. private void bteliminar_Click(object sender, EventArgs e)
  174. {
  175. DialogResult eliminar = MessageBox.Show("¿Esta seguro que desea eliminar al proveedor " + txtrazon.Text + " ?", "", MessageBoxButtons.YesNo);
  176. if (eliminar == System.Windows.Forms.DialogResult.Yes)
  177. {
  178. obj_prov.eliminar(txtruc.Text);
  179. limpiar_cajas();
  180. dsProveedor = obj_prov.cargar_proveedor();
  181. totalProveedor = dsProveedor.Tables["prov"].Rows.Count;
  182. contadorProveedor = 0;
  183. cargar_proveedor(contadorProveedor);
  184. lbRegistro.Text = "Proveedor "+(contadorProveedor+1)+" de "+totalProveedor;
  185. }
  186. else
  187. {
  188. }
  189. }
  190. //VALIDAR RUC PERSONA NATURAL O JURIDICA ////////////////////
  191. public void validar_ruc(String ruc)
  192. {
  193. Char[] vocales = new Char[13];
  194. vocales = ruc.ToCharArray(); //convertir cadena de caracteres a vector
  195. }
  196. private void txtruc_Validated(object sender, EventArgs e)
  197. {
  198. if (flag_guardar == 1)
  199. {
  200. if (txtruc.Text.Length == 13)
  201. {
  202. if (obj_prov.buscarxFiltros(txtruc.Text, "ruc_prv").Rows.Count == 1)
  203. {
  204. MessageBox.Show("Ya esta registrado en la Base de Datos", "Verificar", MessageBoxButtons.OK, MessageBoxIcon.Information);
  205. txtruc.Clear();
  206. txtruc.Focus();
  207. }
  208. }
  209. else
  210. {
  211. if (txtruc.Text.Length > 0 && txtruc.Text.Length < 13)
  212. {
  213. int valida = 13 - txtruc.Text.Length;
  214. MessageBox.Show("Error al ingresar el RUC, faltan " + valida.ToString() + " digitos");
  215. }
  216. }
  217. }
  218. }
  219. //validaciones cajas de texto ////////////////////////////////////////
  220. #region
  221. private void txtruc_KeyPress(object sender, KeyPressEventArgs e)
  222. {
  223. if (Char.IsNumber(e.KeyChar) || (e.KeyChar == 8))
  224. {
  225. e.Handled = false;
  226. }
  227. else
  228. {
  229. e.Handled = true;
  230. }
  231. }
  232. private void txtvendedor_KeyPress(object sender, KeyPressEventArgs e)
  233. {
  234. if (Char.IsNumber(e.KeyChar))
  235. {
  236. e.Handled = true;
  237. }
  238. else
  239. {
  240. e.Handled = false;
  241. }
  242. }
  243. private void txtciudad_KeyPress(object sender, KeyPressEventArgs e)
  244. {
  245. if (Char.IsNumber(e.KeyChar))
  246. {
  247. e.Handled = true;
  248. }
  249. else
  250. {
  251. e.Handled = false;
  252. }
  253. }
  254. private void txttel_KeyPress(object sender, KeyPressEventArgs e)
  255. {
  256. if (Char.IsNumber(e.KeyChar) || (e.KeyChar == 8))
  257. {
  258. e.Handled = false;
  259. }
  260. else
  261. {
  262. e.Handled = true;
  263. }
  264. }
  265. #endregion
  266. ///// botones navegacion
  267. #region
  268. private void btsig_Click(object sender, EventArgs e)
  269. {
  270. contadorProveedor++;
  271. if (contadorProveedor < totalProveedor)
  272. {
  273. cargar_proveedor(contadorProveedor);
  274. lbRegistro.Text = "Proveedor " + (contadorProveedor + 1) + " de " + totalProveedor;
  275. }
  276. else
  277. {
  278. //MessageBox.Show("ULTIMO", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  279. contadorProveedor--;
  280. }
  281. }
  282. private void btfin_Click(object sender, EventArgs e)
  283. {
  284. contadorProveedor = totalProveedor-1;
  285. cargar_proveedor(contadorProveedor);
  286. lbRegistro.Text = "Proveedor " + (contadorProveedor + 1) + " de " + totalProveedor;
  287. }
  288. private void btinicio_Click(object sender, EventArgs e)
  289. {
  290. cargar_proveedor(0);
  291. contadorProveedor = 0;
  292. lbRegistro.Text = "Proveedor " + (contadorProveedor + 1) + " de " + totalProveedor;
  293. }
  294. private void btatras_Click(object sender, EventArgs e)
  295. {
  296. contadorProveedor--;
  297. if (contadorProveedor >= 0)
  298. {
  299. cargar_proveedor(contadorProveedor);
  300. lbRegistro.Text = "Proveedor " + (contadorProveedor + 1) + " de " + totalProveedor;
  301. }
  302. else
  303. {
  304. //MessageBox.Show("PRIMERO ", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
  305. contadorProveedor = 0;
  306. }
  307. }
  308. #endregion
  309. ////////////////////////////////////////////////////////////////////////////////////////
  310. }//penultimo
  311. }//ultimo