code
stringlengths
1
2.01M
repo_name
stringlengths
3
62
path
stringlengths
1
267
language
stringclasses
231 values
license
stringclasses
13 values
size
int64
1
2.01M
/** * editable_selects.js * * Copyright, Moxiecode Systems AB * Released under LGPL License. * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ var TinyMCE_EditableSelects = { editSelectElm : null, init : function() { var nl = document.getElementsByTagName("select"), i, d = document, o; for (i=0; i<nl.length; i++) { if (nl[i].className.indexOf('mceEditableSelect') != -1) { o = new Option(tinyMCEPopup.editor.translate('value'), '__mce_add_custom__'); o.className = 'mceAddSelectValue'; nl[i].options[nl[i].options.length] = o; nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect; } } }, onChangeEditableSelect : function(e) { var d = document, ne, se = window.event ? window.event.srcElement : e.target; if (se.options[se.selectedIndex].value == '__mce_add_custom__') { ne = d.createElement("input"); ne.id = se.id + "_custom"; ne.name = se.name + "_custom"; ne.type = "text"; ne.style.width = se.offsetWidth + 'px'; se.parentNode.insertBefore(ne, se); se.style.display = 'none'; ne.focus(); ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput; ne.onkeydown = TinyMCE_EditableSelects.onKeyDown; TinyMCE_EditableSelects.editSelectElm = se; } }, onBlurEditableSelectInput : function() { var se = TinyMCE_EditableSelects.editSelectElm; if (se) { if (se.previousSibling.value != '') { addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value); selectByValue(document.forms[0], se.id, se.previousSibling.value); } else selectByValue(document.forms[0], se.id, ''); se.style.display = 'inline'; se.parentNode.removeChild(se.previousSibling); TinyMCE_EditableSelects.editSelectElm = null; } }, onKeyDown : function(e) { e = e || window.event; if (e.keyCode == 13) TinyMCE_EditableSelects.onBlurEditableSelectInput(); } };
0683babd6e120333c4dae5bac951f5cc
trunk/assets/tinymce/plugins/compat3x/editable_selects.js
JavaScript
mit
1,959
/** * mctabs.js * * Copyright, Moxiecode Systems AB * Released under LGPL License. * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ function MCTabs() { this.settings = []; this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher'); }; MCTabs.prototype.init = function(settings) { this.settings = settings; }; MCTabs.prototype.getParam = function(name, default_value) { var value = null; value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name]; // Fix bool values if (value == "true" || value == "false") return (value == "true"); return value; }; MCTabs.prototype.showTab =function(tab){ tab.className = 'current'; tab.setAttribute("aria-selected", true); tab.setAttribute("aria-expanded", true); tab.tabIndex = 0; }; MCTabs.prototype.hideTab =function(tab){ var t=this; tab.className = ''; tab.setAttribute("aria-selected", false); tab.setAttribute("aria-expanded", false); tab.tabIndex = -1; }; MCTabs.prototype.showPanel = function(panel) { panel.className = 'current'; panel.setAttribute("aria-hidden", false); }; MCTabs.prototype.hidePanel = function(panel) { panel.className = 'panel'; panel.setAttribute("aria-hidden", true); }; MCTabs.prototype.getPanelForTab = function(tabElm) { return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls"); }; MCTabs.prototype.displayTab = function(tab_id, panel_id, avoid_focus) { var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this; tabElm = document.getElementById(tab_id); if (panel_id === undefined) { panel_id = t.getPanelForTab(tabElm); } panelElm= document.getElementById(panel_id); panelContainerElm = panelElm ? panelElm.parentNode : null; tabContainerElm = tabElm ? tabElm.parentNode : null; selectionClass = t.getParam('selection_class', 'current'); if (tabElm && tabContainerElm) { nodes = tabContainerElm.childNodes; // Hide all other tabs for (i = 0; i < nodes.length; i++) { if (nodes[i].nodeName == "LI") { t.hideTab(nodes[i]); } } // Show selected tab t.showTab(tabElm); } if (panelElm && panelContainerElm) { nodes = panelContainerElm.childNodes; // Hide all other panels for (i = 0; i < nodes.length; i++) { if (nodes[i].nodeName == "DIV") t.hidePanel(nodes[i]); } if (!avoid_focus) { tabElm.focus(); } // Show selected panel t.showPanel(panelElm); } }; MCTabs.prototype.getAnchor = function() { var pos, url = document.location.href; if ((pos = url.lastIndexOf('#')) != -1) return url.substring(pos + 1); return ""; }; //Global instance var mcTabs = new MCTabs(); tinyMCEPopup.onInit.add(function() { var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each; each(dom.select('div.tabs'), function(tabContainerElm) { var keyNav; dom.setAttrib(tabContainerElm, "role", "tablist"); var items = tinyMCEPopup.dom.select('li', tabContainerElm); var action = function(id) { mcTabs.displayTab(id, mcTabs.getPanelForTab(id)); mcTabs.onChange.dispatch(id); }; each(items, function(item) { dom.setAttrib(item, 'role', 'tab'); dom.bind(item, 'click', function(evt) { action(item.id); }); }); dom.bind(dom.getRoot(), 'keydown', function(evt) { if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab keyNav.moveFocus(evt.shiftKey ? -1 : 1); tinymce.dom.Event.cancel(evt); } }); each(dom.select('a', tabContainerElm), function(a) { dom.setAttrib(a, 'tabindex', '-1'); }); keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', { root: tabContainerElm, items: items, onAction: action, actOnFocus: true, enableLeftRight: true, enableUpDown: true }, tinyMCEPopup.dom); }); });
0683babd6e120333c4dae5bac951f5cc
trunk/assets/tinymce/plugins/compat3x/mctabs.js
JavaScript
mit
3,877
/** * validate.js * * Copyright, Moxiecode Systems AB * Released under LGPL License. * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ /** // String validation: if (!Validator.isEmail('myemail')) alert('Invalid email.'); // Form validation: var f = document.forms['myform']; if (!Validator.isEmail(f.myemail)) alert('Invalid email.'); */ var Validator = { isEmail : function(s) { return this.test(s, '^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$'); }, isAbsUrl : function(s) { return this.test(s, '^(news|telnet|nttp|file|http|ftp|https)://[-A-Za-z0-9\\.]+\\/?.*$'); }, isSize : function(s) { return this.test(s, '^[0-9.]+(%|in|cm|mm|em|ex|pt|pc|px)?$'); }, isId : function(s) { return this.test(s, '^[A-Za-z_]([A-Za-z0-9_])*$'); }, isEmpty : function(s) { var nl, i; if (s.nodeName == 'SELECT' && s.selectedIndex < 1) return true; if (s.type == 'checkbox' && !s.checked) return true; if (s.type == 'radio') { for (i=0, nl = s.form.elements; i<nl.length; i++) { if (nl[i].type == "radio" && nl[i].name == s.name && nl[i].checked) return false; } return true; } return new RegExp('^\\s*$').test(s.nodeType == 1 ? s.value : s); }, isNumber : function(s, d) { return !isNaN(s.nodeType == 1 ? s.value : s) && (!d || !this.test(s, '^-?[0-9]*\\.[0-9]*$')); }, test : function(s, p) { s = s.nodeType == 1 ? s.value : s; return s == '' || new RegExp(p).test(s); } }; var AutoValidator = { settings : { id_cls : 'id', int_cls : 'int', url_cls : 'url', number_cls : 'number', email_cls : 'email', size_cls : 'size', required_cls : 'required', invalid_cls : 'invalid', min_cls : 'min', max_cls : 'max' }, init : function(s) { var n; for (n in s) this.settings[n] = s[n]; }, validate : function(f) { var i, nl, s = this.settings, c = 0; nl = this.tags(f, 'label'); for (i=0; i<nl.length; i++) { this.removeClass(nl[i], s.invalid_cls); nl[i].setAttribute('aria-invalid', false); } c += this.validateElms(f, 'input'); c += this.validateElms(f, 'select'); c += this.validateElms(f, 'textarea'); return c == 3; }, invalidate : function(n) { this.mark(n.form, n); }, getErrorMessages : function(f) { var nl, i, s = this.settings, field, msg, values, messages = [], ed = tinyMCEPopup.editor; nl = this.tags(f, "label"); for (i=0; i<nl.length; i++) { if (this.hasClass(nl[i], s.invalid_cls)) { field = document.getElementById(nl[i].getAttribute("for")); values = { field: nl[i].textContent }; if (this.hasClass(field, s.min_cls, true)) { message = ed.getLang('invalid_data_min'); values.min = this.getNum(field, s.min_cls); } else if (this.hasClass(field, s.number_cls)) { message = ed.getLang('invalid_data_number'); } else if (this.hasClass(field, s.size_cls)) { message = ed.getLang('invalid_data_size'); } else { message = ed.getLang('invalid_data'); } message = message.replace(/{\#([^}]+)\}/g, function(a, b) { return values[b] || '{#' + b + '}'; }); messages.push(message); } } return messages; }, reset : function(e) { var t = ['label', 'input', 'select', 'textarea']; var i, j, nl, s = this.settings; if (e == null) return; for (i=0; i<t.length; i++) { nl = this.tags(e.form ? e.form : e, t[i]); for (j=0; j<nl.length; j++) { this.removeClass(nl[j], s.invalid_cls); nl[j].setAttribute('aria-invalid', false); } } }, validateElms : function(f, e) { var nl, i, n, s = this.settings, st = true, va = Validator, v; nl = this.tags(f, e); for (i=0; i<nl.length; i++) { n = nl[i]; this.removeClass(n, s.invalid_cls); if (this.hasClass(n, s.required_cls) && va.isEmpty(n)) st = this.mark(f, n); if (this.hasClass(n, s.number_cls) && !va.isNumber(n)) st = this.mark(f, n); if (this.hasClass(n, s.int_cls) && !va.isNumber(n, true)) st = this.mark(f, n); if (this.hasClass(n, s.url_cls) && !va.isAbsUrl(n)) st = this.mark(f, n); if (this.hasClass(n, s.email_cls) && !va.isEmail(n)) st = this.mark(f, n); if (this.hasClass(n, s.size_cls) && !va.isSize(n)) st = this.mark(f, n); if (this.hasClass(n, s.id_cls) && !va.isId(n)) st = this.mark(f, n); if (this.hasClass(n, s.min_cls, true)) { v = this.getNum(n, s.min_cls); if (isNaN(v) || parseInt(n.value) < parseInt(v)) st = this.mark(f, n); } if (this.hasClass(n, s.max_cls, true)) { v = this.getNum(n, s.max_cls); if (isNaN(v) || parseInt(n.value) > parseInt(v)) st = this.mark(f, n); } } return st; }, hasClass : function(n, c, d) { return new RegExp('\\b' + c + (d ? '[0-9]+' : '') + '\\b', 'g').test(n.className); }, getNum : function(n, c) { c = n.className.match(new RegExp('\\b' + c + '([0-9]+)\\b', 'g'))[0]; c = c.replace(/[^0-9]/g, ''); return c; }, addClass : function(n, c, b) { var o = this.removeClass(n, c); n.className = b ? c + (o != '' ? (' ' + o) : '') : (o != '' ? (o + ' ') : '') + c; }, removeClass : function(n, c) { c = n.className.replace(new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' '); return n.className = c != ' ' ? c : ''; }, tags : function(f, s) { return f.getElementsByTagName(s); }, mark : function(f, n) { var s = this.settings; this.addClass(n, s.invalid_cls); n.setAttribute('aria-invalid', 'true'); this.markLabels(f, n, s.invalid_cls); return false; }, markLabels : function(f, n, ic) { var nl, i; nl = this.tags(f, "label"); for (i=0; i<nl.length; i++) { if (nl[i].getAttribute("for") == n.id || nl[i].htmlFor == n.id) this.addClass(nl[i], ic); } return null; } };
0683babd6e120333c4dae5bac951f5cc
trunk/assets/tinymce/plugins/compat3x/validate.js
JavaScript
mit
5,831
/** * form_utils.js * * Copyright, Moxiecode Systems AB * Released under LGPL License. * * License: http://www.tinymce.com/license * Contributing: http://www.tinymce.com/contributing */ var themeBaseURL = tinyMCEPopup.editor.baseURI.toAbsolute('themes/' + tinyMCEPopup.getParam("theme")); function getColorPickerHTML(id, target_form_element) { var h = "", dom = tinyMCEPopup.dom; if (label = dom.select('label[for=' + target_form_element + ']')[0]) { label.id = label.id || dom.uniqueId(); } h += '<a role="button" aria-labelledby="' + id + '_label" id="' + id + '_link" href="javascript:;" onclick="tinyMCEPopup.pickColor(event,\'' + target_form_element +'\');" onmousedown="return false;" class="pickcolor">'; h += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;<span id="' + id + '_label" class="mceVoiceLabel mceIconOnly" style="display:none;">' + tinyMCEPopup.getLang('browse') + '</span></span></a>'; return h; } function updateColor(img_id, form_element_id) { document.getElementById(img_id).style.backgroundColor = document.forms[0].elements[form_element_id].value; } function setBrowserDisabled(id, state) { var img = document.getElementById(id); var lnk = document.getElementById(id + "_link"); if (lnk) { if (state) { lnk.setAttribute("realhref", lnk.getAttribute("href")); lnk.removeAttribute("href"); tinyMCEPopup.dom.addClass(img, 'disabled'); } else { if (lnk.getAttribute("realhref")) lnk.setAttribute("href", lnk.getAttribute("realhref")); tinyMCEPopup.dom.removeClass(img, 'disabled'); } } } function getBrowserHTML(id, target_form_element, type, prefix) { var option = prefix + "_" + type + "_browser_callback", cb, html; cb = tinyMCEPopup.getParam(option, tinyMCEPopup.getParam("file_browser_callback")); if (!cb) return ""; html = ""; html += '<a id="' + id + '_link" href="javascript:openBrowser(\'' + id + '\',\'' + target_form_element + '\', \'' + type + '\',\'' + option + '\');" onmousedown="return false;" class="browse">'; html += '<span id="' + id + '" title="' + tinyMCEPopup.getLang('browse') + '">&nbsp;</span></a>'; return html; } function openBrowser(img_id, target_form_element, type, option) { var img = document.getElementById(img_id); if (img.className != "mceButtonDisabled") tinyMCEPopup.openBrowser(target_form_element, type, option); } function selectByValue(form_obj, field_name, value, add_custom, ignore_case) { if (!form_obj || !form_obj.elements[field_name]) return; if (!value) value = ""; var sel = form_obj.elements[field_name]; var found = false; for (var i=0; i<sel.options.length; i++) { var option = sel.options[i]; if (option.value == value || (ignore_case && option.value.toLowerCase() == value.toLowerCase())) { option.selected = true; found = true; } else option.selected = false; } if (!found && add_custom && value != '') { var option = new Option(value, value); option.selected = true; sel.options[sel.options.length] = option; sel.selectedIndex = sel.options.length - 1; } return found; } function getSelectValue(form_obj, field_name) { var elm = form_obj.elements[field_name]; if (elm == null || elm.options == null || elm.selectedIndex === -1) return ""; return elm.options[elm.selectedIndex].value; } function addSelectValue(form_obj, field_name, name, value) { var s = form_obj.elements[field_name]; var o = new Option(name, value); s.options[s.options.length] = o; } function addClassesToList(list_id, specific_option) { // Setup class droplist var styleSelectElm = document.getElementById(list_id); var styles = tinyMCEPopup.getParam('theme_advanced_styles', false); styles = tinyMCEPopup.getParam(specific_option, styles); if (styles) { var stylesAr = styles.split(';'); for (var i=0; i<stylesAr.length; i++) { if (stylesAr != "") { var key, value; key = stylesAr[i].split('=')[0]; value = stylesAr[i].split('=')[1]; styleSelectElm.options[styleSelectElm.length] = new Option(key, value); } } } else { tinymce.each(tinyMCEPopup.editor.dom.getClasses(), function(o) { styleSelectElm.options[styleSelectElm.length] = new Option(o.title || o['class'], o['class']); }); } } function isVisible(element_id) { var elm = document.getElementById(element_id); return elm && elm.style.display != "none"; } function convertRGBToHex(col) { var re = new RegExp("rgb\\s*\\(\\s*([0-9]+).*,\\s*([0-9]+).*,\\s*([0-9]+).*\\)", "gi"); var rgb = col.replace(re, "$1,$2,$3").split(','); if (rgb.length == 3) { r = parseInt(rgb[0]).toString(16); g = parseInt(rgb[1]).toString(16); b = parseInt(rgb[2]).toString(16); r = r.length == 1 ? '0' + r : r; g = g.length == 1 ? '0' + g : g; b = b.length == 1 ? '0' + b : b; return "#" + r + g + b; } return col; } function convertHexToRGB(col) { if (col.indexOf('#') != -1) { col = col.replace(new RegExp('[^0-9A-F]', 'gi'), ''); r = parseInt(col.substring(0, 2), 16); g = parseInt(col.substring(2, 4), 16); b = parseInt(col.substring(4, 6), 16); return "rgb(" + r + "," + g + "," + b + ")"; } return col; } function trimSize(size) { return size.replace(/([0-9\.]+)(px|%|in|cm|mm|em|ex|pt|pc)/i, '$1$2'); } function getCSSSize(size) { size = trimSize(size); if (size == "") return ""; // Add px if (/^[0-9]+$/.test(size)) size += 'px'; // Sanity check, IE doesn't like broken values else if (!(/^[0-9\.]+(px|%|in|cm|mm|em|ex|pt|pc)$/i.test(size))) return ""; return size; } function getStyle(elm, attrib, style) { var val = tinyMCEPopup.dom.getAttrib(elm, attrib); if (val != '') return '' + val; if (typeof(style) == 'undefined') style = attrib; return tinyMCEPopup.dom.getStyle(elm, style); }
0683babd6e120333c4dae5bac951f5cc
trunk/assets/tinymce/plugins/compat3x/form_utils.js
JavaScript
mit
5,764
.mce-visualblocks p { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhCQAJAJEAAAAAAP///7u7u////yH5BAEAAAMALAAAAAAJAAkAAAIQnG+CqCN/mlyvsRUpThG6AgA7); } .mce-visualblocks h1 { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhDQAKAIABALu7u////yH5BAEAAAEALAAAAAANAAoAAAIXjI8GybGu1JuxHoAfRNRW3TWXyF2YiRUAOw==); } .mce-visualblocks h2 { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhDgAKAIABALu7u////yH5BAEAAAEALAAAAAAOAAoAAAIajI8Hybbx4oOuqgTynJd6bGlWg3DkJzoaUAAAOw==); } .mce-visualblocks h3 { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhDgAKAIABALu7u////yH5BAEAAAEALAAAAAAOAAoAAAIZjI8Hybbx4oOuqgTynJf2Ln2NOHpQpmhAAQA7); } .mce-visualblocks h4 { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhDgAKAIABALu7u////yH5BAEAAAEALAAAAAAOAAoAAAIajI8HybbxInR0zqeAdhtJlXwV1oCll2HaWgAAOw==); } .mce-visualblocks h5 { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhDgAKAIABALu7u////yH5BAEAAAEALAAAAAAOAAoAAAIajI8HybbxIoiuwjane4iq5GlW05GgIkIZUAAAOw==); } .mce-visualblocks h6 { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhDgAKAIABALu7u////yH5BAEAAAEALAAAAAAOAAoAAAIajI8HybbxIoiuwjan04jep1iZ1XRlAo5bVgAAOw==); } .mce-visualblocks div { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhEgAKAIABALu7u////yH5BAEAAAEALAAAAAASAAoAAAIfjI9poI0cgDywrhuxfbrzDEbQM2Ei5aRjmoySW4pAAQA7); } .mce-visualblocks section { padding-top: 10px; border: 1px dashed #BBB; margin: 0 0 1em 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhKAAKAIABALu7u////yH5BAEAAAEALAAAAAAoAAoAAAI5jI+pywcNY3sBWHdNrplytD2ellDeSVbp+GmWqaDqDMepc8t17Y4vBsK5hDyJMcI6KkuYU+jpjLoKADs=); } .mce-visualblocks article { padding-top: 10px; border: 1px dashed #BBB; margin: 0 0 1em 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhKgAKAIABALu7u////yH5BAEAAAEALAAAAAAqAAoAAAI6jI+pywkNY3wG0GBvrsd2tXGYSGnfiF7ikpXemTpOiJScasYoDJJrjsG9gkCJ0ag6KhmaIe3pjDYBBQA7); } .mce-visualblocks blockquote { padding-top: 10px; border: 1px dashed #BBB; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhPgAKAIABALu7u////yH5BAEAAAEALAAAAAA+AAoAAAJPjI+py+0Knpz0xQDyuUhvfoGgIX5iSKZYgq5uNL5q69asZ8s5rrf0yZmpNkJZzFesBTu8TOlDVAabUyatguVhWduud3EyiUk45xhTTgMBBQA7); } .mce-visualblocks address { padding-top: 10px; border: 1px dashed #BBB; margin: 0 0 1em 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhLQAKAIABALu7u////yH5BAEAAAEALAAAAAAtAAoAAAI/jI+pywwNozSP1gDyyZcjb3UaRpXkWaXmZW4OqKLhBmLs+K263DkJK7OJeifh7FicKD9A1/IpGdKkyFpNmCkAADs=); } .mce-visualblocks pre { padding-top: 10px; border: 1px dashed #BBB; margin-left: 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhFQAKAIABALu7uwAAACH5BAEAAAEALAAAAAAVAAoAAAIjjI+ZoN0cgDwSmnpz1NCueYERhnibZVKLNnbOq8IvKpJtVQAAOw==); } .mce-visualblocks figure { padding-top: 10px; border: 1px dashed #BBB; margin: 0 0 1em 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhJAAKAIAAALu7u////yH5BAEAAAEALAAAAAAkAAoAAAI0jI+py+2fwAHUSFvD3RlvG4HIp4nX5JFSpnZUJ6LlrM52OE7uSWosBHScgkSZj7dDKnWAAgA7); } .mce-visualblocks hgroup { padding-top: 10px; border: 1px dashed #BBB; margin: 0 0 1em 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhJwAKAIABALu7uwAAACH5BAEAAAEALAAAAAAnAAoAAAI3jI+pywYNI3uB0gpsRtt5fFnfNZaVSYJil4Wo03Hv6Z62uOCgiXH1kZIIJ8NiIxRrAZNMZAtQAAA7); } .mce-visualblocks aside { padding-top: 10px; border: 1px dashed #BBB; margin: 0 0 1em 3px; background: transparent no-repeat url(data:image/gif;base64,R0lGODlhHgAKAIABAKqqqv///yH5BAEAAAEALAAAAAAeAAoAAAItjI+pG8APjZOTzgtqy7I3f1yehmQcFY4WKZbqByutmW4aHUd6vfcVbgudgpYCADs=); } .mce-visualblocks figcaption { border: 1px dashed #BBB; }
0683babd6e120333c4dae5bac951f5cc
trunk/assets/tinymce/plugins/visualblocks/css/visualblocks.css
CSS
mit
4,333
@import 'stylesheet.css'; /* Sticky footer styles -------------------------------------------------- */ html, body { height: 100%; background:url('image/bg.png'); /* The html and body elements cannot have any padding or margin. */ } h1,#footer{ font-family:anudawregular; } /* Wrapper for page content to push down footer */ #wrap { min-height: 100%; height: auto !important; height: 100%; /* Negative indent footer by its height */ margin: 0 auto -60px; /* Pad bottom by footer height */ padding: 0 0 60px; } /* Set the fixed height of the footer here */ #footer { height: 60px; background-color: #f5f5f5; background:url('image/footer.png'); } /* Custom page CSS -------------------------------------------------- */ /* Not required for template or sticky footer method. */ #wrap > .container { padding: 60px 15px 0; } .container .credit { margin: 20px 0; } #footer > .container { padding-left: 15px; padding-right: 15px; } .shadow { -moz-box-shadow: 3px 3px 5px 6px #ccc; -webkit-box-shadow: 3px 3px 5px 6px #ccc; box-shadow: 3px 3px 5px 6px #ccc; } code { font-size: 80%; }
0683babd6e120333c4dae5bac951f5cc
trunk/assets/css/error/error_404.css
CSS
mit
1,200
@import 'fonts/Digital-dream-fontfacekit/init.css'; /* html{background:#BED0E0 url('../img/textured_paper.png');} body { background:#BED0E0 url('../img/textured_paper.png'); background-attachment:fixed; } */ html{background:#fff;} body { background:#fff;'); background-attachment:fixed; } /* menu */ .accordion h3{ margin:0; padding:0; font-size:14px; } .side_menu { background-color: #2BA6CB; color: #fff; text-align: center; border:1px solid #2285A2; border-bottom:none; cursor:pointer; } .accordion h3.head a { color: #fff; display: inline; position: relative; font-size:15px; } .accordion.side-nav ul li { margin:0; padding:0; list-style:none; } .accordion div p a { color: #6f9bdc; display: inline; position: relative; } .accordion h3.head2 a { color: #fff; display: inline; position: relative; font-size:15px; } /*header*/ .school-header { text-align:center; background:transparent url('../img/paper.png'); } table{ background:none; border:1px solid #c0c0c0; } table thead{ background:#827D7D; } table thead tr th{ color:#2B2828; } table tbody{ background:#E0E0E0; } .login-box{ padding:20px; min-height:369px; background:url('../img/logo.png')no-repeat -75px 95%; } div.shadow{ -moz-box-shadow: 10px 10px 5px #888; -webkit-box-shadow: 10px 10px 5px #888; box-shadow: 10px 10px 5px #888; border:1px solid #666; } .left{text-align:left;} .right{text-align:right;} .center{text-align:center;} fieldset{ border:lpx dotted #f00; } /* .content-views{ background:#EAEAEA url('../img/paper.png'); border:2px solid #c0c0c0; padding:20px; } */ .content-views{ background:#fff; padding:20px; } .content-menus{ background:#EAEAEA url('../img/paper.png'); border:2px solid #c0c0c0; padding:10px 5px 10px 10px; } table.data-table{ width:100%; } footer div.footer-contents { margin:2% auto; background:#EAEAEA url('../img/paper.png'); border:2px solid #c0c0c0; padding:20px; } #amount_money { font-family: 'DigitaldreamFatRegular'; } .error_simple { font-size:9px; color:#fff; background:#D20000; padding:1px 2px; border:1px solid #790000; } .row.full-width { width: 100%; max-width: 100%; } .help-icon{ display:inline-block; width:16px; height:17px; background:url("../img/glyphicons_194_circle_question_mark.png") no-repeat -5px -6px }
0683babd6e120333c4dae5bac951f5cc
trunk/assets/css/style.css
CSS
mit
2,530
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace ConexionSQL { static class Program { /// <summary> /// Punto de entrada principal para la aplicación. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ConexionSQL/ConexionSQL/Program.cs
C#
asf20
509
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // La información general sobre un ensamblado se controla mediante el siguiente // conjunto de atributos. Cambie estos atributos para modificar la información // asociada con un ensamblado. [assembly: AssemblyTitle("ConexionSQL")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ConexionSQL")] [assembly: AssemblyCopyright("Copyright © 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Si establece ComVisible como false, los tipos de este ensamblado no estarán visibles // para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde // COM, establezca el atributo ComVisible como true en este tipo. [assembly: ComVisible(false)] // El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM [assembly: Guid("c16796c0-d342-43bd-b615-37a4f48c0be3")] // La información de versión de un ensamblado consta de los cuatro valores siguientes: // // Versión principal // Versión secundaria // Número de versión de compilación // Revisión // // Puede especificar todos los valores o establecer como predeterminados los números de versión de compilación y de revisión // mediante el asterisco ('*'), como se muestra a continuación: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
09066bd9cc483c8928891679d8ad73b5
trunk/ConexionSQL/ConexionSQL/Properties/AssemblyInfo.cs
C#
asf20
1,601
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace ConexionSQL { public partial class Form1 : Form { public Form1() { InitializeComponent(); } System.Data.SqlClient.SqlConnection con; private void Form1_Load(object sender, EventArgs e) { con = new System.Data.SqlClient.SqlConnection(); con.ConnectionString = "Data Source=localhost\\SQLSERVER2005; Initial Catalog=GD1C2012; User ID = gd; Password = gd2012"; try { con.Open(); MessageBox.Show("Conexión realizada."); } catch (Exception) { MessageBox.Show("Conexión fallida."); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ConexionSQL/ConexionSQL/Form1.cs
C#
asf20
978
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmCliente { public partial class AbmCliente : Form { public AbmCliente(Modelo.FormActions.Actions action, string id) { InitializeComponent(); pk.Visible = false; lbl_estado.Text = "ALTA"; tb_grande.Visible = false; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE (Id_Cliente != 1 ) AND (Id_Cliente = " + id + ")", con); DataTable dt = new DataTable(); da.Fill(dt); pk.Name = id; tb_nombre.Text = dt.Rows[0]["Cl_Nombre"].ToString(); tb_apellido.Text = dt.Rows[0]["Cl_Apellido"].ToString(); tb_dni.Text = dt.Rows[0]["Cl_Dni"].ToString(); tb_grande.Text = dt.Rows[0]["Cl_Direccion"].ToString(); tb_tel.Text = dt.Rows[0]["Cl_Telefono"].ToString(); tb_mail.Text = dt.Rows[0]["Cl_Mail"].ToString(); dt_nacimiento.Value = DateTime.Parse(dt.Rows[0]["Cl_Fecha_Nac"].ToString()); label7.Visible = label8.Visible = label9.Visible = label11.Visible = false; tb_dpto.Visible = tb_localidad.Visible = tb_nropiso.Visible = tb_cp.Visible = false; tb_grande.Visible = true; if (Convert.ToBoolean(dt.Rows[0]["Cl_Habilitado"].ToString()) == false) { cb_habi.Checked = false; } else { cb_habi.Checked = true; } if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; Propiedades.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmCliente_Load(object sender, EventArgs e) { } private void aceptar_Click_1(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (tb_apellido.Text != "" && tb_dni.Text != "" && tb_nombre.Text != "" && tb_tel.Text != "") { if (lbl_estado.Text == "ALTA") { if (tb_nropiso.Text != "" && tb_localidad.Text != "" && tb_dpto.Text != "" && tb_dir.Text != "" && tb_cp.Text != "") { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Clientes(Cl_Nombre,Cl_Apellido,Cl_Dni,Cl_Direccion,Cl_Telefono,Cl_Mail,Cl_Fecha_Nac,Cl_Habilitado) VALUES(@nom,@ape,@dni,@dire,@tel,@mail,@fech,@habi)", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", tb_dni.Text); comando.Parameters.AddWithValue("dire", "(" + tb_dir.Text + ") (" + tb_dpto.Text + ") (" + tb_nropiso.Text + ") (" + tb_localidad.Text + ") (" + tb_cp.Text + ")"); comando.Parameters.AddWithValue("tel", tb_tel.Text); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_nombre.Text = ""; tb_apellido.Text = ""; tb_dni.Text = ""; tb_dir.Text = ""; tb_tel.Text = ""; tb_mail.Text = ""; tb_dpto.Text = ""; tb_nropiso.Text = ""; tb_localidad.Text = ""; tb_cp.Text = ""; cb_habi.Checked = false; dt_nacimiento.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } if (lbl_estado.Text == "MODIFICACION") { if (tb_grande.Text != "") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Clientes SET Cl_Nombre=@nom,Cl_Apellido=@ape,Cl_Dni=@dni,Cl_Direccion=@dire,Cl_Telefono=@tel,Cl_Mail=@mail,Cl_Fecha_Nac=@fech,Cl_Habilitado=@habi WHERE Id_Cliente = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", Convert.ToDecimal(tb_dni.Text)); comando.Parameters.AddWithValue("dire", tb_grande.Text); comando.Parameters.AddWithValue("tel", Convert.ToDecimal(tb_tel.Text)); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show("Transacción realizada."); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Clientes SET Cl_Habilitado=@habi WHERE Id_Cliente = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show("Transacción realizada."); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmCliente/AbmCliente.cs
C#
asf20
9,828
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmCliente { public partial class Listado_Clientes : Form { private Modelo.FormActions.Actions action; public Listado_Clientes(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente != 1", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Clientes_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmCliente(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente != 1", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string consulta = ""; if (tb_apellido.Text == "" && tb_nombre.Text == "" && tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente != 1"; } else if (tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Clientes WHERE (Id_Cliente != 1) AND (Cl_Nombre LIKE '" + tb_nombre.Text + "' OR Cl_Apellido LIKE '" + tb_apellido.Text + "')"; } else { consulta = "SELECT * FROM NUNCA_TAXI.Clientes WHERE (Id_Cliente != 1) AND (Cl_Nombre LIKE '" + tb_nombre.Text + "' OR Cl_Apellido LIKE '" + tb_apellido.Text + "' OR Cl_Dni = '" + tb_dni.Text + "')"; } SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmCliente/Listado_Clientes.cs
C#
asf20
4,643
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Security.Cryptography; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Login { public partial class Login : Form { #region Properties private Boolean isValidated = false; public static MainForm mainForm; public static List<int> permisosList = new List<int>(); #endregion #region Public public Login() { InitializeComponent(); } #endregion #region Events private void login_button_Click(Object sender, EventArgs e) { //TODO: agregar validacion de user&pass isValidated = validateUser(user.Text, passwd.Text); if (isValidated) { mainForm = new MainForm(this); mainForm.Show(); } else { MessageBox.Show("La combinación de usuario/contraseña es erronea, o usuario no habilitado", "Error de Login"); foreach (Control ctrl in this.Controls) { if (ctrl is TextBox) { ((TextBox)ctrl).Clear(); } } } } #endregion private Boolean validateUser(String user, String passwd) { bool return_value = false; if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(passwd)) { return return_value; } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { //Validate user Modelo.Modelo.openConnection(con); SqlCommand validate_user = new SqlCommand(Modelo.SqlQueries.getUserInfo(user), con); SqlDataReader reader = validate_user.ExecuteReader(); //If users exists if (reader.FieldCount > 0) { reader.Read(); string password = reader.GetString(1); int login_failed = Convert.ToInt32(reader.GetDecimal(2)); bool habilitado = reader.GetBoolean(3); //Validated passwd and enabled if (password.Equals(getSHA256(passwd)) && habilitado) { SqlConnection con2 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con2); SqlCommand reset_fails = new SqlCommand(Modelo.SqlQueries.resetLoginFails(user), con2); reset_fails.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con2); getPermissions(user); return_value = true; } //User exists, but wrong passwd or not enabled else { if (login_failed < 3) { SqlConnection con4 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con4); SqlCommand inc_login_fail = new SqlCommand(Modelo.SqlQueries.incUserLoginFailed(user, login_failed + 1), con4); inc_login_fail.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con4); //This is the third failed time. Disable user if (login_failed == 2) { SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand disable_user = new SqlCommand(Modelo.SqlQueries.disableUser(user), con3); disable_user.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } return return_value; } public static string getSHA256(string input) { string hashed = null; byte[] inputBytes = Encoding.Unicode.GetBytes(input); SHA256Managed hash = new SHA256Managed(); byte[] hashBytes = hash.ComputeHash(inputBytes); hashed = Convert.ToBase64String(hashBytes); return hashed; } private void Login_Load(object sender, EventArgs e) { } private void getPermissions(string username) { using (SqlConnection con2 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_user_id = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(username), con2); SqlDataReader reader = comando_get_user_id.ExecuteReader(); List<int> roles = new List<int>(); while (reader.Read()) { int user_id = Convert.ToInt32(reader.GetDecimal(0)); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter us_rol_da = new SqlDataAdapter(Modelo.SqlQueries.getUserRoles(user_id), con); DataTable us_rol_dt = new DataTable(); us_rol_da.Fill(us_rol_dt); foreach (DataRow rol in us_rol_dt.Rows) { bool added = Convert.ToBoolean(rol.ItemArray[2]); if (added) { int rol_id = Convert.ToInt32(rol.ItemArray[0].ToString()); using (SqlConnection con3 = Modelo.Modelo.createConnection()) { SqlDataAdapter rol_perm_da = new SqlDataAdapter(Modelo.SqlQueries.getRolePermissions(rol_id), con3); DataTable rol_perm_dt = new DataTable(); rol_perm_da.Fill(rol_perm_dt); foreach (DataRow perm in rol_perm_dt.Rows) { foreach (KeyValuePair<string, int> pair in Modelo.Permissions.PermissionsDict) { if (pair.Value == Convert.ToInt32(perm.ItemArray[0].ToString())) { permisosList.Add(pair.Value); break; } } } } } } } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Login/Login.cs
C#
asf20
7,831
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmUsuario { public partial class Listado_Usuario : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Usuario(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledUsers, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getUsers, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmUsuario(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUsersFiltered(busqueda_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUsers, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmUsuario/Listado_Usuario.cs
C#
asf20
2,663
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmUsuario { public partial class AbmUsuario : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmUsuario(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; tb_usuario.Enabled = false; tb_passwd.Enabled = false; cb_hab.Enabled = false; dataGridView1.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; tb_usuario.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Modificar"; break; } } public AbmUsuario(Modelo.FormActions.Actions runAction) { InitializeComponent(); cb_hab.Enabled = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void loadData(int id) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUserById(selected_elem), con); DataTable dt = new DataTable(); da.Fill(dt); DataRow user_info = dt.Rows[0]; tb_usuario.Text = user_info.ItemArray[1].ToString(); cb_hab.Checked = (bool) user_info.ItemArray[2]; SqlDataAdapter us_rol_da = new SqlDataAdapter(Modelo.SqlQueries.getUserRoles(selected_elem), con); DataTable us_rol_dt = new DataTable(); us_rol_da.Fill(us_rol_dt); dataGridView1.DataSource = us_rol_dt; } } private void aceptar_Click(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_usuario.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de usuario es obligatorio"); } if (String.IsNullOrEmpty(tb_passwd.Text)) { error_txt = String.Concat(error_txt, "\n Password es obligatorio"); } if(!String.IsNullOrEmpty(tb_usuario.Text) && (!String.IsNullOrEmpty(tb_passwd.Text))){ using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(tb_usuario.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Usuario duplicado"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addUser(tb_usuario.Text, Login.Login.getSHA256(tb_passwd.Text)), con); comando_add_user.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_user_id = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(tb_usuario.Text), con2); SqlDataReader reader = comando_get_user_id.ExecuteReader(); List<int> roles = new List<int>(); while (reader.Read()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["Added"].Value != null && Convert.ToInt32(row.Cells["Added"].Value) == 1) { roles.Add(Convert.ToInt32(row.Cells["Id"].Value)); } } if (roles.Count > 0) { SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand comando_add_user_role = new SqlCommand(Modelo.SqlQueries.addUserRoles(Convert.ToInt32(reader.GetDecimal(0)), roles), con3); comando_add_user_role.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } } MessageBox.Show(String.Format("Usuario {0} agregado", tb_usuario.Text)); Login.Login.mainForm.openForm(new AbmUsuario(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteUser(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Usuario {0} eliminado", tb_usuario.Text)); Login.Login.mainForm.openForm(new AbmUsuario(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: if (String.IsNullOrEmpty(tb_usuario.Text)) { MessageBox.Show("Nombre de usuario es obligatorio"); } else { List<int> roles_list = new List<int>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["Added"].Value != null && Convert.ToInt32(row.Cells["Added"].Value) == 1) { roles_list.Add(Convert.ToInt32(row.Cells["Id"].Value)); } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateUser(selected_elem, Login.Login.getSHA256(tb_passwd.Text), roles_list), connection); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Usuario {0} modificado", tb_usuario.Text)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmUsuario/AbmUsuario.cs
C#
asf20
10,193
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.RegistrarViaje { public partial class RegistrarViajes : Form { public RegistrarViajes() { InitializeComponent(); tb_chofer_index.Visible = tb_cliente_index.Visible = tb_turno_index.Visible = tb_tipo_viaj_index.Visible = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.TiposViaje", con); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_tipo_viaje.Items.Add(dt.Rows[i]["Ti_DescripcionTipoViaje"].ToString()); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_turno.Items.Add(dt.Rows[i]["Tu_Descripcion"].ToString()); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_chofer.Items.Add("(" + dt.Rows[i]["Id_Chofer"].ToString() + ") (" + dt.Rows[i]["Ch_Nombre"].ToString() + ") (" + dt.Rows[i]["Ch_Apellido"].ToString() + ") (" + dt.Rows[i]["Ch_Dni"].ToString() + ")"); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Cl_Habilitado = 1 AND (Id_Cliente != 1 )", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_cliente.Items.Add("(" + dt.Rows[i]["Id_Cliente"].ToString() + ") (" + dt.Rows[i]["Cl_Nombre"].ToString() + ") (" + dt.Rows[i]["Cl_Apellido"].ToString() + ") (" + dt.Rows[i]["Cl_Dni"].ToString() + ")"); } } } private void RegistrarViajes_Load(object sender, EventArgs e) { } private void cb_chofer_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_chofer.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_chofer_index.Text = numero.ToString(); } private void cb_turno_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_turno.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_turno_index.Text = numero.ToString(); } private void cb_tipo_viaje_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_tipo_viaje.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice); tb_tipo_viaj_index.Text = numero.ToString(); } private void cb_cliente_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_cliente.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 2; tb_cliente_index.Text = numero.ToString(); } private void aceptar_Click(object sender, EventArgs e) { if (cb_chofer.SelectedIndex.ToString() != "" && cb_cliente.SelectedIndex.ToString() != "" && cb_tipo_viaje.SelectedIndex.ToString() != "" && cb_turno.SelectedIndex.ToString() != "" && tb_fichas.Text != "" && tb_chofer_index.Text != "" && tb_cliente_index.Text != "" && tb_tipo_viaj_index.Text != "" && tb_turno_index.Text != "") { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion = '" + cb_turno.SelectedItem.ToString() + "'", con); DataTable dt = new DataTable(); da.Fill(dt); decimal valor_ficha = Convert.ToDecimal(dt.Rows[0]["Tu_Valor_Ficha"].ToString()); decimal valor_bandera = Convert.ToDecimal(dt.Rows[0]["Tu_Valor_Bandera"].ToString()); decimal importe = (Convert.ToDecimal(tb_fichas.Text) * valor_ficha) + valor_bandera; da = new SqlDataAdapter("SELECT T.Id_Taxi FROM NUNCA_TAXI.Taxis T INNER JOIN NUNCA_TAXI.ChoferesTurnosTaxis ON T.Id_Taxi = NUNCA_TAXI.ChoferesTurnosTaxis.Id_Taxi INNER JOIN NUNCA_TAXI.Relojes ON T.Id_Reloj = NUNCA_TAXI.Relojes.Id_Reloj WHERE Ta_Habilitado = 1 AND Re_Habilitado = 1 AND Id_Turno = " + tb_turno_index.Text + " AND Id_Chofer = " + tb_chofer_index.Text, con); dt = new DataTable(); da.Fill(dt); string id_taxi = dt.Rows[0]["Id_Taxi"].ToString(); SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Viajes(Id_Cliente,Id_Chofer,Id_Turno,Id_Taxi,Id_TipoViaje,Vi_Cant_Fichas,Vi_Fecha,Vi_Importe) VALUES(@cliente,@chofer,@turno,@taxi,@tipo_viaje,@cant_fichas,@fecha,@importe)", con); comando.Parameters.AddWithValue("cliente", tb_cliente_index.Text); comando.Parameters.AddWithValue("chofer", tb_chofer_index.Text); comando.Parameters.AddWithValue("turno", tb_turno_index.Text); comando.Parameters.AddWithValue("taxi", id_taxi); comando.Parameters.AddWithValue("tipo_viaje", tb_tipo_viaj_index.Text); comando.Parameters.AddWithValue("cant_fichas", tb_fichas.Text); comando.Parameters.AddWithValue("fecha", dt_fecha.Value); comando.Parameters.AddWithValue("importe", importe); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { cb_tipo_viaje.SelectedIndex = -1; cb_turno.SelectedItem = -1; cb_cliente.SelectedIndex = -1; cb_chofer.SelectedIndex = -1; tb_cliente_index.Text = ""; tb_chofer_index.Text = ""; tb_turno_index.Text = ""; tb_tipo_viaj_index.Text = ""; tb_fichas.Text = ""; dt_fecha.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/RegistrarViaje/RegistrarViajes.cs
C#
asf20
7,569
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmAuto { public partial class AbmAuto : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmAuto(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); marca_cb.DataSource = ds.Tables[0].DefaultView; marca_cb.DisplayMember = "Marca"; marca_cb.ValueMember = "Id"; marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; marca_cb.Enabled = false; reloj_cb.Enabled = false; tb_licencia.Enabled = false; tb_modelo.Enabled = false; tb_patente.Enabled = false; tb_rodado.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar.Text = "Modificar"; break; } } public AbmAuto(Modelo.FormActions.Actions runAction) { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); marca_cb.DataSource = ds.Tables[0].DefaultView; marca_cb.DisplayMember = "Marca"; marca_cb.ValueMember = "Id"; marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_get_autos = new SqlCommand(Modelo.SqlQueries.getAutoById(selected_elem), con3); SqlDataReader reader = comando_get_autos.ExecuteReader(); while (reader.Read()) { marca_cb.SelectedValue= Convert.ToInt32(reader["Marca"]); reloj_cb.SelectedValue = Convert.ToInt32(reader["Reloj"]); tb_licencia.Text = reader["Licencia"].ToString(); tb_modelo.Text = reader["Modelo"].ToString(); tb_patente.Text = reader["Patente"].ToString(); tb_rodado.Text = reader["Rodado"].ToString(); cb_hab.Checked = (Boolean)reader["Habilitado"]; } } } private void aceptar_Click_1(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: string error_txt = "ERROR: "; if (String.IsNullOrEmpty(marca_cb.Text)) { error_txt = String.Concat(error_txt, "\n Marca es obligatorio"); } if (String.IsNullOrEmpty(reloj_cb.Text)) { error_txt = String.Concat(error_txt, "\n Reloj es obligatorio"); } if (String.IsNullOrEmpty(tb_licencia.Text)) { error_txt = String.Concat(error_txt, "\n Licencia es obligatorio"); } if (String.IsNullOrEmpty(tb_modelo.Text)) { error_txt = String.Concat(error_txt, "\n Modelo es obligatorio"); } if (String.IsNullOrEmpty(tb_patente.Text)) { error_txt = String.Concat(error_txt, "\n Patente es obligatorio"); } if (String.IsNullOrEmpty(tb_rodado.Text)) { error_txt = String.Concat(error_txt, "\n Rodado es obligatorio"); } if((!String.IsNullOrEmpty(marca_cb.Text)) && (!String.IsNullOrEmpty(reloj_cb.Text))&& (!String.IsNullOrEmpty(tb_licencia.Text))&& (!String.IsNullOrEmpty(tb_modelo.Text))&& (!String.IsNullOrEmpty(tb_patente.Text))&& (!String.IsNullOrEmpty(tb_rodado.Text))) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTaxiMellizo(tb_patente.Text, tb_licencia.Text, Convert.ToInt32(reloj_cb.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Taxi mellizo"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con_un2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un2); SqlCommand comando_check_unique2 = new SqlCommand(Modelo.SqlQueries.getRelojUsado(Convert.ToInt32(reloj_cb.SelectedValue)), con_un2); SqlDataReader reader = comando_check_unique2.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Reloj en uso"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addAuto( Convert.ToInt32(marca_cb.SelectedValue), Convert.ToInt32(reloj_cb.SelectedValue), tb_licencia.Text, tb_modelo.Text, tb_patente.Text, tb_rodado.Text, true), con); comando_add_user.ExecuteNonQuery(); MessageBox.Show("Taxi agregado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }else { MessageBox.Show(error_txt); } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteAuto(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show("Taxi eliminado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTaxiMellizo(tb_patente.Text, tb_licencia.Text, Convert.ToInt32(reloj_cb.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Taxi mellizo"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateAuto(selected_elem, Convert.ToInt32(marca_cb.SelectedValue), Convert.ToInt32(reloj_cb.SelectedValue), tb_licencia.Text, tb_modelo.Text, tb_patente.Text, tb_rodado.Text, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show("Taxi modificado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } private void AbmAuto_Load(object sender, EventArgs e) { } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmAuto/AbmAuto.cs
C#
asf20
13,284
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmAuto { public partial class Listado_Auto : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Auto(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); busqueda_marca_cb.DataSource = ds.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_reloj_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_reloj_cb.DisplayMember = "Marca"; busqueda_reloj_cb.ValueMember = "Id"; busqueda_reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getAutos(), con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmAuto(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutoFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_patente_tb.Text, busqueda_licencia_tb.Text, busqueda_reloj_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_reloj_cb.SelectedValue)), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutos(), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmAuto/Listado_Auto.cs
C#
asf20
4,080
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace GestorDeFlotasDesktop { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Login.Login()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Program.cs
C#
asf20
519
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Facturar { public partial class Facturar : Form { public Facturar() { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getClientes, con); DataSet ds = new DataSet(); da.Fill(ds); cb_cliente.DataSource = ds.Tables[0].DefaultView; cb_cliente.DisplayMember = "Cliente"; cb_cliente.ValueMember = "Id"; cb_cliente.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); } private void aceptar_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_Factura(Convert.ToInt32(cb_cliente.SelectedValue), dtp_ini.Value, dtp_fin.Value)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Facturar/Facturar.cs
C#
asf20
1,118
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Facturar { public partial class Listado_Factura : Form { private DataTable dt; public Listado_Factura(int cliente_id, DateTime f_ini, DateTime f_fin) { InitializeComponent(); tb_fini.Text = f_ini.ToString(); tb_ffin.Text = f_fin.ToString(); FillData(cliente_id, f_ini, f_fin); } void FillData(int cliente_id, DateTime f_ini, DateTime f_fin) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); da = new SqlDataAdapter(Modelo.SqlQueries.getFacturas(cliente_id, f_ini, f_fin), con); da.Fill(dt); dataGridView1.DataSource = dt; } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con2); SqlCommand comando_up_fact = new SqlCommand(Modelo.SqlQueries.updateFacturas(cliente_id, f_ini, f_fin), con2); comando_up_fact.ExecuteNonQuery(); } double total = 0; foreach (DataRow dr in dt.Rows) { if (dr.RowState != DataRowState.Deleted) total += Convert.ToDouble(dr["Importe"]); } tb_importe.Text = total.ToString(); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Facturar/Listado_Factura.cs
C#
asf20
1,726
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmChofer { public partial class Listado_Chofer : Form { private Modelo.FormActions.Actions action; public Listado_Chofer(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Chofer_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmChofer(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string consulta = ""; if (tb_apellido.Text == "" && tb_nombre.Text == "" && tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Choferes"; } else if (tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '" + tb_nombre.Text + "' OR Ch_Apellido LIKE '" + tb_apellido.Text + "'"; } else { consulta = "SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '" + tb_nombre.Text + "' OR Ch_Apellido LIKE '" + tb_apellido.Text + "' OR Ch_Dni = " + tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmChofer/Listado_Chofer.cs
C#
asf20
4,534
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmChofer { public partial class AbmChofer : Form { public AbmChofer(Modelo.FormActions.Actions action, string id) { InitializeComponent(); pk.Visible = false; lbl_estado.Text = "ALTA"; tb_grande.Visible = false; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Id_Chofer = " + id, con); DataTable dt = new DataTable(); da.Fill(dt); //Ch_Nombre,Ch_Apellido,Ch_Dni,Ch_Direccion,Ch_Telefono,Ch_Mail,Ch_Fecha_Nac,Ch_Habilitado pk.Name = id; tb_nombre.Text = dt.Rows[0]["Ch_Nombre"].ToString(); tb_apellido.Text = dt.Rows[0]["Ch_Apellido"].ToString(); tb_dni.Text = dt.Rows[0]["Ch_Dni"].ToString(); tb_grande.Text = dt.Rows[0]["Ch_Direccion"].ToString(); tb_tel.Text = dt.Rows[0]["Ch_Telefono"].ToString(); tb_mail.Text = dt.Rows[0]["Ch_Mail"].ToString(); dt_nacimiento.Value = DateTime.Parse(dt.Rows[0]["Ch_Fecha_Nac"].ToString()); label7.Visible = label8.Visible = label9.Visible = label11.Visible = false; tb_dpto.Visible = tb_localidad.Visible = tb_nropiso.Visible = tb_cp.Visible = false; tb_grande.Visible = true; if (Convert.ToBoolean(dt.Rows[0]["Ch_Habilitado"].ToString()) == false) { cb_habi.Checked = false; } else { cb_habi.Checked = true; } if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; Propiedades.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmChofer_Load(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (tb_apellido.Text != "" && tb_dni.Text != "" && tb_nombre.Text != "" && tb_tel.Text != "") { if (lbl_estado.Text == "ALTA") { if (tb_nropiso.Text != "" && tb_localidad.Text != "" && tb_dpto.Text != "" && tb_dir.Text != "" && tb_cp.Text != "") { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Choferes(Ch_Nombre,Ch_Apellido,Ch_Dni,Ch_Direccion,Ch_Telefono,Ch_Mail,Ch_Fecha_Nac,Ch_Habilitado) VALUES(@nom,@ape,@dni,@dire,@tel,@mail,@fech,@habi)", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", tb_dni.Text); comando.Parameters.AddWithValue("dire", "(" + tb_dir.Text + ") (" + tb_dpto.Text + ") (" + tb_nropiso.Text + ") (" + tb_localidad.Text + ") (" + tb_cp.Text + ")"); comando.Parameters.AddWithValue("tel", tb_tel.Text); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show("Transacción realizada."); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_nombre.Text = ""; tb_apellido.Text = ""; tb_dni.Text = ""; tb_dir.Text = ""; tb_tel.Text = ""; tb_mail.Text = ""; tb_dpto.Text = ""; tb_nropiso.Text = ""; tb_localidad.Text = ""; tb_cp.Text = ""; cb_habi.Checked = false; dt_nacimiento.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } if (lbl_estado.Text == "MODIFICACION") { if (tb_grande.Text != "") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Choferes SET Ch_Nombre=@nom,Ch_Apellido=@ape,Ch_Dni=@dni,Ch_Direccion=@dire,Ch_Telefono=@tel,Ch_Mail=@mail,Ch_Fecha_Nac=@fech,Ch_Habilitado=@habi WHERE Id_Chofer = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", Convert.ToDecimal(tb_dni.Text)); comando.Parameters.AddWithValue("dire", tb_grande.Text); comando.Parameters.AddWithValue("tel", Convert.ToDecimal(tb_tel.Text)); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Choferes SET Ch_Habilitado=@habi WHERE Id_Chofer = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show("Transacción realizada."); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmChofer/AbmChofer.cs
C#
asf20
9,900
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.RendirViajes { public partial class RendierViajes : Form { public RendierViajes() { InitializeComponent(); tb_chofer_index.Visible = tb_turno_index.Visible = false; tb_importe.Enabled = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Habilitado = 1", con); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_chofer.Items.Add("(" + dt.Rows[i]["Id_Chofer"].ToString() + ") (" + dt.Rows[i]["Ch_Nombre"].ToString() + ") (" + dt.Rows[i]["Ch_Apellido"].ToString() + ") (" + dt.Rows[i]["Ch_Dni"].ToString() + ")"); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_turno.Items.Add(dt.Rows[i]["Tu_Descripcion"].ToString()); } } } private void RendierViajes_Load(object sender, EventArgs e) { } private void cb_chofer_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_chofer.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_chofer_index.Text = numero.ToString(); } private void cb_turno_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_turno.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_turno_index.Text = numero.ToString(); } private void calcular_Click(object sender, EventArgs e) { if (tb_turno_index.Text != "" && tb_chofer_index.Text != "" && tb_dia.Text != "" && tb_anio.Text != "" && tb_mes.Text != "") { string fecha = "'" + tb_anio.Text + "/" + tb_mes.Text + "/" + tb_dia.Text + "'"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + tb_turno_index.Text + ") AND (Id_Chofer = " + tb_chofer_index.Text + ") AND (CONVERT(varchar, Vi_Fecha, 111) = " + fecha + ")", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; da = new SqlDataAdapter("SELECT Id_Chofer, SUM(Vi_Importe) AS Monto_Rendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + tb_turno_index.Text + ") AND (CONVERT(varchar, Vi_Fecha, 111) = " + fecha + ") AND (Id_Chofer = " + tb_chofer_index.Text + ") GROUP BY Id_Chofer", con); dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("No hay elementos a mostrar"); } else { tb_importe.Text = dt.Rows[0]["Monto_Rendicion"].ToString(); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } private void rendir_Click(object sender, EventArgs e) { if (tb_turno_index.Text != "" && tb_chofer_index.Text != "" && tb_dia.Text != "" && tb_anio.Text != "" && tb_mes.Text != "") { string fecha = "'" + tb_anio.Text + "/" + tb_mes.Text + "/" + tb_dia.Text + "'"; string fecha_aux = tb_anio.Text + "/" + tb_mes.Text + "/" + tb_dia.Text; DateTime dt_fecha = DateTime.Parse(fecha_aux); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Viajes SET Vi_FechaRendido=@fecha WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + tb_turno_index.Text + ") AND (Id_Chofer = " + tb_chofer_index.Text + ") AND (CONVERT(varchar, Vi_Fecha, 111) = " + fecha + ")", con); comando.Parameters.AddWithValue("fecha", System.DateTime.Now); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Rendiciones(Id_Chofer,Id_Turno,Ren_Fecha,Ren_Importe) VALUES(@chofer,@turno,@fecha,@importe)", con); comando.Parameters.AddWithValue("chofer", tb_chofer_index.Text); comando.Parameters.AddWithValue("turno", tb_turno_index.Text); comando.Parameters.AddWithValue("fecha", dt_fecha); comando.Parameters.AddWithValue("importe", Convert.ToDecimal(tb_importe.Text)); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { cb_turno.SelectedItem = -1; cb_chofer.SelectedIndex = -1; tb_importe.Text = ""; tb_anio.Text = ""; tb_mes.Text = ""; tb_dia.Text = ""; Modelo.Modelo.closeConnection(con); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/RendirViajes/RendierViajes.cs
C#
asf20
6,881
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using GestorDeFlotasDesktop.Modelo; // Objetos SQL using System.Data.SqlClient; namespace GestorDeFlotasDesktop { public partial class MainForm : Form { private Login.Login loginForm; private Form activeForm = null; public MainForm(Login.Login loginForm) { InitializeComponent(); this.loginForm = loginForm; this.loginForm.Hide(); this.filterOptions(); } private void filterOptions() { if(!Login.Login.permisosList.Contains(1)) { clienteToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(2)) { rolToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(3)) { usuarioToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(4)) { autoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(5)) { relojToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(6)) { choferToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(7)) { turnoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(8)) { asignarChoferAutoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(9)) { nuevoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(10)) { rendicionToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(11)) { facturacionToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(12)) { reportesToolStripMenuItem.Visible = false; } } public void openForm(Form form){ //lo borro de la coleccion de controles, y seteo la activa a null if (this.activeForm != null) { this.Controls.Remove(this.activeForm); this.activeForm.Dispose(); this.activeForm = null; } this.activeForm = form; this.activeForm.TopLevel = false; this.activeForm.Dock = DockStyle.Fill; this.activeForm.FormBorderStyle = FormBorderStyle.None; this.activeForm.Visible = true; this.Controls.Add(this.activeForm); } private void MainForm_Load(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); toolStripStatusLabel1.Text = "Conectado."; } catch (Exception) { toolStripStatusLabel1.Text = "Sin Conexion !!"; toolStripStatusLabel1.ForeColor = Color.Red; } finally { Modelo.Modelo.closeConnection(con); } } } #region Salir private void salirToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } #endregion #region Formulario Cliente private void altaClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.AbmCliente(Modelo.FormActions.Actions.Alta, "")); } private void bajaClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Baja)); } private void modificacionClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Rol private void altaRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.AbmRol(Modelo.FormActions.Actions.Alta)); } private void bajaRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Baja)); } private void modificacionRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Usuario private void altaUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.AbmUsuario(Modelo.FormActions.Actions.Alta)); } private void bajaUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Baja)); } private void modificacionUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Auto private void altaAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.AbmAuto(Modelo.FormActions.Actions.Alta)); } private void bajaAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Baja)); } private void modificacionAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Reloj private void altaRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.AbmReloj(Modelo.FormActions.Actions.Alta)); } private void bajaRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Baja)); } private void modificacionRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Chofer private void altaChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.AbmChofer(Modelo.FormActions.Actions.Alta, "")); } private void bajaChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Baja)); } private void modificacionChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Turno-Tarifa private void altaTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTarifa.AbmTurno(Modelo.FormActions.Actions.Alta, "")); } private void bajaTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Baja)); } private void modificacionTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Modificacion)); } #endregion private void nuevoToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new RegistrarViaje.RegistrarViajes()); } private void asignarChoferAutoToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new AsignChoferAuto.AsignChoferAuto()); } private void facturacionToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new Facturar.Facturar()); } private void rendicionToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new RendirViajes.RendierViajes()); } private void reportesToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new Listado.Listado()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/MainForm.cs
C#
asf20
9,199
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmRol { public partial class AbmRol : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmRol(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; func.Enabled = false; this.aceptar_btn.Text = "Eliminar"; this.tb_rol.Enabled = false; cb_hab.Enabled = false; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar_btn.Text = "Modificar"; cb_hab.Enabled = true; tb_rol.Enabled = true; break; } } public AbmRol(Modelo.FormActions.Actions runAction) { InitializeComponent(); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoleById(selected_elem), con); DataTable dt = new DataTable(); da.Fill(dt); DataRow rol_info = dt.Rows[0]; tb_rol.Text = rol_info.ItemArray[1].ToString(); cb_hab.Checked = (bool)rol_info.ItemArray[2]; SqlDataAdapter rol_perm_da = new SqlDataAdapter(Modelo.SqlQueries.getRolePermissions(selected_elem), con); DataTable rol_perm_dt = new DataTable(); rol_perm_da.Fill(rol_perm_dt); foreach (DataRow perm in rol_perm_dt.Rows) { Convert.ToInt32(perm.ItemArray[0].ToString()); string key = String.Empty; foreach (KeyValuePair<string, int> pair in Modelo.Permissions.PermissionsDict) { if (pair.Value == Convert.ToInt32(perm.ItemArray[0].ToString())) { key = pair.Key; break; } } foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Text.Equals(key)) { ((CheckBox)c).Checked = true; } } } } } } private void aceptar_btn_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(tb_rol.Text)) { switch (action) { case Modelo.FormActions.Actions.Alta: { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addRole(tb_rol.Text), con); comando_add_user.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_role_id = new SqlCommand(Modelo.SqlQueries.getRoleIdByName(tb_rol.Text), con2); SqlDataReader reader = comando_get_role_id.ExecuteReader(); List<int> permissions = new List<int>(); while (reader.Read()) { foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked) { permissions.Add(Modelo.Permissions.PermissionsDict[c.Text]); } } } SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand comando_add_role_permissions = new SqlCommand(Modelo.SqlQueries.addRolePermissions(Convert.ToInt32(reader.GetDecimal(0)), permissions), con3); comando_add_role_permissions.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } MessageBox.Show(String.Format("Rol {0} agregado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteRole(selected_elem), con); Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Rol {0} eliminado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } break; case Modelo.FormActions.Actions.Modificacion: List<int> permissions_list = new List<int>(); foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked) { permissions_list.Add(Modelo.Permissions.PermissionsDict[c.Text]); } } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateRole(selected_elem, tb_rol.Text, permissions_list, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Rol {0} modificado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } else { MessageBox.Show("ERROR: El nombre del rol es obligatorio."); } } private void AbmRol_Load(object sender, EventArgs e) { } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmRol/AbmRol.cs
C#
asf20
9,771
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmRol { public partial class Listado_Rol : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Rol(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRoles, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmRol(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRolesFiltered(busqueda_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmRol/Listado_Rol.cs
C#
asf20
2,647
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("GestorDeFlotasDesktop")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("GestorDeFlotasDesktop")] [assembly: AssemblyCopyright("Copyright © 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("a1c2fdc9-25c4-4ac4-9e6f-a482c920e7f3")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Properties/AssemblyInfo.cs
C#
asf20
1,454
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmTurno { public partial class Listado : Form { private Modelo.FormActions.Actions action; public Listado(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; for (int i = 0; i < dt.Rows.Count; i++) { cb_desc.Items.Add(dt.Rows[i]["Tu_Descripcion"]); } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Load(object sender, EventArgs e) { } private void cb_desc_SelectedIndexChanged(object sender, EventArgs e) { string curItem = cb_desc.SelectedItem.ToString(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_descripcion = '" + curItem + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 7) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmTarifa.AbmTurno(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_busqueda.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_descripcion LIKE '" + tb_busqueda.Text + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmTurno/Listado.cs
C#
asf20
3,762
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmTarifa { public partial class AbmTurno : Form { public AbmTurno(Modelo.FormActions.Actions action, string id) { InitializeComponent(); lbl_estado.Text = "ALTA"; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Id_Turno = " + id , con); DataTable dt = new DataTable(); da.Fill(dt); tb_desc.Text = dt.Rows[0]["Tu_Descripcion"].ToString(); tb_ini.Text = dt.Rows[0]["Tu_Hora_Ini"].ToString(); tb_fin.Text = dt.Rows[0]["Tu_Hora_Fin"].ToString(); tb_ficha.Text = dt.Rows[0]["Tu_Valor_Ficha"].ToString(); tb_bandera.Text = dt.Rows[0]["Tu_Valor_Bandera"].ToString(); if (Convert.ToBoolean(dt.Rows[0]["Tu_Habilitado"].ToString()) == false) { cb_habilitado.Checked = false; } else { cb_habilitado.Checked = true; } tb_desc.Enabled = false; if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; gb_car.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmTurno_Load(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { if (tb_bandera.Text != "" && tb_desc.Text != "" && tb_ficha.Text != "" && tb_fin.Text != "" && tb_ini.Text != "") { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (lbl_estado.Text == "ALTA") { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Turnos(Tu_Hora_Ini,Tu_Hora_Fin,Tu_Descripcion,Tu_Valor_Ficha,Tu_Valor_Bandera,Tu_Habilitado) VALUES(@h_ini,@h_fin,@desc,@ficha,@bandera,@habi)", con); comando.Parameters.AddWithValue("h_ini", tb_ini.Text); comando.Parameters.AddWithValue("h_fin", tb_fin.Text); comando.Parameters.AddWithValue("desc", tb_desc.Text); comando.Parameters.AddWithValue("ficha", Convert.ToDecimal(tb_ficha.Text)); comando.Parameters.AddWithValue("bandera", Convert.ToDecimal(tb_bandera.Text)); if (cb_habilitado.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habilitado.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_ini.Text = ""; tb_fin.Text = ""; tb_desc.Text = ""; tb_ficha.Text = ""; tb_bandera.Text = ""; Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "MODIFICACION") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Turnos SET Tu_Hora_Ini=@h_ini,Tu_Hora_Fin=@h_fin,Tu_Descripcion=@desc,Tu_Valor_Ficha=@ficha,Tu_Valor_Bandera=@bandera,Tu_Habilitado=@habi WHERE Tu_Descripcion = '" + tb_desc.Text + "'", con); comando.Parameters.AddWithValue("h_ini", tb_ini.Text); comando.Parameters.AddWithValue("h_fin", tb_fin.Text); comando.Parameters.AddWithValue("desc", tb_desc.Text); comando.Parameters.AddWithValue("ficha", Convert.ToDecimal(tb_ficha.Text)); comando.Parameters.AddWithValue("bandera", Convert.ToDecimal(tb_bandera.Text)); if (cb_habilitado.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habilitado.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Turnos SET Tu_Habilitado=@habi WHERE Tu_Descripcion = '" + tb_desc.Text + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmTurno/AbmTurno.cs
C#
asf20
7,481
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class AsignChoferAuto : Form { private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public AsignChoferAuto() { InitializeComponent(); fecha = dtp_fecha.Value; } public AsignChoferAuto(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; auto_text = auto_txt; chofer_id = chofer; chofer_text = chofer_txt; turno_id = turno; turno_text = turno_txt; InitializeComponent(); dtp_fecha.Value = fecha; tb_auto.Text = auto_text; tb_chofer.Text = chofer_text; tb_turno.Text = turno_text; } private void aceptar_Click_1(object sender, EventArgs e) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getFecAutCho(fecha, auto_id, chofer_id), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("La combinacion Fecha-Auto-Chofer ya existe en la BD"); } else { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_ACA = new SqlCommand(Modelo.SqlQueries.addACA( fecha, auto_id, chofer_id, turno_id), con); comando_add_ACA.ExecuteNonQuery(); MessageBox.Show("Asignacion Chofer-Auto agregada"); Login.Login.mainForm.openForm(new AsignChoferAuto()); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void bt_auto_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Auto(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void bt_chofer_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Chofer(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void bt_turno_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Turno(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AsignChoferAuto/AsignChoferAuto.cs
C#
asf20
4,162
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Auto : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Auto(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); busqueda_marca_cb.DataSource = ds.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_reloj_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_reloj_cb.DisplayMember = "Marca"; busqueda_reloj_cb.ValueMember = "Id"; busqueda_reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; auto_id = Convert.ToInt32(row.Cells["Id"].Value); auto_text = String.Concat(row.Cells["Marca"].Value, " - ", row.Cells["Model"].Value); Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutoFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_patente_tb.Text, busqueda_licencia_tb.Text, busqueda_reloj_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_reloj_cb.SelectedValue)), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Auto.cs
C#
asf20
4,340
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Turno : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Turno(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; for (int i = 0; i < dt.Rows.Count; i++) { cb_desc.Items.Add(dt.Rows[i]["Tu_Descripcion"]); } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void Listado_Load(object sender, EventArgs e) { } private void cb_desc_SelectedIndexChanged(object sender, EventArgs e) { string curItem = cb_desc.SelectedItem.ToString(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Habilitado = 1 AND Tu_descripcion = '" + curItem + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 7) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewCell desc_cell = dataGridView1.Rows[e.RowIndex].Cells[3]; Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, chofer_id, chofer_text, Convert.ToInt32(cell.Value.ToString()), desc_cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_busqueda.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Habilitado = 1 AND Tu_descripcion LIKE '" + tb_busqueda.Text + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Turno.cs
C#
asf20
4,298
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Chofer : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Chofer(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void Listado_Chofer_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewCell cell_nombre = dataGridView1.Rows[e.RowIndex].Cells[1]; DataGridViewCell cell_apellido = dataGridView1.Rows[e.RowIndex].Cells[2]; Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, Convert.ToInt32(cell.Value.ToString()), String.Concat(cell_nombre.Value.ToString(), " - ", cell_apellido.Value.ToString()), turno_id, turno_text)); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string dni; if (tb_dni.Text == "") { dni = "0"; } else { dni = tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '" + tb_nombre.Text + "' OR Ch_Apellido LIKE '" + tb_apellido.Text + "' OR Ch_Dni = " + dni + " AND Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Chofer.cs
C#
asf20
4,872
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Modelo { public static class Modelo { //public static System.Data.SqlClient.SqlConnection con; public const string con_str = "Data Source=localhost\\SQLSERVER2005; Initial Catalog=GD1C2012; User ID = gd; Password = gd2012"; public static SqlConnection createConnection() { SqlConnection con = new SqlConnection(); con.ConnectionString = con_str; return con; } public static void openConnection(SqlConnection con) { con.Open(); } public static void closeConnection(SqlConnection con) { con.Close(); } } public class User { public void getRoles() { } } public class Roles { public void getPermissions() { } } public class Permissions { public static Dictionary<string, int> PermissionsDict= new Dictionary<string,int>() { {"ABM de Cliente",1}, {"ABM de Rol",2}, {"ABM de Usuario",3}, {"ABM de Auto",4}, {"ABM de Reloj",5}, {"ABM de Chofer",6}, {"ABM de Turno",7}, {"Asignación Chofer-Auto",8}, {"Registro de Viajes",9}, {"Rendición de Cuenta del Chofer",10}, {"Facturación del Cliente",11}, {"Listado Estadístico",12}, }; } public static class FormActions { public enum Actions { Alta, Baja, Modificacion } } public static class SqlQueries { #region Roles public static string getRoles = "SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles;"; public static string getEnabledRoles = "SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles WHERE Ro_Habilitado = 1;"; public static string getRolesFiltered(string filter_text) { return String.Format("SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles WHERE Ro_Descripcion LIKE '%{0}%';", filter_text); } public static string getRoleById(int id) { return String.Format("SELECT Id_Rol, Ro_Descripcion, Ro_Habilitado FROM NUNCA_TAXI.Roles WHERE Id_Rol = {0};", id); } public static string deleteRole(int id) { string delete_role = String.Format("UPDATE NUNCA_TAXI.Roles SET Ro_habilitado = 0 WHERE Id_Rol = {0};", id); string delete_user_role = String.Format("DELETE FROM NUNCA_TAXI.UsuariosRoles WHERE Id_Rol = {0};", id); return String.Concat(delete_role, delete_user_role); } public static string addRole(string role) { return String.Format("INSERT INTO NUNCA_TAXI.Roles(Ro_Descripcion, Ro_Habilitado)" + " VALUES('{0}',1);", role); } public static string getRoleIdByName(string role) { return String.Format("SELECT TOP 1 Id_Rol FROM NUNCA_TAXI.Roles WHERE Ro_Descripcion = '{0}';", role); } public static string addRolePermissions(int roleId, List<int> permissions) { string insert_role_permissions = String.Empty; foreach (int permission in permissions) { string insert_role_permission = String.Format("INSERT INTO NUNCA_TAXI.PermisosRoles(Id_Rol, Id_Permiso)" + " VALUES ({0}, {1});", roleId, permission); insert_role_permissions = String.Concat(insert_role_permissions, insert_role_permission); } return insert_role_permissions; } public static string updateRole(int roleId, string roleName, List<int> permissions, bool enabled) { string update_rol_info = String.Format("UPDATE NUNCA_TAXI.Roles SET Ro_Descripcion = '{1}', Ro_Habilitado = {2} " + "WHERE Id_Rol = {0};", roleId, roleName, Convert.ToInt32(enabled)); string delete_roles_permissions = String.Format("DELETE FROM NUNCA_TAXI.PermisosRoles WHERE Id_Rol = {0};", roleId); string update_roles_permissions = String.Concat(update_rol_info, delete_roles_permissions); foreach (int permission in permissions) { string update_role_permission = String.Format("INSERT INTO NUNCA_TAXI.PermisosRoles(Id_Rol, Id_Permiso)" + " VALUES ({0}, {1});", roleId, permission); update_roles_permissions = String.Concat(update_roles_permissions, update_role_permission); } return update_roles_permissions; } public static string getRolePermissions(int roleId) { return String.Format("SELECT Id_Permiso FROM NUNCA_TAXI.PermisosRoles WHERE Id_Rol = {0};", roleId); } #endregion #region Users public static string getUsers = "SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios;"; public static string getEnabledUsers = "SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_habilitado = 1;"; public static string getUsersFiltered(string filter_text) { return String.Format("SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario LIKE '%{0}%';", filter_text); } public static string getUserById(int id) { return String.Format("SELECT Id_Usuario, Us_Usuario, Us_Habilitado FROM NUNCA_TAXI.Usuarios WHERE Id_Usuario = {0};", id); } public static string getUserIdByUsername(string username) { return String.Format("SELECT Id_Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario = '{0}';", username); } public static string deleteUser(int id) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = 0 WHERE Id_Usuario = {0};", id); } public static string getUserRoles(int userId) { return String.Format("SELECT Rol.Id_Rol as Id, Rol.Ro_Descripcion as Descripcion, " + "ISNULL((SELECT 1 FROM NUNCA_TAXI.UsuariosRoles " + "WHERE Id_Rol = Rol.Id_Rol " + "AND Id_usuario = {0}), 0) as Habilitado " + "FROM NUNCA_TAXI.Roles Rol;", userId); } public static string addUser(string user, string passwd) { return String.Format("INSERT INTO NUNCA_TAXI.Usuarios(Us_Habilitado, Us_Usuario, Us_Password)" + " VALUES(1,'{0}','{1}');", user, Login.Login.getSHA256(passwd)); } public static string addUserRoles(int userId, List<int> roles) { string insert_user_roles = String.Empty; foreach (int role in roles) { string insert_user_role = String.Format("INSERT INTO NUNCA_TAXI.UsuariosRoles(Id_Usuario, Id_Rol)" + " VALUES ({0}, {1});",userId, role); insert_user_roles = String.Concat(insert_user_roles, insert_user_role); } return insert_user_roles; } public static string updateUser(int userId, string passwd, List<int> roles) { string update_user = String.Empty; if (!String.IsNullOrEmpty(passwd)) { update_user = String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Password = '{0}' " + "WHERE Id_Usuario = {1};", passwd, userId); } string delete_user_roles = String.Format("DELETE FROM NUNCA_TAXI.UsuariosRoles WHERE Id_Usuario = {0};", userId); string update_user_roles = String.Concat(update_user, delete_user_roles); foreach (int role in roles) { string update_user_role = String.Format("INSERT INTO NUNCA_TAXI.UsuariosRoles(Id_Usuario, Id_Rol)" + " VALUES ({0}, {1});", userId, role); update_user_roles = String.Concat(update_user_roles, update_user_role); } return update_user_roles; } public static string getUserInfo(string user) { return String.Format("SELECT Us_Usuario, Us_Password, Us_Login_Failed, Us_Habilitado FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario = '{0}';",user); } public static string resetLoginFails(string user) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Login_Failed = 0 WHERE Us_Usuario = '{0}'", user); } public static string disableUser(string user) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = 0 WHERE Us_Usuario = '{0}'", user); } public static string incUserLoginFailed(string user, int fails) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Login_Failed = {1} WHERE Us_Usuario = '{0}'", user, fails); } #endregion #region Auto public static string getAutoFiltered(int marca, string modelo, string patente, string licencia, int reloj){ string marca_where = String.Empty; string modelo_where = String.Empty; string patente_where = String.Empty; string licencia_where = String.Empty; string reloj_where = String.Empty; string auto_filtered = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj"; if (marca != -1) { marca_where = String.Format(" AND T.Id_MarcaTaxi = {0}", Convert.ToInt32(marca)); auto_filtered = String.Concat(auto_filtered, marca_where); } if (!String.IsNullOrEmpty(modelo)) { modelo_where = String.Format(" AND T.Ta_Modelo LIKE '%{0}%'", modelo); auto_filtered = String.Concat(auto_filtered, modelo_where); } if (!String.IsNullOrEmpty(patente)) { patente_where = String.Format(" AND T.Ta_Patente LIKE '%{0}%'", patente); auto_filtered = String.Concat(auto_filtered, patente_where); } if (!String.IsNullOrEmpty(licencia)) { licencia_where = String.Format(" AND T.Ta_Licencia LIKE '%{0}%'", licencia); auto_filtered = String.Concat(auto_filtered, licencia_where); } if (reloj != -1) { reloj_where = String.Format(" AND T.Id_Reloj = {0}", Convert.ToInt32(reloj)); auto_filtered = String.Concat(auto_filtered, reloj_where); } auto_filtered = String.Concat(auto_filtered, ";"); return auto_filtered; } public static string getAutos() { return "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj;"; } public static string getAutosComplete = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj, T.Ta_Rodado as Rodado, T.Ta_Habilitado as Habilitado " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj;;"; public static string getEnabledAutos = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj AND T.Ta_Habilitado = 1;"; public static string getAutoById(int id) { string getEnabledAutosById = "SELECT T.Id_Taxi as ID, T.Id_MarcaTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, T.Id_Reloj as Reloj, T.Ta_Rodado as Rodado, T.Ta_Habilitado as Habilitado " + "FROM NUNCA_TAXI.Taxis T " + "WHERE T.Id_Taxi = {0};"; return String.Format(getEnabledAutosById, id); } public static string deleteAuto(int id) { return String.Format("UPDATE NUNCA_TAXI.Taxis SET Ta_Habilitado = 0 WHERE Id_Taxi = {0};", id); } public static string updateAuto(int id, int marca, int reloj, string licencia, string modelo, string patente, string rodado, bool hab) { return String.Format("UPDATE NUNCA_TAXI.Taxis SET Id_MarcaTaxi = {1}, Id_Reloj = {2} , Ta_Licencia = '{3}', Ta_Modelo = '{4}', Ta_Patente = '{5}', Ta_Rodado = '{6}', Ta_Habilitado = {7} " + "WHERE Id_Taxi = {0};", id, marca, reloj, licencia, modelo, patente, rodado, Convert.ToInt32(hab)); } public static string addAuto(int marca, int reloj, string licencia, string modelo, string patente, string rodado, bool hab) { return String.Format("INSERT INTO NUNCA_TAXI.Taxis(Id_MarcaTaxi, Id_Reloj, Ta_Licencia, Ta_Modelo, Ta_Patente, Ta_Rodado, Ta_Habilitado) " + "VALUES({0}, {1}, '{2}', '{3}', '{4}', '{5}', {6})", marca, reloj, licencia, modelo, patente, rodado, Convert.ToInt32(hab)); } #endregion #region Relojes public static string getEnabledRelojes = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj AND R.Re_Habilitado = 1;"; public static string getRelojes = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj;"; public static string getRelojFiltered(int marca, string modelo, string nro_serie){ string marca_where = String.Empty; string modelo_where = String.Empty; string nro_serie_where = String.Empty; string reloj_filtered = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj"; if (marca != -1) { marca_where = String.Format(" AND R.Id_MarcaReloj = {0}", Convert.ToInt32(marca)); reloj_filtered = String.Concat(reloj_filtered, marca_where); } if (!String.IsNullOrEmpty(modelo)) { modelo_where = String.Format(" AND R.Re_Modelo LIKE '%{0}%'", modelo); reloj_filtered = String.Concat(reloj_filtered, modelo_where); } if (!String.IsNullOrEmpty(nro_serie)) { nro_serie_where = String.Format(" AND R.Re_NoSerie LIKE '%{0}%'", nro_serie); reloj_filtered = String.Concat(reloj_filtered, nro_serie_where); } reloj_filtered = String.Concat(reloj_filtered, ";"); return reloj_filtered; } public static string getRelojById(int id) { return String.Format("SELECT R.Re_Habilitado as Habilitado, R.Re_Fecha_Ver as FecVerific, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, R.Id_MarcaReloj as Marca " + "FROM NUNCA_TAXI.Relojes R " + "WHERE R.Id_Reloj = {0};", id); } public static string addReloj(int id_marca_reloj, string modelo, string nroserie, DateTime verific, bool hab) { return String.Format("INSERT INTO NUNCA_TAXI.Relojes(Id_MarcaReloj, Re_modelo, Re_NoSerie, Re_Habilitado, Re_Fecha_Ver) " + "VALUES({0}, '{1}', '{2}', {3}, '{4}');", id_marca_reloj, modelo, nroserie, Convert.ToInt32(hab), String.Format("{0:d/M/yyyy HH:mm:ss}", verific)); } public static string deleteReloj(int id) { return String.Format("UPDATE NUNCA_TAXI.Relojes SET Re_Habilitado = 0 WHERE Id_Reloj = {0};", id); } public static string updateReloj(int id, int id_marca_reloj, string modelo, string nroserie, DateTime verific, bool hab) { return String.Format("UPDATE NUNCA_TAXI.Relojes SET Id_MarcaReloj = {0}, Re_modelo = '{1}', Re_NoSerie = '{2}', Re_Habilitado = {3}, Re_Fecha_Ver = '{4}' " + "WHERE Id_Reloj = {5};", id_marca_reloj, modelo, nroserie, Convert.ToInt32(hab), String.Format("{0:d/M/yyyy HH:mm:ss}", verific), id); } #endregion #region MarcasTaxi public static string getMarcasTaxi() { return "SELECT Id_MarcaTaxi as Id, Ma_NombreTaxi as Marca FROM NUNCA_TAXI.MarcasTaxi;"; } #endregion #region MarcasReloj public static string getMarcasReloj() { return "SELECT Id_MarcaReloj as Id, Ma_NombreReloj as Marca FROM NUNCA_TAXI.MarcasReloj;"; } public static string getMarcaModeloReloj() { return "SELECT R.Id_Reloj as Id, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj;"; } #endregion public static string addACA(DateTime fecha, int auto_id, int chofer_id, int turno_id) { return String.Format("INSERT INTO NUNCA_TAXI.ChoferesTurnosTaxis(Id_Chofer, Id_Turno, Id_Taxi, Fecha) " + " VALUES({2},{3},{1},'{0}');",String.Format("{0:d/M/yyyy}", fecha), auto_id,chofer_id,turno_id); } public static string getClientes = "SELECT Id_Cliente as Id, (Cl_Nombre + ' - ' + Cl_Apellido) as Cliente FROM NUNCA_TAXI.Clientes;"; public static string getFacturas(int id_cliente, DateTime ini, DateTime fin) { return String.Format("SELECT (Ch.Ch_Nombre + ' - ' + Ch.Ch_Apellido) as Chofer, V.Vi_Cant_Fichas as CantidadFichas, V.Vi_Importe as Importe, V.Vi_Fecha as Fecha, T.Tu_Descripcion as Turno " + "FROM NUNCA_TAXI.Choferes Ch, NUNCA_TAXI.Viajes V, NUNCA_TAXI.Turnos T " + "WHERE V.Id_Chofer = Ch.Id_Chofer AND V.Id_Turno = T.Id_Turno AND V.Id_Cliente = {0} AND V.Vi_Fecha <= '{1}' AND V.Vi_Fecha >= '{2}' AND Vi_FFactura_Ini IS NULL AND Vi_FFactura_Fin IS NULL ;", id_cliente, String.Format("{0:d/M/yyyy HH:mm:ss}", fin), String.Format("{0:d/M/yyyy HH:mm:ss}", ini)); } public static string updateFacturas(int id_cliente, DateTime ini, DateTime fin) { return String.Format("UPDATE NUNCA_TAXI.Viajes SET Vi_FFactura_Ini = '{2}', Vi_FFactura_Fin = '{1}' WHERE Id_Cliente = {0};", id_cliente, String.Format("{0:d/M/yyyy HH:mm:ss}", fin), String.Format("{0:d/M/yyyy HH:mm:ss}", ini)); } public static string getTaxiMellizo(string patente, string licencia, int reloj) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.Taxis T " + "WHERE Ta_Patente = '{0}' AND Ta_Licencia = '{1}' AND Id_Reloj = {2}", patente, licencia, reloj); } public static string getRelojUsado(int reloj) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.Taxis T " + "WHERE Id_Reloj = {0} AND Ta_Habilitado = 1;", reloj); } public static string getFecAutCho(DateTime fecha, int autoId, int choferId) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.ChoferesTurnosTaxis " + "WHERE Id_Chofer = {0} AND Id_Taxi = {1} AND Fecha = '{2}';", choferId, autoId, String.Format("{0:d/M/yyyy}", fecha)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Modelo/Modelo.cs
C#
asf20
22,396
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmReloj { public partial class Listado_Reloj : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Reloj(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_marca_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRelojes, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getRelojes, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmReloj(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRelojFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_nroserie_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRelojes, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmReloj/Listado_Reloj.cs
C#
asf20
3,403
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmReloj { public partial class AbmReloj : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmReloj(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; reloj_cb.Enabled = false; tb_modelo.Enabled = false; tb_nroserie.Enabled = false; verific_dtp.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar.Text = "Modificar"; break; } } public AbmReloj(Modelo.FormActions.Actions runAction) { InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_get_autos = new SqlCommand(Modelo.SqlQueries.getRelojById(selected_elem), con3); SqlDataReader reader = comando_get_autos.ExecuteReader(); while (reader.Read()) { reloj_cb.SelectedValue = Convert.ToInt32(reader["Marca"]); tb_modelo.Text = reader["Modelo"].ToString(); tb_nroserie.Text = reader["NroSerie"].ToString(); verific_dtp.Value = Convert.ToDateTime(reader["FecVerific"]); cb_hab.Checked = (Boolean)reader["Habilitado"]; } } } private void aceptar_Click(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_reloj = new SqlCommand(Modelo.SqlQueries.addReloj( Convert.ToInt32(reloj_cb.SelectedValue), tb_modelo.Text, tb_nroserie.Text, verific_dtp.Value, true), con); comando_add_reloj.ExecuteNonQuery(); MessageBox.Show("Reloj agregado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getRelojUsado(selected_elem), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Reloj estaba siendo usado por un taxi habilitado"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteReloj(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show("Reloj eliminado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateReloj(selected_elem, Convert.ToInt32(reloj_cb.SelectedValue), tb_modelo.Text, tb_nroserie.Text, verific_dtp.Value, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show("Reloj modificado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/AbmReloj/AbmReloj.cs
C#
asf20
7,882
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Listado { public partial class Listado : Form { public Listado() { InitializeComponent(); cb_tipo_listado.Items.Add("choferes"); cb_tipo_listado.Items.Add("taxis"); cb_tipo_listado.Items.Add("clientes"); cb_trimestre.Items.Add("1"); cb_trimestre.Items.Add("2"); cb_trimestre.Items.Add("3"); cb_trimestre.Items.Add("4"); } private void Listado_Load(object sender, EventArgs e) { } private void cb_tipo_listado_SelectedIndexChanged(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (tb_anio.Text != "" && cb_trimestre.SelectedIndex.ToString() != "" && cb_tipo_listado.SelectedIndex.ToString() != "") { string fecha_ini = ""; string fecha_fin = ""; string consulta = ""; if (cb_trimestre.SelectedItem.ToString() == "1") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-01-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-03-31 23:59:59', 120)"; } if (cb_trimestre.SelectedItem.ToString() == "2") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-04-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-06-30 23:59:59', 120)"; } if (cb_trimestre.SelectedItem.ToString() == "3") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-07-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-09-30 23:59:59', 120)"; } if (cb_trimestre.SelectedItem.ToString() == "4") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-10-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-12-31 23:59:59', 120)"; } //=============================================================================================== //0: choferes //=============================================================================================== if (cb_tipo_listado.SelectedIndex.ToString() == "0") { consulta += "SELECT TOP (5) Id_Chofer,(SELECT Ch_Dni FROM NUNCA_TAXI.Choferes WHERE (NUNCA_TAXI.Viajes.Id_Chofer = Id_Chofer)) AS DNI,(SELECT Ch_Nombre FROM NUNCA_TAXI.Choferes AS Choferes_2 WHERE (NUNCA_TAXI.Viajes.Id_Chofer = Id_Chofer)) AS NOMBRE,(SELECT Ch_Apellido FROM NUNCA_TAXI.Choferes AS Choferes_1 WHERE (NUNCA_TAXI.Viajes.Id_Chofer = Id_Chofer)) AS APELLIDO, SUM(Vi_Importe) AS GastoTotal FROM NUNCA_TAXI.Viajes WHERE (Vi_Fecha BETWEEN "; consulta += fecha_ini; consulta += " AND "; consulta += fecha_fin; consulta += ") GROUP BY Id_Chofer ORDER BY gastototal DESC"; SqlDataAdapter da = new SqlDataAdapter(consulta , con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } //=============================================================================================== //1: taxis //=============================================================================================== if (cb_tipo_listado.SelectedIndex.ToString() == "1") { consulta += "SELECT TOP (5) Id_Taxi,(SELECT Ta_Patente FROM NUNCA_TAXI.Taxis WHERE (NUNCA_TAXI.Viajes.Id_Taxi = Id_Taxi)) AS patente,(SELECT Ta_Licencia FROM NUNCA_TAXI.Taxis AS Choferes_2 WHERE (NUNCA_TAXI.Viajes.Id_Taxi = Id_Taxi)) AS licencia,(SELECT Ma_NombreTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE (Id_MarcaTaxi =(SELECT Id_MarcaTaxi FROM NUNCA_TAXI.Taxis AS Taxis_1 WHERE (NUNCA_TAXI.Viajes.Id_Taxi = Id_Taxi)))) AS MARCA, SUM(Vi_Importe) AS GastoTotal FROM NUNCA_TAXI.Viajes WHERE (Vi_Fecha BETWEEN "; consulta += fecha_ini; consulta += " AND "; consulta += fecha_fin; consulta += ")GROUP BY Id_Taxi ORDER BY gastototal DESC"; SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } //=============================================================================================== //2: clientes //=============================================================================================== if (cb_tipo_listado.SelectedIndex.ToString() == "2") { consulta += "SELECT TOP (5) Id_Cliente,(SELECT Cl_Dni FROM NUNCA_TAXI.Clientes WHERE (NUNCA_TAXI.Viajes.Id_Cliente = Id_Cliente)) AS DNI,(SELECT Cl_Nombre FROM NUNCA_TAXI.Clientes AS Clientes_2 WHERE (NUNCA_TAXI.Viajes.Id_Cliente = Id_Cliente)) AS NOMBRE,(SELECT Cl_Apellido FROM NUNCA_TAXI.Clientes AS Clientes_1 WHERE (NUNCA_TAXI.Viajes.Id_Cliente = Id_Cliente)) AS APELLIDO, SUM(Vi_Importe) AS GastoTotal FROM NUNCA_TAXI.Viajes WHERE (Id_Cliente != 1) AND (Vi_Fecha BETWEEN "; consulta += fecha_ini; consulta += " AND "; consulta += fecha_fin; consulta += ") GROUP BY Id_Cliente ORDER BY gastototal DESC"; SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/GestorDeFlotasDesktop/Listado/Listado.cs
C#
asf20
6,950
/*--- GRUPO: ---*//*--- INTEGRANTES: ---*/ /*--- NUNCA_TAXI ---*//*--- Dorati Hermida, Ivan ---*/ /*--- ---*//*--- Pereyra, Yohanna ---*/ /*--- CURSADA: ---*//*--- Torrente, Nicolas ---*/ /*--- 1er Cuatrimestre, 2012 ---*//*--- Schachner, Pablo ---*/ /*--- ---*//*--- ---*/ /*--- CURSO: ---*//*--- ---*/ /*--- K3151-K3051 ---*//*--- ---*/ /*=============================================================================*/ /*= =*/ /*= CREAR ESQUEMA =*/ /*= =*/ /*=============================================================================*/ CREATE SCHEMA NUNCA_TAXI GO /*=============================================================================*/ /*= =*/ /*= CREAR TABLAS =*/ /*= =*/ /*=============================================================================*/ CREATE PROCEDURE NUNCA_TAXI.CrearTablasNuncaTaxi AS BEGIN /*==== CREATE TABLE NUNCA_TAXI.MarcasReloj ====*/ CREATE TABLE NUNCA_TAXI.MarcasReloj( Id_MarcaReloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ma_NombreReloj varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Relojes ====*/ CREATE TABLE NUNCA_TAXI.Relojes( Id_Reloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_MarcaReloj numeric (18, 0) References NUNCA_TAXI.MarcasReloj(Id_MarcaReloj) NOT NULL ,Re_Modelo varchar(255) UNIQUE NOT NULL ,Re_Habilitado bit CONSTRAINT [DF_Relojes_R_Habilitado] DEFAULT ((1)) NOT NULL ,Re_Fecha_Ver datetime NOT NULL ,Re_NoSerie varchar(18) NULL) /*==== CREATE TABLE NUNCA_TAXI.Clientes ====*/ CREATE TABLE NUNCA_TAXI.Clientes( Id_Cliente numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Cl_Nombre varchar(255) NOT NULL ,Cl_Apellido varchar(255) NOT NULL ,Cl_Dni numeric(18, 0) UNIQUE NOT NULL ,Cl_Telefono numeric(18, 0) UNIQUE NOT NULL ,Cl_Direccion varchar(255) UNIQUE NOT NULL ,Cl_Mail varchar(255) NULL ,Cl_Fecha_Nac datetime NOT NULL ,Cl_Habilitado bit CONSTRAINT [DF_Clientes_Cl_Habilitacion] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Turnos ====*/ CREATE TABLE NUNCA_TAXI.Turnos( Id_Turno numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Tu_Hora_Ini numeric(18, 0) NOT NULL ,Tu_Hora_Fin numeric(18, 0) NOT NULL ,Tu_Descripcion varchar(255) UNIQUE NOT NULL ,Tu_Valor_Ficha numeric(18, 2) NOT NULL ,Tu_Valor_Bandera numeric(18, 2) NOT NULL ,Tu_Habilitado bit CONSTRAINT [DF_Turnos_Tu_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Choferes ====*/ CREATE TABLE NUNCA_TAXI.Choferes( Id_Chofer numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ch_Nombre varchar(255) NOT NULL ,Ch_Apellido varchar(255) NOT NULL ,Ch_Dni numeric(18, 0) UNIQUE NOT NULL ,Ch_Direccion varchar(255) UNIQUE NOT NULL ,Ch_Telefono numeric(18, 0) UNIQUE NOT NULL ,Ch_Mail varchar(255) NULL ,Ch_Fecha_Nac datetime NOT NULL ,Ch_Habilitado bit CONSTRAINT [DF_Choferes_Ch_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.MarcasTaxi ====*/ CREATE TABLE NUNCA_TAXI.MarcasTaxi( Id_MarcaTaxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ma_NombreTaxi varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Taxis ====*/ CREATE TABLE NUNCA_TAXI.Taxis( Id_Taxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Reloj numeric(18, 0) References NUNCA_TAXI.Relojes(Id_Reloj) NULL ,Id_MarcaTaxi numeric(18, 0) References NUNCA_TAXI.MarcasTaxi(Id_MarcaTaxi) NOT NULL ,Ta_Patente varchar(255) UNIQUE NOT NULL ,Ta_Licencia varchar(255) UNIQUE NOT NULL ,Ta_Rodado varchar(250) NOT NULL ,Ta_Modelo varchar(255) NOT NULL ,Ta_Habilitado bit CONSTRAINT [DF_Taxis_Ta_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.TiposViaje ====*/ CREATE TABLE NUNCA_TAXI.TiposViaje( Id_TipoViaje numeric(18, 0) PRIMARY KEY IDENTITY(0,1) NOT NULL ,Ti_DescripcionTipoViaje varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Viajes ====*/ CREATE TABLE NUNCA_TAXI.Viajes( Id_Viaje numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Cliente numeric(18, 0) References NUNCA_TAXI.Clientes(Id_Cliente) NOT NULL ,Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Id_Taxi numeric(18, 0) References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL ,Id_TipoViaje numeric(18, 0) References NUNCA_TAXI.TiposViaje(Id_TipoViaje) NOT NULL ,Vi_Cant_Fichas numeric(18, 0) NOT NULL ,Vi_Fecha datetime NOT NULL ,Vi_Importe numeric(18, 2) NOT NULL ,Vi_FechaRendido datetime NULL ,Vi_FFactura_Ini datetime NULL ,Vi_FFactura_Fin datetime NULL) /*==== CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis ====*/ CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis( Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Id_Taxi numeric(18, 0) References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL ,Fecha datetime CONSTRAINT [DF_ChoferesTurnosTaxis_Cat_Fecha] DEFAULT ((getdate())) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Facturas ====*/ CREATE TABLE NUNCA_TAXI.Facturas( Id_Factura numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Cliente numeric(18, 0) References NUNCA_TAXI.Clientes(Id_Cliente) NOT NULL ,Fa_Feha_Inicio datetime NOT NULL ,Fa_Fecha_Fin datetime NOT NULL ,Fa_Importe numeric(18, 2) NOT NULL ,Fa_Estado bit CONSTRAINT [DF_Facturas_Fa_Estado] DEFAULT ((0)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Rendiciones ====*/ CREATE TABLE NUNCA_TAXI.Rendiciones( Id_Rendicion numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Ren_Fecha datetime NOT NULL ,Ren_Importe numeric(18, 2) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Usuarios ====*/ CREATE TABLE NUNCA_TAXI.Usuarios( Id_Usuario numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Us_Usuario varchar(255) UNIQUE NOT NULL ,Us_Password varchar(255) NOT NULL ,Us_Habilitado bit CONSTRAINT [DF_Usuarios_Us_Habilitado] DEFAULT ((1)) NOT NULL ,Us_Login_Failed numeric(18,0) CONSTRAINT [DF_Usuarios_Us_Login_Failed] DEFAULT ((0)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Roles ====*/ CREATE TABLE NUNCA_TAXI.Roles( Id_Rol numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ro_Descripcion varchar(255) UNIQUE NOT NULL ,Ro_Habilitado bit CONSTRAINT [DF_Roles_Ro_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.UsuariosRoles ====*/ CREATE TABLE NUNCA_TAXI.UsuariosRoles( Id_Usuario numeric(18, 0) References NUNCA_TAXI.Usuarios(Id_Usuario) NOT NULL ,Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Permisos ====*/ CREATE TABLE NUNCA_TAXI.Permisos( Id_Permiso numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Pe_Descripcion varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.PermisosRoles ====*/ CREATE TABLE NUNCA_TAXI.PermisosRoles( Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL ,Id_Permiso numeric(18, 0) References NUNCA_TAXI.Permisos(Id_Permiso) NOT NULL) END GO /*=============================================================================*/ /*= =*/ /*= MIGRAR Y COMPLETAR TABLAS =*/ /*= =*/ /*=============================================================================*/ CREATE PROCEDURE NUNCA_TAXI.CargarTablasNuncaTaxi AS BEGIN /*==== MIGRAR NUNCA_TAXI.MarcasReloj ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.MarcasReloj (Ma_NombreReloj) SELECT DISTINCT Reloj_Marca FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Relojes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Relojes (Id_MarcaReloj ,Re_Modelo ,Re_Fecha_Ver) SELECT DISTINCT (SELECT Id_MarcaReloj FROM NUNCA_TAXI.MarcasReloj WHERE Ma_NombreReloj=gd_esquema.Maestra.Reloj_Marca) ,Reloj_Modelo ,Reloj_Fecha_Ver FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Clientes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre,Cl_Apellido,Cl_Dni,Cl_Telefono,Cl_Direccion,Cl_Fecha_Nac) VALUES ('Desconocido','Desconocido',00000000,00000000 ,'Todas partes',getdate()) INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre ,Cl_Apellido ,Cl_Dni ,Cl_Telefono ,Cl_Direccion ,Cl_Mail ,Cl_Fecha_Nac ,Cl_Habilitado) SELECT DISTINCT Cliente_Nombre, Cliente_Apellido, Cliente_Dni, Cliente_Telefono, Cliente_Direccion, Cliente_Mail, Cliente_Fecha_Nac,1 FROM gd_esquema.Maestra WHERE (Auto_Marca IS NOT NULL) AND (Cliente_Nombre IS NOT NULL) /*==== MIGRAR NUNCA_TAXI.Turnos ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Turnos (Tu_Hora_Ini ,Tu_Hora_Fin ,Tu_Descripcion ,Tu_Valor_Ficha ,Tu_Valor_Bandera) SELECT DISTINCT Turno_Hora_Inicio, Turno_Hora_Fin, Turno_Descripcion, Turno_Valor_Ficha, Turno_Valor_Bandera FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Choferes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Choferes (Ch_Nombre ,Ch_Apellido ,Ch_Dni ,Ch_Direccion ,Ch_Telefono ,Ch_Mail ,Ch_Fecha_Nac) SELECT DISTINCT Chofer_Nombre, Chofer_Apellido, Chofer_Dni, Chofer_Direccion, Chofer_Telefono, Chofer_Mail, Chofer_Fecha_Nac FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.MarcasTaxi ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.MarcasTaxi (Ma_NombreTaxi) SELECT DISTINCT Auto_Marca FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Taxis ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Taxis (Id_Reloj,Id_MarcaTaxi,Ta_Patente,Ta_Licencia,Ta_Rodado,Ta_Modelo) SELECT DISTINCT (SELECT Id_Reloj FROM NUNCA_TAXI.Relojes WHERE Re_Modelo=gd_esquema.Maestra.Reloj_Modelo) ,(SELECT Id_MarcaTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE Ma_NombreTaxi=gd_esquema.Maestra.Auto_Marca) ,Auto_Patente ,Auto_Licencia ,Auto_Rodado ,Auto_Modelo FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.TiposViaje====*/ INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Calle') INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES ('Cliente') /*==== MIGRAR NUNCA_TAXI.Viajes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Viajes (Id_Cliente ,Id_Chofer ,Id_Turno ,Id_Taxi ,Vi_Cant_Fichas ,Vi_Fecha ,Id_TipoViaje ,Vi_Importe) SELECT DISTINCT (CASE WHEN M.cliente_dni IS NOT NULL THEN(SELECT Cl.id_cliente) WHEN M.cliente_dni IS NULL THEN(SELECT 1) END) ,Ch.id_chofer ,Tu.id_turno ,Ta.id_taxi ,M.Viaje_Cant_Fichas ,M.Viaje_Fecha ,(CASE WHEN M.cliente_dni IS NOT NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Cliente') WHEN M.cliente_dni IS NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Calle') END) ,(M.Viaje_Cant_Fichas*Tu.Tu_Valor_ficha)+Tu.Tu_Valor_Bandera FROM NUNCA_TAXI.Clientes Cl, NUNCA_TAXI.Choferes Ch, NUNCA_TAXI.Turnos Tu, NUNCA_TAXI.Taxis Ta,gd_esquema.Maestra M WHERE (Cl_Dni = Cliente_Dni or Cliente_Dni IS NULL) AND (Ch_Dni = Chofer_Dni) AND (Tu_Descripcion = Turno_Descripcion) AND (Ta_Patente = Auto_Patente) AND (M.Rendicion_Fecha IS NULL) AND (M.Factura_Fecha_Inicio IS NULL) AND (M.Factura_Fecha_Fin IS NULL) UPDATE GD1C2012.NUNCA_TAXI.Viajes SET Vi_FechaRendido=M.Rendicion_Fecha FROM gd_esquema.Maestra AS M INNER JOIN [NUNCA_TAXI].[Choferes] ON Choferes.Ch_Dni = M.Chofer_Dni INNER JOIN [NUNCA_TAXI].[Clientes] ON Clientes.Cl_Dni = isnull(M.Cliente_dni,00000000) INNER JOIN [NUNCA_TAXI].[Taxis] ON Taxis.Ta_Patente = M.Auto_Patente INNER JOIN [NUNCA_TAXI].[Turnos] ON Turnos.Tu_Descripcion = M.Turno_Descripcion INNER JOIN [NUNCA_TAXI].[Viajes] ON Viajes.Vi_Fecha = M.Viaje_Fecha WHERE (M.Rendicion_Fecha IS NOT NULL) AND (Clientes.id_Cliente = Viajes.Id_Cliente) AND (Choferes.Id_Chofer = Viajes.Id_Chofer) AND (Turnos.Id_Turno = Viajes.Id_Turno) AND (Taxis.Id_Taxi = Viajes.Id_Taxi) UPDATE GD1C2012.NUNCA_TAXI.Viajes SET Vi_FFactura_Ini = M.Factura_Fecha_Inicio, Vi_FFactura_Fin = M.Factura_Fecha_Fin FROM gd_esquema.Maestra AS M INNER JOIN [NUNCA_TAXI].[Choferes] ON Choferes.Ch_Dni = M.Chofer_Dni INNER JOIN [NUNCA_TAXI].[Clientes] ON Clientes.Cl_Dni = isnull(M.Cliente_dni,00000000) INNER JOIN [NUNCA_TAXI].[Taxis] ON Taxis.Ta_Patente = M.Auto_Patente INNER JOIN [NUNCA_TAXI].[Turnos] ON Turnos.Tu_Descripcion = M.Turno_Descripcion INNER JOIN [NUNCA_TAXI].[Viajes] ON Viajes.Vi_Fecha = M.Viaje_Fecha WHERE (M.factura_fecha_fin IS NOT NULL) AND (M.factura_fecha_inicio IS NOT NULL) AND (M.Cliente_Dni IS NOT NULL) AND (Clientes.id_Cliente = Viajes.Id_Cliente) AND (Choferes.Id_Chofer = Viajes.Id_Chofer) AND (Turnos.Id_Turno = Viajes.Id_Turno) AND (Taxis.Id_Taxi = Viajes.Id_Taxi) /*==== MIGRAR NUNCA_TAXI.ChoferesTurnosTaxis ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.ChoferesTurnosTaxis (Id_Chofer,Id_Turno,Id_Taxi) SELECT DISTINCT (SELECT id_chofer FROM NUNCA_TAXI.Choferes Where Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos Where Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Facturas ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Facturas (Id_Cliente,Fa_Feha_Inicio,Fa_Fecha_Fin,Fa_Importe) SELECT Id_Cliente,Vi_FFactura_Ini,Vi_FFactura_Fin,SUM(Vi_Importe) AS ImporteDeFactura FROM NUNCA_TAXI.Viajes WHERE (Vi_FFactura_Ini IS NOT NULL) AND (Vi_FFactura_Fin IS NOT NULL) GROUP BY Id_Cliente, Vi_FFactura_Ini, Vi_FFactura_Fin /*==== MIGRAR NUNCA_TAXI.Rendiciones ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Rendiciones (Id_Chofer,Id_Turno,Ren_Fecha,Ren_Importe) SELECT Id_Chofer, Id_Turno, Vi_FechaRendido, SUM(Vi_Importe) AS ImporteDeRendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NOT NULL) GROUP BY Id_Chofer, Id_Turno, Vi_FechaRendido /*==== MIGRAR NUNCA_TAXI.Usuarios ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Usuarios (Us_Usuario,Us_Password) VALUES ('admin','Utd0YrJJhxdcjX2rkBpZZ+kn/8jQtuSiNOB6SuxeNyQ=') /*==== MIGRAR NUNCA_TAXI.Permisos ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Rol') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Usuario') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Auto') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Reloj') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Chofer') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Turno') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Asignacion Chofer-Auto') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Registro de Viajes') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Rendicion de Cuenta del Chofer') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Facturacion del Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Listado Estadistico') /*==== MIGRAR NUNCA_TAXI.Roles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Roles (Ro_Descripcion) VALUES ('Administrador del Generaal') /*==== MIGRAR NUNCA_TAXI.UsuariosRoles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.UsuariosRoles (Id_Usuario,Id_Rol) VALUES (1,1) /*==== MIGRAR NUNCA_TAXI.PermisosRoles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,1) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,2) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,3) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,4) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,5) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,6) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,7) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,8) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,9) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,10) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,11) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,12) END GO /*=============================================================================*/ /*= =*/ /*= EJECUCION DE PROCEDIMIENTOS =*/ /*= =*/ /*=============================================================================*/ /*==== EXEC NUNCA_TAXI.CrearTablasNuncaTaxi ====*/ EXEC NUNCA_TAXI.CrearTablasNuncaTaxi GO /*==== EXEC NUNCA_TAXI.CargarTablasNuncaTaxi ====*/ EXEC NUNCA_TAXI.CargarTablasNuncaTaxi GO
09066bd9cc483c8928891679d8ad73b5
trunk/script_creacion_inicial29.sql
TSQL
asf20
17,886
/*--- GRUPO: ---*//*--- INTEGRANTES: ---*/ /*--- NUNCA_TAXI ---*//*--- Dorati Hermida, Ivan ---*/ /*--- ---*//*--- Pereyra, Yohanna ---*/ /*--- CURSADA: ---*//*--- Torrente, Nicolas ---*/ /*--- 1er Cuatrimestre, 2012 ---*//*--- Schachner, Pablo ---*/ /*--- ---*//*--- ---*/ /*--- CURSO: ---*//*--- ---*/ /*--- K3151-K3051 ---*//*--- ---*/ /*=============================================================================*/ /*= =*/ /*= CREAR ESQUEMA =*/ /*= =*/ /*=============================================================================*/ CREATE SCHEMA NUNCA_TAXI GO /*=============================================================================*/ /*= =*/ /*= CREAR TABLAS =*/ /*= =*/ /*=============================================================================*/ CREATE PROCEDURE NUNCA_TAXI.CrearTablasNuncaTaxi AS BEGIN /*==== CREATE TABLE NUNCA_TAXI.MarcasReloj ====*/ CREATE TABLE NUNCA_TAXI.MarcasReloj( Id_MarcaReloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ma_NombreReloj varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Relojes ====*/ CREATE TABLE NUNCA_TAXI.Relojes( Id_Reloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_MarcaReloj numeric (18, 0) References NUNCA_TAXI.MarcasReloj(Id_MarcaReloj) NOT NULL ,Re_Modelo varchar(255) UNIQUE NOT NULL ,Re_Habilitado bit CONSTRAINT [DF_Relojes_R_Habilitado] DEFAULT ((1)) NOT NULL ,Re_Fecha_Ver datetime NOT NULL ,Re_NoSerie varchar(18) NULL) /*==== CREATE TABLE NUNCA_TAXI.Clientes ====*/ CREATE TABLE NUNCA_TAXI.Clientes( Id_Cliente numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Cl_Nombre varchar(255) NOT NULL ,Cl_Apellido varchar(255) NOT NULL ,Cl_Dni numeric(18, 0) UNIQUE NOT NULL ,Cl_Telefono numeric(18, 0) UNIQUE NOT NULL ,Cl_Direccion varchar(255) UNIQUE NOT NULL ,Cl_Mail varchar(255) NULL ,Cl_Fecha_Nac datetime NOT NULL ,Cl_Habilitado bit CONSTRAINT [DF_Clientes_Cl_Habilitacion] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Turnos ====*/ CREATE TABLE NUNCA_TAXI.Turnos( Id_Turno numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Tu_Hora_Ini numeric(18, 0) NOT NULL ,Tu_Hora_Fin numeric(18, 0) NOT NULL ,Tu_Descripcion varchar(255) UNIQUE NOT NULL ,Tu_Valor_Ficha numeric(18, 2) NOT NULL ,Tu_Valor_Bandera numeric(18, 2) NOT NULL ,Tu_Habilitado bit CONSTRAINT [DF_Turnos_Tu_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Choferes ====*/ CREATE TABLE NUNCA_TAXI.Choferes( Id_Chofer numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ch_Nombre varchar(255) NOT NULL ,Ch_Apellido varchar(255) NOT NULL ,Ch_Dni numeric(18, 0) UNIQUE NOT NULL ,Ch_Direccion varchar(255) UNIQUE NOT NULL ,Ch_Telefono numeric(18, 0) UNIQUE NOT NULL ,Ch_Mail varchar(255) NULL ,Ch_Fecha_Nac datetime NOT NULL ,Ch_Habilitado bit CONSTRAINT [DF_Choferes_Ch_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.MarcasTaxi ====*/ CREATE TABLE NUNCA_TAXI.MarcasTaxi( Id_MarcaTaxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ma_NombreTaxi varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Taxis ====*/ CREATE TABLE NUNCA_TAXI.Taxis( Id_Taxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Reloj numeric(18, 0) References NUNCA_TAXI.Relojes(Id_Reloj) NULL ,Id_MarcaTaxi numeric(18, 0) References NUNCA_TAXI.MarcasTaxi(Id_MarcaTaxi) NOT NULL ,Ta_Patente varchar(255) UNIQUE NOT NULL ,Ta_Licencia varchar(255) UNIQUE NOT NULL ,Ta_Rodado varchar(250) NOT NULL ,Ta_Modelo varchar(255) NOT NULL ,Ta_Habilitado bit CONSTRAINT [DF_Taxis_Ta_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.TiposViaje ====*/ CREATE TABLE NUNCA_TAXI.TiposViaje( Id_TipoViaje numeric(18, 0) PRIMARY KEY IDENTITY(0,1) NOT NULL ,Ti_DescripcionTipoViaje varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Viajes ====*/ CREATE TABLE NUNCA_TAXI.Viajes( Id_Viaje numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Cliente numeric(18, 0) References NUNCA_TAXI.Clientes(Id_Cliente) NOT NULL ,Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Id_Taxi numeric(18, 0) References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL ,Id_TipoViaje numeric(18, 0) References NUNCA_TAXI.TiposViaje(Id_TipoViaje) NOT NULL ,Vi_Cant_Fichas numeric(18, 0) NOT NULL ,Vi_Fecha datetime NOT NULL ,Vi_Importe numeric(18, 2) NOT NULL ,Vi_FechaRendido datetime NULL ,Vi_FFactura_Ini datetime NULL ,Vi_FFactura_Fin datetime NULL) /*==== CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis ====*/ CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis( Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Id_Taxi numeric(18, 0) References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL ,Fecha datetime CONSTRAINT [DF_ChoferesTurnosTaxis_Cat_Fecha] DEFAULT ((getdate())) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Facturas ====*/ CREATE TABLE NUNCA_TAXI.Facturas( Id_Factura numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Cliente numeric(18, 0) References NUNCA_TAXI.Clientes(Id_Cliente) NOT NULL ,Fa_Feha_Inicio datetime NOT NULL ,Fa_Fecha_Fin datetime NOT NULL ,Fa_Importe numeric(18, 2) NOT NULL ,Fa_Estado bit CONSTRAINT [DF_Facturas_Fa_Estado] DEFAULT ((0)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Rendiciones ====*/ CREATE TABLE NUNCA_TAXI.Rendiciones( Id_Rendicion numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Ren_Fecha datetime NOT NULL ,Ren_Importe numeric(18, 2) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Usuarios ====*/ CREATE TABLE NUNCA_TAXI.Usuarios( Id_Usuario numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Us_Usuario varchar(255) UNIQUE NOT NULL ,Us_Password varchar(255) NOT NULL ,Us_Habilitado bit CONSTRAINT [DF_Usuarios_Us_Habilitado] DEFAULT ((1)) NOT NULL ,Us_Login_Failed numeric(18,0) CONSTRAINT [DF_Usuarios_Us_Login_Failed] DEFAULT ((0)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Roles ====*/ CREATE TABLE NUNCA_TAXI.Roles( Id_Rol numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ro_Descripcion varchar(255) UNIQUE NOT NULL ,Ro_Habilitado bit CONSTRAINT [DF_Roles_Ro_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.UsuariosRoles ====*/ CREATE TABLE NUNCA_TAXI.UsuariosRoles( Id_Usuario numeric(18, 0) References NUNCA_TAXI.Usuarios(Id_Usuario) NOT NULL ,Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Permisos ====*/ CREATE TABLE NUNCA_TAXI.Permisos( Id_Permiso numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Pe_Descripcion varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.PermisosRoles ====*/ CREATE TABLE NUNCA_TAXI.PermisosRoles( Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL ,Id_Permiso numeric(18, 0) References NUNCA_TAXI.Permisos(Id_Permiso) NOT NULL) END GO /*=============================================================================*/ /*= =*/ /*= MIGRAR Y COMPLETAR TABLAS =*/ /*= =*/ /*=============================================================================*/ CREATE PROCEDURE NUNCA_TAXI.CargarTablasNuncaTaxi AS BEGIN /*==== MIGRAR NUNCA_TAXI.MarcasReloj ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.MarcasReloj (Ma_NombreReloj) SELECT DISTINCT Reloj_Marca FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Relojes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Relojes (Id_MarcaReloj ,Re_Modelo ,Re_Fecha_Ver) SELECT DISTINCT (SELECT Id_MarcaReloj FROM NUNCA_TAXI.MarcasReloj WHERE Ma_NombreReloj=gd_esquema.Maestra.Reloj_Marca) ,Reloj_Modelo ,Reloj_Fecha_Ver FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Clientes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre,Cl_Apellido,Cl_Dni,Cl_Telefono,Cl_Direccion,Cl_Fecha_Nac) VALUES ('Desconocido','Desconocido',00000000,00000000 ,'Todas partes',getdate()) INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre ,Cl_Apellido ,Cl_Dni ,Cl_Telefono ,Cl_Direccion ,Cl_Mail ,Cl_Fecha_Nac ,Cl_Habilitado) SELECT DISTINCT Cliente_Nombre, Cliente_Apellido, Cliente_Dni, Cliente_Telefono, Cliente_Direccion, Cliente_Mail, Cliente_Fecha_Nac,1 FROM gd_esquema.Maestra WHERE (Auto_Marca IS NOT NULL) AND (Cliente_Nombre IS NOT NULL) /*==== MIGRAR NUNCA_TAXI.Turnos ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Turnos (Tu_Hora_Ini ,Tu_Hora_Fin ,Tu_Descripcion ,Tu_Valor_Ficha ,Tu_Valor_Bandera) SELECT DISTINCT Turno_Hora_Inicio, Turno_Hora_Fin, Turno_Descripcion, Turno_Valor_Ficha, Turno_Valor_Bandera FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Choferes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Choferes (Ch_Nombre ,Ch_Apellido ,Ch_Dni ,Ch_Direccion ,Ch_Telefono ,Ch_Mail ,Ch_Fecha_Nac) SELECT DISTINCT Chofer_Nombre, Chofer_Apellido, Chofer_Dni, Chofer_Direccion, Chofer_Telefono, Chofer_Mail, Chofer_Fecha_Nac FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.MarcasTaxi ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.MarcasTaxi (Ma_NombreTaxi) SELECT DISTINCT Auto_Marca FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Taxis ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Taxis (Id_Reloj,Id_MarcaTaxi,Ta_Patente,Ta_Licencia,Ta_Rodado,Ta_Modelo) SELECT DISTINCT (SELECT Id_Reloj FROM NUNCA_TAXI.Relojes WHERE Re_Modelo=gd_esquema.Maestra.Reloj_Modelo) ,(SELECT Id_MarcaTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE Ma_NombreTaxi=gd_esquema.Maestra.Auto_Marca) ,Auto_Patente ,Auto_Licencia ,Auto_Rodado ,Auto_Modelo FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.TiposViaje====*/ INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Calle') INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES ('Cliente') /*==== MIGRAR NUNCA_TAXI.Viajes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Viajes (Id_Cliente ,Id_Chofer ,Id_Turno ,Id_Taxi ,Vi_Cant_Fichas ,Vi_Fecha ,Id_TipoViaje ,Vi_Importe) SELECT DISTINCT (CASE WHEN M.cliente_dni IS NOT NULL THEN(SELECT Cl.id_cliente) WHEN M.cliente_dni IS NULL THEN(SELECT 1) END) ,Ch.id_chofer ,Tu.id_turno ,Ta.id_taxi ,M.Viaje_Cant_Fichas ,M.Viaje_Fecha ,(CASE WHEN M.cliente_dni IS NOT NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Cliente') WHEN M.cliente_dni IS NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Calle') END) ,(M.Viaje_Cant_Fichas*Tu.Tu_Valor_ficha)+Tu.Tu_Valor_Bandera FROM NUNCA_TAXI.Clientes Cl, NUNCA_TAXI.Choferes Ch, NUNCA_TAXI.Turnos Tu, NUNCA_TAXI.Taxis Ta,gd_esquema.Maestra M WHERE (Cl_Dni = Cliente_Dni or Cliente_Dni IS NULL) AND (Ch_Dni = Chofer_Dni) AND (Tu_Descripcion = Turno_Descripcion) AND (Ta_Patente = Auto_Patente) AND (M.Rendicion_Fecha IS NULL) AND (M.Factura_Fecha_Inicio IS NULL) AND (M.Factura_Fecha_Fin IS NULL) UPDATE GD1C2012.NUNCA_TAXI.Viajes SET Vi_FechaRendido=M.Rendicion_Fecha FROM gd_esquema.Maestra AS M INNER JOIN [NUNCA_TAXI].[Choferes] ON Choferes.Ch_Dni = M.Chofer_Dni INNER JOIN [NUNCA_TAXI].[Clientes] ON Clientes.Cl_Dni = isnull(M.Cliente_dni,00000000) INNER JOIN [NUNCA_TAXI].[Taxis] ON Taxis.Ta_Patente = M.Auto_Patente INNER JOIN [NUNCA_TAXI].[Turnos] ON Turnos.Tu_Descripcion = M.Turno_Descripcion INNER JOIN [NUNCA_TAXI].[Viajes] ON Viajes.Vi_Fecha = M.Viaje_Fecha WHERE (M.Rendicion_Fecha IS NOT NULL) AND (Clientes.id_Cliente = Viajes.Id_Cliente) AND (Choferes.Id_Chofer = Viajes.Id_Chofer) AND (Turnos.Id_Turno = Viajes.Id_Turno) AND (Taxis.Id_Taxi = Viajes.Id_Taxi) UPDATE GD1C2012.NUNCA_TAXI.Viajes SET Vi_FFactura_Ini = M.Factura_Fecha_Inicio, Vi_FFactura_Fin = M.Factura_Fecha_Fin FROM gd_esquema.Maestra AS M INNER JOIN [NUNCA_TAXI].[Choferes] ON Choferes.Ch_Dni = M.Chofer_Dni INNER JOIN [NUNCA_TAXI].[Clientes] ON Clientes.Cl_Dni = isnull(M.Cliente_dni,00000000) INNER JOIN [NUNCA_TAXI].[Taxis] ON Taxis.Ta_Patente = M.Auto_Patente INNER JOIN [NUNCA_TAXI].[Turnos] ON Turnos.Tu_Descripcion = M.Turno_Descripcion INNER JOIN [NUNCA_TAXI].[Viajes] ON Viajes.Vi_Fecha = M.Viaje_Fecha WHERE (M.factura_fecha_fin IS NOT NULL) AND (M.factura_fecha_inicio IS NOT NULL) AND (M.Cliente_Dni IS NOT NULL) AND (Clientes.id_Cliente = Viajes.Id_Cliente) AND (Choferes.Id_Chofer = Viajes.Id_Chofer) AND (Turnos.Id_Turno = Viajes.Id_Turno) AND (Taxis.Id_Taxi = Viajes.Id_Taxi) /*==== MIGRAR NUNCA_TAXI.ChoferesTurnosTaxis ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.ChoferesTurnosTaxis (Id_Chofer,Id_Turno,Id_Taxi) SELECT DISTINCT (SELECT id_chofer FROM NUNCA_TAXI.Choferes Where Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos Where Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Facturas ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Facturas (Id_Cliente,Fa_Feha_Inicio,Fa_Fecha_Fin,Fa_Importe) SELECT Id_Cliente,Vi_FFactura_Ini,Vi_FFactura_Fin,SUM(Vi_Importe) AS ImporteDeFactura FROM NUNCA_TAXI.Viajes WHERE (Vi_FFactura_Ini IS NOT NULL) AND (Vi_FFactura_Fin IS NOT NULL) GROUP BY Id_Cliente, Vi_FFactura_Ini, Vi_FFactura_Fin /*==== MIGRAR NUNCA_TAXI.Rendiciones ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Rendiciones (Id_Chofer,Id_Turno,Ren_Fecha,Ren_Importe) SELECT Id_Chofer, Id_Turno, Vi_FechaRendido, SUM(Vi_Importe) AS ImporteDeRendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NOT NULL) GROUP BY Id_Chofer, Id_Turno, Vi_FechaRendido /*==== MIGRAR NUNCA_TAXI.Usuarios ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Usuarios (Us_Usuario,Us_Password) VALUES ('admin','Utd0YrJJhxdcjX2rkBpZZ+kn/8jQtuSiNOB6SuxeNyQ=') /*==== MIGRAR NUNCA_TAXI.Permisos ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Rol') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Usuario') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Auto') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Reloj') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Chofer') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Turno') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Asignacion Chofer-Auto') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Registro de Viajes') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Rendicion de Cuenta del Chofer') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Facturacion del Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Listado Estadistico') /*==== MIGRAR NUNCA_TAXI.Roles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Roles (Ro_Descripcion) VALUES ('Administrador del Generaal') /*==== MIGRAR NUNCA_TAXI.UsuariosRoles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.UsuariosRoles (Id_Usuario,Id_Rol) VALUES (1,1) /*==== MIGRAR NUNCA_TAXI.PermisosRoles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,1) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,2) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,3) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,4) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,5) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,6) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,7) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,8) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,9) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,10) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,11) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,12) END GO /*=============================================================================*/ /*= =*/ /*= EJECUCION DE PROCEDIMIENTOS =*/ /*= =*/ /*=============================================================================*/ /*==== EXEC NUNCA_TAXI.CrearTablasNuncaTaxi ====*/ EXEC NUNCA_TAXI.CrearTablasNuncaTaxi GO /*==== EXEC NUNCA_TAXI.CargarTablasNuncaTaxi ====*/ EXEC NUNCA_TAXI.CargarTablasNuncaTaxi GO
09066bd9cc483c8928891679d8ad73b5
trunk/script_creacion_inicial.sql
TSQL
asf20
17,886
/*--- GRUPO: ---*//*--- INTEGRANTES: ---*/ /*--- NUNCA_TAXI ---*//*--- Dorati Hermida, Ivan ---*/ /*--- ---*//*--- Pereyra, Yohanna ---*/ /*--- CURSADA: ---*//*--- Torrente, Nicolas ---*/ /*--- 1er Cuatrimestre, 2012 ---*//*--- Schachner, Pablo ---*/ /*--- ---*//*--- ---*/ /*--- CURSO: ---*//*--- ---*/ /*--- K3151-K3051 ---*//*--- ---*/ /*=============================================================================*/ /*= =*/ /*= CREAR ESQUEMA =*/ /*= =*/ /*=============================================================================*/ CREATE SCHEMA NUNCA_TAXI GO /*=============================================================================*/ /*= =*/ /*= CREAR TABLAS =*/ /*= =*/ /*=============================================================================*/ CREATE PROCEDURE NUNCA_TAXI.CrearTablasNuncaTaxi AS BEGIN /*==== CREATE TABLE NUNCA_TAXI.MarcasReloj ====*/ CREATE TABLE NUNCA_TAXI.MarcasReloj( Id_MarcaReloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ma_NombreReloj varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Relojes ====*/ CREATE TABLE NUNCA_TAXI.Relojes( Id_Reloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_MarcaReloj numeric (18, 0) References NUNCA_TAXI.MarcasReloj(Id_MarcaReloj) NOT NULL ,Re_Modelo varchar(255) UNIQUE NOT NULL ,Re_Habilitado bit CONSTRAINT [DF_Relojes_R_Habilitado] DEFAULT ((1)) NOT NULL ,Re_Fecha_Ver datetime NOT NULL ,Re_NoSerie varchar(18) NULL) /*==== CREATE TABLE NUNCA_TAXI.Clientes ====*/ CREATE TABLE NUNCA_TAXI.Clientes( Id_Cliente numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Cl_Nombre varchar(255) NOT NULL ,Cl_Apellido varchar(255) NOT NULL ,Cl_Dni numeric(18, 0) UNIQUE NOT NULL ,Cl_Telefono numeric(18, 0) UNIQUE NOT NULL ,Cl_Direccion varchar(255) UNIQUE NOT NULL ,Cl_Mail varchar(255) NULL ,Cl_Fecha_Nac datetime NOT NULL ,Cl_Habilitado bit CONSTRAINT [DF_Clientes_Cl_Habilitacion] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Turnos ====*/ CREATE TABLE NUNCA_TAXI.Turnos( Id_Turno numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Tu_Hora_Ini numeric(18, 0) NOT NULL ,Tu_Hora_Fin numeric(18, 0) NOT NULL ,Tu_Descripcion varchar(255) UNIQUE NOT NULL ,Tu_Valor_Ficha numeric(18, 2) NOT NULL ,Tu_Valor_Bandera numeric(18, 2) NOT NULL ,Tu_Habilitado bit CONSTRAINT [DF_Turnos_Tu_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Choferes ====*/ CREATE TABLE NUNCA_TAXI.Choferes( Id_Chofer numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ch_Nombre varchar(255) NOT NULL ,Ch_Apellido varchar(255) NOT NULL ,Ch_Dni numeric(18, 0) UNIQUE NOT NULL ,Ch_Direccion varchar(255) UNIQUE NOT NULL ,Ch_Telefono numeric(18, 0) UNIQUE NOT NULL ,Ch_Mail varchar(255) NULL ,Ch_Fecha_Nac datetime NOT NULL ,Ch_Habilitado bit CONSTRAINT [DF_Choferes_Ch_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.MarcasTaxi ====*/ CREATE TABLE NUNCA_TAXI.MarcasTaxi( Id_MarcaTaxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ma_NombreTaxi varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Taxis ====*/ CREATE TABLE NUNCA_TAXI.Taxis( Id_Taxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Reloj numeric(18, 0) References NUNCA_TAXI.Relojes(Id_Reloj) NULL ,Id_MarcaTaxi numeric(18, 0) References NUNCA_TAXI.MarcasTaxi(Id_MarcaTaxi) NOT NULL ,Ta_Patente varchar(255) UNIQUE NOT NULL ,Ta_Licencia varchar(255) UNIQUE NOT NULL ,Ta_Rodado varchar(250) NOT NULL ,Ta_Modelo varchar(255) NOT NULL ,Ta_Habilitado bit CONSTRAINT [DF_Taxis_Ta_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.TiposViaje ====*/ CREATE TABLE NUNCA_TAXI.TiposViaje( Id_TipoViaje numeric(18, 0) PRIMARY KEY IDENTITY(0,1) NOT NULL ,Ti_DescripcionTipoViaje varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Viajes ====*/ CREATE TABLE NUNCA_TAXI.Viajes( Id_Viaje numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Cliente numeric(18, 0) References NUNCA_TAXI.Clientes(Id_Cliente) NOT NULL ,Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Id_Taxi numeric(18, 0) References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL ,Id_TipoViaje numeric(18, 0) References NUNCA_TAXI.TiposViaje(Id_TipoViaje) NOT NULL ,Vi_Cant_Fichas numeric(18, 0) NOT NULL ,Vi_Fecha datetime NOT NULL ,Vi_Importe numeric(18, 2) NOT NULL ,Vi_FechaRendido datetime NULL ,Vi_FFactura_Ini datetime NULL ,Vi_FFactura_Fin datetime NULL) /*==== CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis ====*/ CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis( Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Id_Taxi numeric(18, 0) References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL ,Fecha datetime CONSTRAINT [DF_ChoferesTurnosTaxis_Cat_Fecha] DEFAULT ((getdate())) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Facturas ====*/ CREATE TABLE NUNCA_TAXI.Facturas( Id_Factura numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Cliente numeric(18, 0) References NUNCA_TAXI.Clientes(Id_Cliente) NOT NULL ,Fa_Feha_Inicio datetime NOT NULL ,Fa_Fecha_Fin datetime NOT NULL ,Fa_Importe numeric(18, 2) NOT NULL ,Fa_Estado bit CONSTRAINT [DF_Facturas_Fa_Estado] DEFAULT ((0)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Rendiciones ====*/ CREATE TABLE NUNCA_TAXI.Rendiciones( Id_Rendicion numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Id_Chofer numeric(18, 0) References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL ,Id_Turno numeric(18, 0) References NUNCA_TAXI.Turnos(Id_Turno) NOT NULL ,Ren_Fecha datetime NOT NULL ,Ren_Importe numeric(18, 2) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Usuarios ====*/ CREATE TABLE NUNCA_TAXI.Usuarios( Id_Usuario numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Us_Usuario varchar(255) UNIQUE NOT NULL ,Us_Password varchar(255) NOT NULL ,Us_Habilitado bit CONSTRAINT [DF_Usuarios_Us_Habilitado] DEFAULT ((1)) NOT NULL ,Us_Login_Failed numeric(18,0) CONSTRAINT [DF_Usuarios_Us_Login_Failed] DEFAULT ((0)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Roles ====*/ CREATE TABLE NUNCA_TAXI.Roles( Id_Rol numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Ro_Descripcion varchar(255) UNIQUE NOT NULL ,Ro_Habilitado bit CONSTRAINT [DF_Roles_Ro_Habilitado] DEFAULT ((1)) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.UsuariosRoles ====*/ CREATE TABLE NUNCA_TAXI.UsuariosRoles( Id_Usuario numeric(18, 0) References NUNCA_TAXI.Usuarios(Id_Usuario) NOT NULL ,Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.Permisos ====*/ CREATE TABLE NUNCA_TAXI.Permisos( Id_Permiso numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL ,Pe_Descripcion varchar(255) UNIQUE NOT NULL) /*==== CREATE TABLE NUNCA_TAXI.PermisosRoles ====*/ CREATE TABLE NUNCA_TAXI.PermisosRoles( Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL ,Id_Permiso numeric(18, 0) References NUNCA_TAXI.Permisos(Id_Permiso) NOT NULL) END GO /*=============================================================================*/ /*= =*/ /*= MIGRAR Y COMPLETAR TABLAS =*/ /*= =*/ /*=============================================================================*/ CREATE PROCEDURE NUNCA_TAXI.CargarTablasNuncaTaxi AS BEGIN /*==== MIGRAR NUNCA_TAXI.MarcasReloj ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.MarcasReloj (Ma_NombreReloj) SELECT DISTINCT Reloj_Marca FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Relojes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Relojes (Id_MarcaReloj ,Re_Modelo ,Re_Fecha_Ver) SELECT DISTINCT (SELECT Id_MarcaReloj FROM NUNCA_TAXI.MarcasReloj WHERE Ma_NombreReloj=gd_esquema.Maestra.Reloj_Marca) ,Reloj_Modelo ,Reloj_Fecha_Ver FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Clientes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre,Cl_Apellido,Cl_Dni,Cl_Telefono,Cl_Direccion,Cl_Fecha_Nac) VALUES ('Desconocido','Desconocido',00000000,00000000 ,'Todas partes',getdate()) INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre ,Cl_Apellido ,Cl_Dni ,Cl_Telefono ,Cl_Direccion ,Cl_Mail ,Cl_Fecha_Nac ,Cl_Habilitado) SELECT DISTINCT Cliente_Nombre, Cliente_Apellido, Cliente_Dni, Cliente_Telefono, Cliente_Direccion, Cliente_Mail, Cliente_Fecha_Nac,1 FROM gd_esquema.Maestra WHERE (Auto_Marca IS NOT NULL) AND (Cliente_Nombre IS NOT NULL) /*==== MIGRAR NUNCA_TAXI.Turnos ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Turnos (Tu_Hora_Ini ,Tu_Hora_Fin ,Tu_Descripcion ,Tu_Valor_Ficha ,Tu_Valor_Bandera) SELECT DISTINCT Turno_Hora_Inicio, Turno_Hora_Fin, Turno_Descripcion, Turno_Valor_Ficha, Turno_Valor_Bandera FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Choferes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Choferes (Ch_Nombre ,Ch_Apellido ,Ch_Dni ,Ch_Direccion ,Ch_Telefono ,Ch_Mail ,Ch_Fecha_Nac) SELECT DISTINCT Chofer_Nombre, Chofer_Apellido, Chofer_Dni, Chofer_Direccion, Chofer_Telefono, Chofer_Mail, Chofer_Fecha_Nac FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.MarcasTaxi ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.MarcasTaxi (Ma_NombreTaxi) SELECT DISTINCT Auto_Marca FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Taxis ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Taxis (Id_Reloj,Id_MarcaTaxi,Ta_Patente,Ta_Licencia,Ta_Rodado,Ta_Modelo) SELECT DISTINCT (SELECT Id_Reloj FROM NUNCA_TAXI.Relojes WHERE Re_Modelo=gd_esquema.Maestra.Reloj_Modelo) ,(SELECT Id_MarcaTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE Ma_NombreTaxi=gd_esquema.Maestra.Auto_Marca) ,Auto_Patente ,Auto_Licencia ,Auto_Rodado ,Auto_Modelo FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.TiposViaje====*/ INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Calle') INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES ('Cliente') /*==== MIGRAR NUNCA_TAXI.Viajes ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Viajes (Id_Cliente ,Id_Chofer ,Id_Turno ,Id_Taxi ,Vi_Cant_Fichas ,Vi_Fecha ,Id_TipoViaje ,Vi_Importe) SELECT DISTINCT (CASE WHEN M.cliente_dni IS NOT NULL THEN(SELECT Cl.id_cliente) WHEN M.cliente_dni IS NULL THEN(SELECT 1) END) ,Ch.id_chofer ,Tu.id_turno ,Ta.id_taxi ,M.Viaje_Cant_Fichas ,M.Viaje_Fecha ,(CASE WHEN M.cliente_dni IS NOT NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Cliente') WHEN M.cliente_dni IS NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Calle') END) ,(M.Viaje_Cant_Fichas*Tu.Tu_Valor_ficha)+Tu.Tu_Valor_Bandera FROM NUNCA_TAXI.Clientes Cl, NUNCA_TAXI.Choferes Ch, NUNCA_TAXI.Turnos Tu, NUNCA_TAXI.Taxis Ta,gd_esquema.Maestra M WHERE (Cl_Dni = Cliente_Dni or Cliente_Dni IS NULL) AND (Ch_Dni = Chofer_Dni) AND (Tu_Descripcion = Turno_Descripcion) AND (Ta_Patente = Auto_Patente) AND (M.Rendicion_Fecha IS NULL) AND (M.Factura_Fecha_Inicio IS NULL) AND (M.Factura_Fecha_Fin IS NULL) UPDATE GD1C2012.NUNCA_TAXI.Viajes SET Vi_FechaRendido=M.Rendicion_Fecha FROM gd_esquema.Maestra AS M INNER JOIN [NUNCA_TAXI].[Choferes] ON Choferes.Ch_Dni = M.Chofer_Dni INNER JOIN [NUNCA_TAXI].[Clientes] ON Clientes.Cl_Dni = isnull(M.Cliente_dni,00000000) INNER JOIN [NUNCA_TAXI].[Taxis] ON Taxis.Ta_Patente = M.Auto_Patente INNER JOIN [NUNCA_TAXI].[Turnos] ON Turnos.Tu_Descripcion = M.Turno_Descripcion INNER JOIN [NUNCA_TAXI].[Viajes] ON Viajes.Vi_Fecha = M.Viaje_Fecha WHERE (M.Rendicion_Fecha IS NOT NULL) AND (Clientes.id_Cliente = Viajes.Id_Cliente) AND (Choferes.Id_Chofer = Viajes.Id_Chofer) AND (Turnos.Id_Turno = Viajes.Id_Turno) AND (Taxis.Id_Taxi = Viajes.Id_Taxi) UPDATE GD1C2012.NUNCA_TAXI.Viajes SET Vi_FFactura_Ini = M.Factura_Fecha_Inicio, Vi_FFactura_Fin = M.Factura_Fecha_Fin FROM gd_esquema.Maestra AS M INNER JOIN [NUNCA_TAXI].[Choferes] ON Choferes.Ch_Dni = M.Chofer_Dni INNER JOIN [NUNCA_TAXI].[Clientes] ON Clientes.Cl_Dni = isnull(M.Cliente_dni,00000000) INNER JOIN [NUNCA_TAXI].[Taxis] ON Taxis.Ta_Patente = M.Auto_Patente INNER JOIN [NUNCA_TAXI].[Turnos] ON Turnos.Tu_Descripcion = M.Turno_Descripcion INNER JOIN [NUNCA_TAXI].[Viajes] ON Viajes.Vi_Fecha = M.Viaje_Fecha WHERE (M.factura_fecha_fin IS NOT NULL) AND (M.factura_fecha_inicio IS NOT NULL) AND (M.Cliente_Dni IS NOT NULL) AND (Clientes.id_Cliente = Viajes.Id_Cliente) AND (Choferes.Id_Chofer = Viajes.Id_Chofer) AND (Turnos.Id_Turno = Viajes.Id_Turno) AND (Taxis.Id_Taxi = Viajes.Id_Taxi) /*==== MIGRAR NUNCA_TAXI.ChoferesTurnosTaxis ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.ChoferesTurnosTaxis (Id_Chofer,Id_Turno,Id_Taxi) SELECT DISTINCT (SELECT id_chofer FROM NUNCA_TAXI.Choferes Where Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos Where Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) FROM gd_esquema.Maestra /*==== MIGRAR NUNCA_TAXI.Facturas ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Facturas (Id_Cliente,Fa_Feha_Inicio,Fa_Fecha_Fin,Fa_Importe) SELECT Id_Cliente,Vi_FFactura_Ini,Vi_FFactura_Fin,SUM(Vi_Importe) AS ImporteDeFactura FROM NUNCA_TAXI.Viajes WHERE (Vi_FFactura_Ini IS NOT NULL) AND (Vi_FFactura_Fin IS NOT NULL) GROUP BY Id_Cliente, Vi_FFactura_Ini, Vi_FFactura_Fin /*==== MIGRAR NUNCA_TAXI.Rendiciones ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Rendiciones (Id_Chofer,Id_Turno,Ren_Fecha,Ren_Importe) SELECT Id_Chofer, Id_Turno, Vi_FechaRendido, SUM(Vi_Importe) AS ImporteDeRendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NOT NULL) GROUP BY Id_Chofer, Id_Turno, Vi_FechaRendido /*==== MIGRAR NUNCA_TAXI.Usuarios ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Usuarios (Us_Usuario,Us_Password) VALUES ('admin','Utd0YrJJhxdcjX2rkBpZZ+kn/8jQtuSiNOB6SuxeNyQ=') /*==== MIGRAR NUNCA_TAXI.Permisos ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Rol') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Usuario') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Auto') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Reloj') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Chofer') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Turno') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Asignacion Chofer-Auto') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Registro de Viajes') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Rendicion de Cuenta del Chofer') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Facturacion del Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('Listado Estadistico') /*==== MIGRAR NUNCA_TAXI.Roles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.Roles (Ro_Descripcion) VALUES ('Administrador General') /*==== MIGRAR NUNCA_TAXI.UsuariosRoles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.UsuariosRoles (Id_Usuario,Id_Rol) VALUES (1,1) /*==== MIGRAR NUNCA_TAXI.PermisosRoles ====*/ INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,1) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,2) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,3) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,4) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,5) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,6) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,7) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,8) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,9) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,10) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,11) INSERT INTO GD1C2012.NUNCA_TAXI.PermisosRoles (Id_Rol,Id_Permiso) VALUES (1,12) END GO /*=============================================================================*/ /*= =*/ /*= EJECUCION DE PROCEDIMIENTOS =*/ /*= =*/ /*=============================================================================*/ /*==== EXEC NUNCA_TAXI.CrearTablasNuncaTaxi ====*/ EXEC NUNCA_TAXI.CrearTablasNuncaTaxi GO /*==== EXEC NUNCA_TAXI.CargarTablasNuncaTaxi ====*/ EXEC NUNCA_TAXI.CargarTablasNuncaTaxi GO
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/data/script_creacion_inicial.sql
TSQL
asf20
17,881
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmCliente { public partial class AbmCliente : Form { private int selected_elem = -1; public AbmCliente(Modelo.FormActions.Actions action, string id) { InitializeComponent(); pk.Visible = false; lbl_estado.Text = "ALTA"; tb_grande.Visible = false; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { selected_elem = Convert.ToInt32(id); lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE (Id_Cliente != 1 ) AND (Id_Cliente = " + id + ")", con); DataTable dt = new DataTable(); da.Fill(dt); pk.Name = id; tb_nombre.Text = dt.Rows[0]["Cl_Nombre"].ToString(); tb_apellido.Text = dt.Rows[0]["Cl_Apellido"].ToString(); tb_dni.Text = dt.Rows[0]["Cl_Dni"].ToString(); tb_grande.Text = dt.Rows[0]["Cl_Direccion"].ToString(); tb_tel.Text = dt.Rows[0]["Cl_Telefono"].ToString(); tb_mail.Text = dt.Rows[0]["Cl_Mail"].ToString(); dt_nacimiento.Value = DateTime.Parse(dt.Rows[0]["Cl_Fecha_Nac"].ToString()); label7.Visible = label8.Visible = label9.Visible = label11.Visible = false; tb_dpto.Visible = tb_localidad.Visible = tb_nropiso.Visible = tb_cp.Visible = false; tb_grande.Visible = true; if (Convert.ToBoolean(dt.Rows[0]["Cl_Habilitado"].ToString()) == false) { cb_habi.Checked = false; } else { cb_habi.Checked = true; } if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; Propiedades.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmCliente_Load(object sender, EventArgs e) { } private void aceptar_Click_1(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (lbl_estado.Text == "ALTA") { bool valido = true; string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_nombre.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_apellido.Text)) { error_txt = String.Concat(error_txt, "\n Apellido de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_dni.Text)) { error_txt = String.Concat(error_txt, "\n DNI de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_tel.Text)) { error_txt = String.Concat(error_txt, "\n Telefono de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_dir.Text)) { error_txt = String.Concat(error_txt, "\n Direccion de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_cp.Text)) { error_txt = String.Concat(error_txt, "\n Codigo Postal de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(dt_nacimiento.Text)) { error_txt = String.Concat(error_txt, "\n Fecha de Nacimiento de cliente es obligatorio"); valido = false; } if (valido) { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Clientes(Cl_Nombre,Cl_Apellido,Cl_Dni,Cl_Direccion,Cl_Telefono,Cl_Mail,Cl_Fecha_Nac,Cl_Habilitado) VALUES(@nom,@ape,@dni,@dire,@tel,@mail,@fech,@habi)", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", tb_dni.Text); comando.Parameters.AddWithValue("dire", tb_dir.Text + " - " + tb_nropiso.Text + " " + tb_dpto.Text + " - " + "(" + tb_localidad.Text + ") (" + tb_cp.Text + ")"); comando.Parameters.AddWithValue("tel", tb_tel.Text); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getClienteByTel(tb_tel.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Cliente duplicado. Ya existe otro con igual telefono"); } else { if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_nombre.Text = ""; tb_apellido.Text = ""; tb_dni.Text = ""; tb_dir.Text = ""; tb_tel.Text = ""; tb_mail.Text = ""; tb_dpto.Text = ""; tb_nropiso.Text = ""; tb_localidad.Text = ""; tb_cp.Text = ""; cb_habi.Checked = false; dt_nacimiento.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); MessageBox.Show("Cliente agregado exitosamente"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } } if (lbl_estado.Text == "MODIFICACION") { bool valido = true; string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_nombre.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_apellido.Text)) { error_txt = String.Concat(error_txt, "\n Apellido de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_dni.Text)) { error_txt = String.Concat(error_txt, "\n DNI de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_tel.Text)) { error_txt = String.Concat(error_txt, "\n Telefono de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_grande.Text)) { error_txt = String.Concat(error_txt, "\n Direccion de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(dt_nacimiento.Text)) { error_txt = String.Concat(error_txt, "\n Fecha de Nacimiento de cliente es obligatorio"); valido = false; } if (valido) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Clientes SET Cl_Nombre=@nom,Cl_Apellido=@ape,Cl_Dni=@dni,Cl_Direccion=@dire,Cl_Telefono=@tel,Cl_Mail=@mail,Cl_Fecha_Nac=@fech,Cl_Habilitado=@habi WHERE Id_Cliente = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", Convert.ToDecimal(tb_dni.Text)); comando.Parameters.AddWithValue("dire", tb_grande.Text); comando.Parameters.AddWithValue("tel", Convert.ToDecimal(tb_tel.Text)); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getClienteByTel(tb_tel.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); bool found = false; while (reader.Read()) { if (!reader[0].ToString().Equals(selected_elem.ToString())) { found = true; break; } } if (found) { MessageBox.Show("Cliente duplicado. Ya existe otro con igual telefono"); } else { if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Clientes SET Cl_Habilitado=@habi WHERE Id_Cliente = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmCliente/AbmCliente.cs
C#
asf20
15,660
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmCliente { public partial class Listado_Clientes : Form { private Modelo.FormActions.Actions action; public Listado_Clientes(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente != 1", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Clientes_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmCliente(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente != 1", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string consulta = ""; if (tb_apellido.Text == "" && tb_nombre.Text == "" && tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente != 1"; } else if (tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Clientes WHERE (Id_Cliente != 1) AND (Cl_Nombre LIKE '%" + tb_nombre.Text + "%' AND Cl_Apellido LIKE '%" + tb_apellido.Text + "%')"; } else { consulta = "SELECT * FROM NUNCA_TAXI.Clientes WHERE (Id_Cliente != 1) AND (Cl_Nombre LIKE '%" + tb_nombre.Text + "%' AND Cl_Apellido LIKE '%" + tb_apellido.Text + "%' AND Cl_Dni = '" + tb_dni.Text + "')"; } SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmCliente/Listado_Clientes.cs
C#
asf20
4,654
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Security.Cryptography; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Login { public partial class Login : Form { #region Properties private Boolean isValidated = false; public static MainForm mainForm; public static List<int> permisosList = new List<int>(); #endregion #region Public public Login() { InitializeComponent(); } #endregion #region Events private void login_button_Click(Object sender, EventArgs e) { //TODO: agregar validacion de user&pass isValidated = validateUser(user.Text, passwd.Text); if (isValidated) { mainForm = new MainForm(this); mainForm.Show(); } else { MessageBox.Show("La combinación de usuario/contraseña es erronea, o usuario no habilitado", "Error de Login"); foreach (Control ctrl in this.Controls) { if (ctrl is TextBox) { ((TextBox)ctrl).Clear(); } } } } #endregion private Boolean validateUser(String user, String passwd) { bool return_value = false; if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(passwd)) { return return_value; } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { //Validate user Modelo.Modelo.openConnection(con); SqlCommand validate_user = new SqlCommand(Modelo.SqlQueries.getUserInfo(user), con); SqlDataReader reader = validate_user.ExecuteReader(); //If users exists if (reader.FieldCount > 0) { reader.Read(); string password = reader.GetString(1); int login_failed = Convert.ToInt32(reader.GetDecimal(2)); bool habilitado = reader.GetBoolean(3); //Validated passwd and enabled if (password.Equals(getSHA256(passwd)) && habilitado) { SqlConnection con2 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con2); SqlCommand reset_fails = new SqlCommand(Modelo.SqlQueries.resetLoginFails(user), con2); reset_fails.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con2); getPermissions(user); return_value = true; } //User exists, but wrong passwd or not enabled else { if (login_failed < 3) { SqlConnection con4 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con4); SqlCommand inc_login_fail = new SqlCommand(Modelo.SqlQueries.incUserLoginFailed(user, login_failed + 1), con4); inc_login_fail.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con4); //This is the third failed time. Disable user if (login_failed == 2) { SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand disable_user = new SqlCommand(Modelo.SqlQueries.disableUser(user), con3); disable_user.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } return return_value; } public static string getSHA256(string input) { string hashed = null; byte[] inputBytes = Encoding.Unicode.GetBytes(input); SHA256Managed hash = new SHA256Managed(); byte[] hashBytes = hash.ComputeHash(inputBytes); hashed = Convert.ToBase64String(hashBytes); return hashed; } private void Login_Load(object sender, EventArgs e) { } private void getPermissions(string username) { using (SqlConnection con2 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_user_id = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(username), con2); SqlDataReader reader = comando_get_user_id.ExecuteReader(); List<int> roles = new List<int>(); while (reader.Read()) { int user_id = Convert.ToInt32(reader.GetDecimal(0)); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter us_rol_da = new SqlDataAdapter(Modelo.SqlQueries.getUserRoles(user_id), con); DataTable us_rol_dt = new DataTable(); us_rol_da.Fill(us_rol_dt); foreach (DataRow rol in us_rol_dt.Rows) { bool added = Convert.ToBoolean(rol.ItemArray[2]); if (added) { int rol_id = Convert.ToInt32(rol.ItemArray[0].ToString()); using (SqlConnection con3 = Modelo.Modelo.createConnection()) { SqlDataAdapter rol_perm_da = new SqlDataAdapter(Modelo.SqlQueries.getRolePermissions(rol_id), con3); DataTable rol_perm_dt = new DataTable(); rol_perm_da.Fill(rol_perm_dt); foreach (DataRow perm in rol_perm_dt.Rows) { foreach (KeyValuePair<string, int> pair in Modelo.Permissions.PermissionsDict) { if (pair.Value == Convert.ToInt32(perm.ItemArray[0].ToString())) { permisosList.Add(pair.Value); break; } } } } } } } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Login/Login.cs
C#
asf20
7,831
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmUsuario { public partial class Listado_Usuario : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Usuario(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledUsers, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getUsers, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmUsuario(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUsersFiltered(busqueda_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUsers, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmUsuario/Listado_Usuario.cs
C#
asf20
2,663
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmUsuario { public partial class AbmUsuario : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmUsuario(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; tb_usuario.Enabled = false; tb_passwd.Enabled = false; cb_hab.Enabled = false; dataGridView1.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; tb_usuario.Enabled = false; cb_hab.Enabled = true; aceptar.Text = "Modificar"; break; } } public AbmUsuario(Modelo.FormActions.Actions runAction) { InitializeComponent(); cb_hab.Enabled = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRoles, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void loadData(int id) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUserById(selected_elem), con); DataTable dt = new DataTable(); da.Fill(dt); DataRow user_info = dt.Rows[0]; tb_usuario.Text = user_info.ItemArray[1].ToString(); cb_hab.Checked = (bool) user_info.ItemArray[2]; SqlDataAdapter us_rol_da = new SqlDataAdapter(Modelo.SqlQueries.getUserRoles(selected_elem), con); DataTable us_rol_dt = new DataTable(); us_rol_da.Fill(us_rol_dt); dataGridView1.DataSource = us_rol_dt; } } private void aceptar_Click(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_usuario.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de usuario es obligatorio"); } if (String.IsNullOrEmpty(tb_passwd.Text)) { error_txt = String.Concat(error_txt, "\n Password es obligatorio"); } if(!String.IsNullOrEmpty(tb_usuario.Text) && (!String.IsNullOrEmpty(tb_passwd.Text))){ using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(tb_usuario.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Usuario duplicado"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addUser(tb_usuario.Text, Login.Login.getSHA256(tb_passwd.Text)), con); comando_add_user.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_user_id = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(tb_usuario.Text), con2); SqlDataReader reader = comando_get_user_id.ExecuteReader(); List<int> roles = new List<int>(); while (reader.Read()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["Added"].Value != null && Convert.ToInt32(row.Cells["Added"].Value) == 1) { roles.Add(Convert.ToInt32(row.Cells["Id"].Value)); } } if (roles.Count > 0) { SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand comando_add_user_role = new SqlCommand(Modelo.SqlQueries.addUserRoles(Convert.ToInt32(reader.GetDecimal(0)), roles), con3); comando_add_user_role.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } } MessageBox.Show(String.Format("Usuario {0} agregado", tb_usuario.Text)); Login.Login.mainForm.openForm(new AbmUsuario(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteUser(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Usuario {0} eliminado", tb_usuario.Text)); Login.Login.mainForm.openForm(new AbmUsuario(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: if (String.IsNullOrEmpty(tb_usuario.Text)) { MessageBox.Show("Nombre de usuario es obligatorio"); } else { List<int> roles_list = new List<int>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["Added"].Value != null && Convert.ToInt32(row.Cells["Added"].Value) == 1) { roles_list.Add(Convert.ToInt32(row.Cells["Id"].Value)); } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateUser(selected_elem, Login.Login.getSHA256(tb_passwd.Text), roles_list, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Usuario {0} modificado", tb_usuario.Text)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmUsuario/AbmUsuario.cs
C#
asf20
10,215
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.RegistrarViaje { public partial class RegistrarViajes : Form { public RegistrarViajes() { InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlConnection con1 = Modelo.Modelo.createConnection(); SqlDataAdapter da1 = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.TiposViaje", con1); DataSet ds1 = new DataSet(); da1.Fill(ds1); cb_tipo_viaje.DataSource = ds1.Tables[0].DefaultView; cb_tipo_viaje.DisplayMember = "Ti_DescripcionTipoViaje"; cb_tipo_viaje.ValueMember = "Id_TipoViaje"; cb_tipo_viaje.SelectedIndex = -1; Modelo.Modelo.closeConnection(con1); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); cb_turno.DataSource = ds2.Tables[0].DefaultView; cb_turno.DisplayMember = "Tu_Descripcion"; cb_turno.ValueMember = "Id_Turno"; cb_turno.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); SqlConnection con3 = Modelo.Modelo.createConnection(); SqlDataAdapter da3 = new SqlDataAdapter("SELECT Id_Chofer, (Ch_Nombre + ', ' +Ch_Apellido) as Ch_Nombre FROM NUNCA_TAXI.Choferes WHERE Ch_Habilitado = 1", con3); DataSet ds3 = new DataSet(); da3.Fill(ds3); cb_chofer.DataSource = ds3.Tables[0].DefaultView; cb_chofer.DisplayMember = "Ch_Nombre"; cb_chofer.ValueMember = "Id_Chofer"; cb_chofer.SelectedIndex = -1; Modelo.Modelo.closeConnection(con3); SqlConnection con4 = Modelo.Modelo.createConnection(); SqlDataAdapter da4 = new SqlDataAdapter("SELECT Id_Cliente, (Cl_Nombre + ', ' +Cl_Apellido) as Cl_Nombre FROM NUNCA_TAXI.Clientes WHERE Cl_Habilitado = 1", con4); DataSet ds4 = new DataSet(); da4.Fill(ds4); cb_cliente.DataSource = ds4.Tables[0].DefaultView; cb_cliente.DisplayMember = "Cl_Nombre"; cb_cliente.ValueMember = "Id_Cliente"; cb_cliente.SelectedIndex = -1; Modelo.Modelo.closeConnection(con4); } } private void aceptar_Click(object sender, EventArgs e) { if (cb_chofer.SelectedIndex.ToString() != "" && cb_cliente.SelectedIndex.ToString() != "" && cb_tipo_viaje.SelectedIndex.ToString() != "" && cb_turno.SelectedIndex.ToString() != "" && tb_fichas.Text != "" && cb_chofer.SelectedValue != "" && cb_cliente.SelectedValue != "" && cb_tipo_viaje.SelectedValue != "" && cb_turno.SelectedValue != "") { bool found = false; using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getIsRelojEnabled(Convert.ToDateTime(dt_fecha.Text), Convert.ToInt32(cb_chofer.SelectedValue), Convert.ToInt32(cb_turno.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); while (reader.Read()) { if (!reader[0].ToString().Equals("1")) { found = true; break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (!found) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion = '" + cb_turno.Text + "'", con); DataTable dt = new DataTable(); da.Fill(dt); decimal valor_ficha = Convert.ToDecimal(dt.Rows[0]["Tu_Valor_Ficha"].ToString()); decimal valor_bandera = Convert.ToDecimal(dt.Rows[0]["Tu_Valor_Bandera"].ToString()); decimal importe = (Convert.ToDecimal(tb_fichas.Text) * valor_ficha) + valor_bandera; da = new SqlDataAdapter("SELECT Id_Taxi FROM NUNCA_TAXI.ChoferesTurnosTaxis WHERE Id_Chofer = " + cb_chofer.SelectedValue + " AND Id_Turno = " + cb_turno.SelectedValue, con); dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("El Taxi no esta registrado en el turno, para el chofer seleccionado"); } else { string id_taxi = dt.Rows[0]["Id_Taxi"].ToString(); SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Viajes(Id_Cliente,Id_Chofer,Id_Turno,Id_Taxi,Id_TipoViaje,Vi_Cant_Fichas,Vi_Fecha,Vi_Importe) VALUES(@cliente,@chofer,@turno,@taxi,@tipo_viaje,@cant_fichas,@fecha,@importe)", con); comando.Parameters.AddWithValue("cliente", cb_cliente.SelectedValue); comando.Parameters.AddWithValue("chofer", cb_chofer.SelectedValue); comando.Parameters.AddWithValue("turno", cb_turno.SelectedValue); comando.Parameters.AddWithValue("taxi", id_taxi); comando.Parameters.AddWithValue("tipo_viaje", cb_tipo_viaje.SelectedValue); comando.Parameters.AddWithValue("cant_fichas", tb_fichas.Text); comando.Parameters.AddWithValue("fecha", dt_fecha.Value); comando.Parameters.AddWithValue("importe", importe); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); Login.Login.mainForm.openForm(new RegistrarViaje.RegistrarViajes()); } } } } else { MessageBox.Show("Reloj no esta habilitado"); } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/RegistrarViaje/RegistrarViajes.cs
C#
asf20
7,818
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmAuto { public partial class AbmAuto : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmAuto(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); marca_cb.DataSource = ds.Tables[0].DefaultView; marca_cb.DisplayMember = "Marca"; marca_cb.ValueMember = "Id"; marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; marca_cb.Enabled = false; reloj_cb.Enabled = false; tb_licencia.Enabled = false; tb_modelo.Enabled = false; tb_patente.Enabled = false; tb_rodado.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar.Text = "Modificar"; break; } } public AbmAuto(Modelo.FormActions.Actions runAction) { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); marca_cb.DataSource = ds.Tables[0].DefaultView; marca_cb.DisplayMember = "Marca"; marca_cb.ValueMember = "Id"; marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_get_autos = new SqlCommand(Modelo.SqlQueries.getAutoById(selected_elem), con3); SqlDataReader reader = comando_get_autos.ExecuteReader(); while (reader.Read()) { marca_cb.SelectedValue= Convert.ToInt32(reader["Marca"]); reloj_cb.SelectedValue = Convert.ToInt32(reader["Reloj"]); tb_licencia.Text = reader["Licencia"].ToString(); tb_modelo.Text = reader["Modelo"].ToString(); tb_patente.Text = reader["Patente"].ToString(); tb_rodado.Text = reader["Rodado"].ToString(); cb_hab.Checked = (Boolean)reader["Habilitado"]; } } } private void aceptar_Click_1(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: string error_txt = "ERROR: "; if (String.IsNullOrEmpty(marca_cb.Text)) { error_txt = String.Concat(error_txt, "\n Marca es obligatorio"); } if (String.IsNullOrEmpty(reloj_cb.Text)) { error_txt = String.Concat(error_txt, "\n Reloj es obligatorio"); } if (String.IsNullOrEmpty(tb_licencia.Text)) { error_txt = String.Concat(error_txt, "\n Licencia es obligatorio"); } if (String.IsNullOrEmpty(tb_modelo.Text)) { error_txt = String.Concat(error_txt, "\n Modelo es obligatorio"); } if (String.IsNullOrEmpty(tb_patente.Text)) { error_txt = String.Concat(error_txt, "\n Patente es obligatorio"); } if (String.IsNullOrEmpty(tb_rodado.Text)) { error_txt = String.Concat(error_txt, "\n Rodado es obligatorio"); } if((!String.IsNullOrEmpty(marca_cb.Text)) && (!String.IsNullOrEmpty(reloj_cb.Text))&& (!String.IsNullOrEmpty(tb_licencia.Text))&& (!String.IsNullOrEmpty(tb_modelo.Text))&& (!String.IsNullOrEmpty(tb_patente.Text))&& (!String.IsNullOrEmpty(tb_rodado.Text))) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTaxiMellizo(tb_patente.Text, tb_licencia.Text, Convert.ToInt32(reloj_cb.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Taxi mellizo"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con_un2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un2); SqlCommand comando_check_unique2 = new SqlCommand(Modelo.SqlQueries.getRelojUsado(Convert.ToInt32(reloj_cb.SelectedValue)), con_un2); SqlDataReader reader = comando_check_unique2.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Reloj en uso"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addAuto( Convert.ToInt32(marca_cb.SelectedValue), Convert.ToInt32(reloj_cb.SelectedValue), tb_licencia.Text, tb_modelo.Text, tb_patente.Text, tb_rodado.Text, true), con); comando_add_user.ExecuteNonQuery(); MessageBox.Show("Taxi agregado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }else { MessageBox.Show(error_txt); } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteAuto(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show("Taxi eliminado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTaxiMellizo(tb_patente.Text, tb_licencia.Text, Convert.ToInt32(reloj_cb.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); bool found = false; while(reader.Read()) { if(!reader[0].ToString().Equals(selected_elem.ToString())) { MessageBox.Show("Taxi mellizo"); found = true; break; } } if (found) { break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateAuto(selected_elem, Convert.ToInt32(marca_cb.SelectedValue), Convert.ToInt32(reloj_cb.SelectedValue), tb_licencia.Text, tb_modelo.Text, tb_patente.Text, tb_rodado.Text, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show("Taxi modificado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmAuto/AbmAuto.cs
C#
asf20
13,609
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmAuto { public partial class Listado_Auto : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Auto(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); busqueda_marca_cb.DataSource = ds.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_reloj_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_reloj_cb.DisplayMember = "Marca"; busqueda_reloj_cb.ValueMember = "Id"; busqueda_reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getAutos(), con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmAuto(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutoFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_patente_tb.Text, busqueda_licencia_tb.Text, busqueda_reloj_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_reloj_cb.SelectedValue)), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutos(), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmAuto/Listado_Auto.cs
C#
asf20
4,080
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace GestorDeFlotasDesktop { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Login.Login()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Program.cs
C#
asf20
519
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Facturar { public partial class Facturar : Form { public Facturar() { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getClientes, con); DataSet ds = new DataSet(); da.Fill(ds); cb_cliente.DataSource = ds.Tables[0].DefaultView; cb_cliente.DisplayMember = "Cliente"; cb_cliente.ValueMember = "Id"; cb_cliente.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); } private void aceptar_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(cb_cliente.Text) && (!String.IsNullOrEmpty(dtp_fin.Text)) && (!String.IsNullOrEmpty(dtp_ini.Text))) { Login.Login.mainForm.openForm(new Listado_Factura(Convert.ToInt32(cb_cliente.SelectedValue), dtp_ini.Value, dtp_fin.Value)); } else { MessageBox.Show("Todos los campos son obligatorios"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Facturar/Facturar.cs
C#
asf20
1,410
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Facturar { public partial class Listado_Factura : Form { private DataTable dt; public Listado_Factura(int cliente_id, DateTime f_ini, DateTime f_fin) { InitializeComponent(); tb_fini.Text = f_ini.Date.ToShortDateString(); tb_ffin.Text = f_fin.Date.ToShortDateString(); FillData(cliente_id, f_ini, f_fin); } void FillData(int cliente_id, DateTime f_ini, DateTime f_fin) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); da = new SqlDataAdapter(Modelo.SqlQueries.getFacturas(cliente_id, f_ini, f_fin), con); da.Fill(dt); dataGridView1.DataSource = dt; } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con2); SqlCommand comando_up_fact = new SqlCommand(Modelo.SqlQueries.updateFacturas(cliente_id, f_ini, f_fin), con2); comando_up_fact.ExecuteNonQuery(); } double total = 0; foreach (DataRow dr in dt.Rows) { if (dr.RowState != DataRowState.Deleted) total += Convert.ToDouble(dr["Importe"]); } tb_importe.Text = total.ToString(); using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_up_fact = new SqlCommand(Modelo.SqlQueries.insertFacturas(cliente_id, f_ini, f_fin, Convert.ToDouble(tb_importe.Text)), con3); comando_up_fact.ExecuteNonQuery(); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Facturar/Listado_Factura.cs
C#
asf20
2,129
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmChofer { public partial class Listado_Chofer : Form { private Modelo.FormActions.Actions action; public Listado_Chofer(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Chofer_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmChofer(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string consulta = ""; if (tb_apellido.Text == "" && tb_nombre.Text == "" && tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Choferes"; } else if (tb_dni.Text == "") { consulta = "SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '%" + tb_nombre.Text + "%' AND Ch_Apellido LIKE '%" + tb_apellido.Text + "%'"; } else { consulta = "SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '%" + tb_nombre.Text + "%' AND Ch_Apellido LIKE '%" + tb_apellido.Text + "%' AND Ch_Dni = " + tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmChofer/Listado_Chofer.cs
C#
asf20
4,545
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmChofer { public partial class AbmChofer : Form { private int selected_elem = -1; public AbmChofer(Modelo.FormActions.Actions action, string id) { InitializeComponent(); pk.Visible = false; lbl_estado.Text = "ALTA"; tb_grande.Visible = false; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { selected_elem = Convert.ToInt32(id); lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Id_Chofer = " + id, con); DataTable dt = new DataTable(); da.Fill(dt); //Ch_Nombre,Ch_Apellido,Ch_Dni,Ch_Direccion,Ch_Telefono,Ch_Mail,Ch_Fecha_Nac,Ch_Habilitado pk.Name = id; tb_nombre.Text = dt.Rows[0]["Ch_Nombre"].ToString(); tb_apellido.Text = dt.Rows[0]["Ch_Apellido"].ToString(); tb_dni.Text = dt.Rows[0]["Ch_Dni"].ToString(); tb_grande.Text = dt.Rows[0]["Ch_Direccion"].ToString(); tb_tel.Text = dt.Rows[0]["Ch_Telefono"].ToString(); tb_mail.Text = dt.Rows[0]["Ch_Mail"].ToString(); dt_nacimiento.Value = DateTime.Parse(dt.Rows[0]["Ch_Fecha_Nac"].ToString()); label7.Visible = label8.Visible = label9.Visible = label11.Visible = false; tb_dpto.Visible = tb_localidad.Visible = tb_nropiso.Visible = tb_cp.Visible = false; tb_grande.Visible = true; if (Convert.ToBoolean(dt.Rows[0]["Ch_Habilitado"].ToString()) == false) { cb_habi.Checked = false; } else { cb_habi.Checked = true; } if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; Propiedades.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmChofer_Load(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { if (lbl_estado.Text == "ALTA") { bool valido = true; string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_nombre.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_apellido.Text)) { error_txt = String.Concat(error_txt, "\n Apellido de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_dni.Text)) { error_txt = String.Concat(error_txt, "\n DNI de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_tel.Text)) { error_txt = String.Concat(error_txt, "\n Telefono de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_dir.Text)) { error_txt = String.Concat(error_txt, "\n Direccion de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_cp.Text)) { error_txt = String.Concat(error_txt, "\n Codigo Postal de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(dt_nacimiento.Text)) { error_txt = String.Concat(error_txt, "\n Fecha de Nacimiento de cliente es obligatorio"); valido = false; } if (valido) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getChoferByTel(tb_tel.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); bool found = false; while (reader.Read()) { if (!reader[0].ToString().Equals(selected_elem.ToString())) { found = true; break; } } if (found) { MessageBox.Show("Chofer duplicado. Ya existe otro con igual telefono"); } else { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Choferes(Ch_Nombre,Ch_Apellido,Ch_Dni,Ch_Direccion,Ch_Telefono,Ch_Mail,Ch_Fecha_Nac,Ch_Habilitado) VALUES(@nom,@ape,@dni,@dire,@tel,@mail,@fech,@habi)", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", tb_dni.Text); comando.Parameters.AddWithValue("dire", tb_dir.Text + " - " + tb_nropiso.Text + " " + tb_dpto.Text + " - " + "(" + tb_localidad.Text + ") (" + tb_cp.Text + ")"); comando.Parameters.AddWithValue("tel", tb_tel.Text); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_nombre.Text = ""; tb_apellido.Text = ""; tb_dni.Text = ""; tb_dir.Text = ""; tb_tel.Text = ""; tb_mail.Text = ""; tb_dpto.Text = ""; tb_nropiso.Text = ""; tb_localidad.Text = ""; tb_cp.Text = ""; cb_habi.Checked = false; dt_nacimiento.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } } if (lbl_estado.Text == "MODIFICACION") { bool valido = true; string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_nombre.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_apellido.Text)) { error_txt = String.Concat(error_txt, "\n Apellido de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_dni.Text)) { error_txt = String.Concat(error_txt, "\n DNI de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_tel.Text)) { error_txt = String.Concat(error_txt, "\n Telefono de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(tb_grande.Text)) { error_txt = String.Concat(error_txt, "\n Direccion de cliente es obligatorio"); valido = false; } if (String.IsNullOrEmpty(dt_nacimiento.Text)) { error_txt = String.Concat(error_txt, "\n Fecha de Nacimiento de cliente es obligatorio"); valido = false; } if (valido) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getChoferByTel(tb_tel.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); bool found = false; while (reader.Read()) { if (!reader[0].ToString().Equals(selected_elem.ToString())) { found = true; break; } } if (found) { MessageBox.Show("Chofer duplicado. Ya existe otro con igual telefono"); } else { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Choferes SET Ch_Nombre=@nom,Ch_Apellido=@ape,Ch_Dni=@dni,Ch_Direccion=@dire,Ch_Telefono=@tel,Ch_Mail=@mail,Ch_Fecha_Nac=@fech,Ch_Habilitado=@habi WHERE Id_Chofer = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", Convert.ToDecimal(tb_dni.Text)); comando.Parameters.AddWithValue("dire", tb_grande.Text); comando.Parameters.AddWithValue("tel", Convert.ToDecimal(tb_tel.Text)); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } } if (lbl_estado.Text == "BAJA") { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Choferes SET Ch_Habilitado=@habi WHERE Id_Chofer = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmChofer/AbmChofer.cs
C#
asf20
16,007
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.RendirViajes { public partial class RendierViajes : Form { public RendierViajes() { InitializeComponent(); tb_importe.Enabled = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlConnection con3 = Modelo.Modelo.createConnection(); SqlDataAdapter da3 = new SqlDataAdapter("SELECT Id_Chofer, (Ch_Nombre + ', ' +Ch_Apellido) as Ch_Nombre FROM NUNCA_TAXI.Choferes WHERE Ch_Habilitado = 1", con3); DataSet ds3 = new DataSet(); da3.Fill(ds3); cb_chofer.DataSource = ds3.Tables[0].DefaultView; cb_chofer.DisplayMember = "Ch_Nombre"; cb_chofer.ValueMember = "Id_Chofer"; cb_chofer.SelectedIndex = -1; Modelo.Modelo.closeConnection(con3); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); cb_turno.DataSource = ds2.Tables[0].DefaultView; cb_turno.DisplayMember = "Tu_Descripcion"; cb_turno.ValueMember = "Id_Turno"; cb_turno.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); } } private void calcular_Click(object sender, EventArgs e) { bool found = false; using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getIsRelojEnabled(Convert.ToDateTime(tb_dia.Text + "/" + tb_mes.Text + "/" + tb_anio.Text), Convert.ToInt32(cb_chofer.SelectedValue), Convert.ToInt32(cb_turno.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); while (reader.Read()) { if (!reader[0].ToString().Equals("1")) { found = true; break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (!found) { if (cb_turno.SelectedValue != "" && cb_chofer.SelectedValue != "" && tb_dia.Text != "" && tb_anio.Text != "" && tb_mes.Text != "") { string fecha = "'" + tb_anio.Text + "/" + tb_mes.Text + "/" + tb_dia.Text + "'"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + cb_turno.SelectedValue + ") AND (Id_Chofer = " + cb_chofer.SelectedValue + ") AND (DATEADD(dd, 0, DATEDIFF(dd, 0, Vi_Fecha)) = " + fecha + ")", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; da = new SqlDataAdapter("SELECT Id_Chofer, SUM(Vi_Importe) AS Monto_Rendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + cb_turno.SelectedValue + ") AND (DATEADD(dd, 0, DATEDIFF(dd, 0, Vi_Fecha)) = " + fecha + ") AND (Id_Chofer = " + cb_chofer.SelectedValue + ") GROUP BY Id_Chofer", con); dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("No hay elementos a mostrar"); } else { tb_importe.Text = dt.Rows[0]["Monto_Rendicion"].ToString(); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } else { MessageBox.Show("Reloj no esta habilitado"); } } private void rendir_Click(object sender, EventArgs e) { bool found = false; using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getIsRelojEnabled(Convert.ToDateTime(tb_dia.Text + "/" + tb_mes.Text + "/" + tb_anio.Text), Convert.ToInt32(cb_chofer.SelectedValue), Convert.ToInt32(cb_turno.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); while (reader.Read()) { if (!reader[0].ToString().Equals("1")) { found = true; break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (!found) { if (cb_turno.SelectedValue != "" && cb_chofer.SelectedValue != "" && tb_dia.Text != "" && tb_anio.Text != "" && tb_mes.Text != "") { string fecha = "'" + tb_anio.Text + "/" + tb_mes.Text + "/" + tb_dia.Text + "'"; string fecha_aux = tb_anio.Text + "/" + tb_mes.Text + "/" + tb_dia.Text; DateTime dt_fecha = DateTime.Parse(fecha_aux); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Viajes SET Vi_FechaRendido=@fecha WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + cb_turno.SelectedValue + ") AND (Id_Chofer = " + cb_chofer.SelectedValue + ") AND (DATEADD(dd, 0, DATEDIFF(dd, 0, Vi_Fecha)) = " + fecha + ")", con); comando.Parameters.AddWithValue("fecha", System.DateTime.Now); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Rendiciones(Id_Chofer,Id_Turno,Ren_Fecha,Ren_Importe) VALUES(@chofer,@turno,@fecha,@importe)", con); comando.Parameters.AddWithValue("chofer", cb_chofer.SelectedValue); comando.Parameters.AddWithValue("turno", cb_turno.SelectedValue); comando.Parameters.AddWithValue("fecha", dt_fecha); if (String.IsNullOrEmpty(tb_importe.Text)) { comando.Parameters.AddWithValue("importe", 0); } else { comando.Parameters.AddWithValue("importe", Convert.ToDecimal(tb_importe.Text)); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); Login.Login.mainForm.openForm(new RendierViajes()); } } } else { MessageBox.Show("Por favor, complete todos los campos para continuar"); } } else { MessageBox.Show("Reloj no esta habilitado"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/RendirViajes/RendierViajes.cs
C#
asf20
9,201
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using GestorDeFlotasDesktop.Modelo; // Objetos SQL using System.Data.SqlClient; namespace GestorDeFlotasDesktop { public partial class MainForm : Form { private Login.Login loginForm; private Form activeForm = null; public MainForm(Login.Login loginForm) { InitializeComponent(); this.loginForm = loginForm; this.loginForm.Hide(); this.filterOptions(); } private void filterOptions() { if(!Login.Login.permisosList.Contains(1)) { clienteToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(2)) { rolToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(3)) { usuarioToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(4)) { autoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(5)) { relojToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(6)) { choferToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(7)) { turnoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(8)) { asignarChoferAutoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(9)) { nuevoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(10)) { rendicionToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(11)) { facturacionToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(12)) { reportesToolStripMenuItem.Visible = false; } } public void openForm(Form form){ //lo borro de la coleccion de controles, y seteo la activa a null if (this.activeForm != null) { this.Controls.Remove(this.activeForm); this.activeForm.Dispose(); this.activeForm = null; } this.activeForm = form; this.activeForm.TopLevel = false; this.activeForm.Dock = DockStyle.Fill; this.activeForm.FormBorderStyle = FormBorderStyle.None; this.activeForm.Visible = true; this.Controls.Add(this.activeForm); } private void MainForm_Load(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); toolStripStatusLabel1.Text = "Conectado."; } catch (Exception) { toolStripStatusLabel1.Text = "Sin Conexion !!"; toolStripStatusLabel1.ForeColor = Color.Red; } finally { Modelo.Modelo.closeConnection(con); } } } #region Salir private void salirToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } #endregion #region Formulario Cliente private void altaClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.AbmCliente(Modelo.FormActions.Actions.Alta, "")); } private void bajaClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Baja)); } private void modificacionClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Rol private void altaRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.AbmRol(Modelo.FormActions.Actions.Alta)); } private void bajaRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Baja)); } private void modificacionRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Usuario private void altaUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.AbmUsuario(Modelo.FormActions.Actions.Alta)); } private void bajaUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Baja)); } private void modificacionUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Auto private void altaAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.AbmAuto(Modelo.FormActions.Actions.Alta)); } private void bajaAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Baja)); } private void modificacionAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Reloj private void altaRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.AbmReloj(Modelo.FormActions.Actions.Alta)); } private void bajaRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Baja)); } private void modificacionRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Chofer private void altaChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.AbmChofer(Modelo.FormActions.Actions.Alta, "")); } private void bajaChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Baja)); } private void modificacionChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Turno-Tarifa private void altaTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTarifa.AbmTurno(Modelo.FormActions.Actions.Alta, "")); } private void bajaTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Baja)); } private void modificacionTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Modificacion)); } #endregion private void nuevoToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new RegistrarViaje.RegistrarViajes()); } private void asignarChoferAutoToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new AsignChoferAuto.AsignChoferAuto()); } private void facturacionToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new Facturar.Facturar()); } private void rendicionToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new RendirViajes.RendierViajes()); } private void reportesToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new Listado.Listado()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/MainForm.cs
C#
asf20
9,199
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmRol { public partial class AbmRol : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmRol(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; func.Enabled = false; this.aceptar_btn.Text = "Eliminar"; this.tb_rol.Enabled = false; cb_hab.Enabled = false; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar_btn.Text = "Modificar"; cb_hab.Enabled = true; tb_rol.Enabled = true; break; } } public AbmRol(Modelo.FormActions.Actions runAction) { InitializeComponent(); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoleById(selected_elem), con); DataTable dt = new DataTable(); da.Fill(dt); DataRow rol_info = dt.Rows[0]; tb_rol.Text = rol_info.ItemArray[1].ToString(); cb_hab.Checked = (bool)rol_info.ItemArray[2]; SqlDataAdapter rol_perm_da = new SqlDataAdapter(Modelo.SqlQueries.getRolePermissions(selected_elem), con); DataTable rol_perm_dt = new DataTable(); rol_perm_da.Fill(rol_perm_dt); foreach (DataRow perm in rol_perm_dt.Rows) { Convert.ToInt32(perm.ItemArray[0].ToString()); string key = String.Empty; foreach (KeyValuePair<string, int> pair in Modelo.Permissions.PermissionsDict) { if (pair.Value == Convert.ToInt32(perm.ItemArray[0].ToString())) { key = pair.Key; break; } } foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Text.Equals(key)) { ((CheckBox)c).Checked = true; } } } } } } private void aceptar_btn_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(tb_rol.Text)) { switch (action) { case Modelo.FormActions.Actions.Alta: { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addRole(tb_rol.Text), con); comando_add_user.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_role_id = new SqlCommand(Modelo.SqlQueries.getRoleIdByName(tb_rol.Text), con2); SqlDataReader reader = comando_get_role_id.ExecuteReader(); List<int> permissions = new List<int>(); while (reader.Read()) { foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked) { permissions.Add(Modelo.Permissions.PermissionsDict[c.Text]); } } } SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand comando_add_role_permissions = new SqlCommand(Modelo.SqlQueries.addRolePermissions(Convert.ToInt32(reader.GetDecimal(0)), permissions), con3); if (permissions.Count != 0) { comando_add_role_permissions.ExecuteNonQuery(); } Modelo.Modelo.closeConnection(con3); } MessageBox.Show(String.Format("Rol {0} agregado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteRole(selected_elem), con); Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Rol {0} eliminado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } break; case Modelo.FormActions.Actions.Modificacion: List<int> permissions_list = new List<int>(); foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked) { permissions_list.Add(Modelo.Permissions.PermissionsDict[c.Text]); } } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateRole(selected_elem, tb_rol.Text, permissions_list, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Rol {0} modificado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } else { MessageBox.Show("ERROR: El nombre del rol es obligatorio."); } } private void AbmRol_Load(object sender, EventArgs e) { } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmRol/AbmRol.cs
C#
asf20
9,930
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmRol { public partial class Listado_Rol : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Rol(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRoles, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmRol(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRolesFiltered(busqueda_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmRol/Listado_Rol.cs
C#
asf20
2,647
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("GestorDeFlotasDesktop")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("GestorDeFlotasDesktop")] [assembly: AssemblyCopyright("Copyright © 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("a1c2fdc9-25c4-4ac4-9e6f-a482c920e7f3")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Properties/AssemblyInfo.cs
C#
asf20
1,454
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmTurno { public partial class Listado : Form { private Modelo.FormActions.Actions action; public Listado(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; for (int i = 0; i < dt.Rows.Count; i++) { cb_desc.Items.Add(dt.Rows[i]["Tu_Descripcion"]); } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Load(object sender, EventArgs e) { } private void cb_desc_SelectedIndexChanged(object sender, EventArgs e) { string curItem = cb_desc.SelectedItem.ToString(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_descripcion = '" + curItem + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 7) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmTarifa.AbmTurno(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_busqueda.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Descripcion LIKE '%" + tb_busqueda.Text + "%'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmTurno/Listado.cs
C#
asf20
4,166
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmTarifa { public partial class AbmTurno : Form { private int selected_elem = -1; public AbmTurno(Modelo.FormActions.Actions action, string id) { InitializeComponent(); lbl_estado.Text = "ALTA"; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { selected_elem = Convert.ToInt32(id); lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Id_Turno = " + id , con); DataTable dt = new DataTable(); da.Fill(dt); tb_desc.Text = dt.Rows[0]["Tu_Descripcion"].ToString(); tb_ini.Text = dt.Rows[0]["Tu_Hora_Ini"].ToString(); tb_fin.Text = dt.Rows[0]["Tu_Hora_Fin"].ToString(); tb_ficha.Text = dt.Rows[0]["Tu_Valor_Ficha"].ToString(); tb_bandera.Text = dt.Rows[0]["Tu_Valor_Bandera"].ToString(); if (Convert.ToBoolean(dt.Rows[0]["Tu_Habilitado"].ToString()) == false) { cb_habilitado.Checked = false; } else { cb_habilitado.Checked = true; } tb_desc.Enabled = false; if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; gb_car.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmTurno_Load(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { if (tb_bandera.Text != "" && tb_desc.Text != "" && tb_ficha.Text != "" && tb_fin.Text != "" && tb_ini.Text != "" && Convert.ToInt32(tb_ini.Text) <= 24 && Convert.ToInt32(tb_ini.Text) >= 0 && Convert.ToInt32(tb_fin.Text) <= 24 && Convert.ToInt32(tb_fin.Text) >= 0) { if (!(Convert.ToInt32(tb_ini.Text) >= Convert.ToInt32(tb_fin.Text))) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (lbl_estado.Text == "ALTA") { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTurnoByFranja(tb_ini.Text, tb_fin.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Los turnos no pueden pisarse entre si. Franja horaria ocupada"); } else { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Turnos(Tu_Hora_Ini,Tu_Hora_Fin,Tu_Descripcion,Tu_Valor_Ficha,Tu_Valor_Bandera,Tu_Habilitado) VALUES(@h_ini,@h_fin,@desc,@ficha,@bandera,@habi)", con); comando.Parameters.AddWithValue("h_ini", tb_ini.Text); comando.Parameters.AddWithValue("h_fin", tb_fin.Text); comando.Parameters.AddWithValue("desc", tb_desc.Text); comando.Parameters.AddWithValue("ficha", Convert.ToDecimal(tb_ficha.Text)); comando.Parameters.AddWithValue("bandera", Convert.ToDecimal(tb_bandera.Text)); if (cb_habilitado.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habilitado.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_ini.Text = ""; tb_fin.Text = ""; tb_desc.Text = ""; tb_ficha.Text = ""; tb_bandera.Text = ""; Modelo.Modelo.closeConnection(con); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } if (lbl_estado.Text == "MODIFICACION") { bool found = false; using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTurnoByFranja(tb_ini.Text, tb_fin.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); while (reader.Read()) { if (!reader[0].ToString().Equals(selected_elem.ToString())) { MessageBox.Show("Los turnos no pueden pisarse entre si. Franja horaria ocupada"); found = true; break; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (!found) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Turnos SET Tu_Hora_Ini=@h_ini,Tu_Hora_Fin=@h_fin,Tu_Descripcion=@desc,Tu_Valor_Ficha=@ficha,Tu_Valor_Bandera=@bandera,Tu_Habilitado=@habi WHERE Tu_Descripcion = '" + tb_desc.Text + "'", con); comando.Parameters.AddWithValue("h_ini", tb_ini.Text); comando.Parameters.AddWithValue("h_fin", tb_fin.Text); comando.Parameters.AddWithValue("desc", tb_desc.Text); comando.Parameters.AddWithValue("ficha", Convert.ToDecimal(tb_ficha.Text)); comando.Parameters.AddWithValue("bandera", Convert.ToDecimal(tb_bandera.Text)); if (cb_habilitado.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habilitado.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Turnos SET Tu_Habilitado=@habi WHERE Tu_Descripcion = '" + tb_desc.Text + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } else { MessageBox.Show("La hora de inicio debe ser menor a la hora fin"); } } else { MessageBox.Show("Por favor, complete todos los campos con valores validos para continuar"); } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmTurno/AbmTurno.cs
C#
asf20
11,509
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class AsignChoferAuto : Form { private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public AsignChoferAuto() { InitializeComponent(); fecha = dtp_fecha.Value; } public AsignChoferAuto(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; auto_text = auto_txt; chofer_id = chofer; chofer_text = chofer_txt; turno_id = turno; turno_text = turno_txt; InitializeComponent(); dtp_fecha.Value = fecha; tb_auto.Text = auto_text; tb_chofer.Text = chofer_text; tb_turno.Text = turno_text; } private void aceptar_Click_1(object sender, EventArgs e) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getFecAutCho(fecha, auto_id, turno_id), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("La combinacion Fecha-Auto-Turno ya existe en la BD"); } else { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_ACA = new SqlCommand(Modelo.SqlQueries.addACA( fecha, auto_id, chofer_id, turno_id), con); comando_add_ACA.ExecuteNonQuery(); MessageBox.Show("Asignacion Chofer-Auto agregada"); Login.Login.mainForm.openForm(new AsignChoferAuto()); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void bt_auto_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Auto(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void bt_chofer_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Chofer(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void bt_turno_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Turno(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AsignChoferAuto/AsignChoferAuto.cs
C#
asf20
4,160
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Auto : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Auto(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); busqueda_marca_cb.DataSource = ds.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_reloj_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_reloj_cb.DisplayMember = "Marca"; busqueda_reloj_cb.ValueMember = "Id"; busqueda_reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; auto_id = Convert.ToInt32(row.Cells["Id"].Value); auto_text = String.Concat(row.Cells["Marca"].Value, " - ", row.Cells["Model"].Value); Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutoFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_patente_tb.Text, busqueda_licencia_tb.Text, busqueda_reloj_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_reloj_cb.SelectedValue)), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Auto.cs
C#
asf20
4,340
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Turno : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Turno(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; for (int i = 0; i < dt.Rows.Count; i++) { cb_desc.Items.Add(dt.Rows[i]["Tu_Descripcion"]); } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void Listado_Load(object sender, EventArgs e) { } private void cb_desc_SelectedIndexChanged(object sender, EventArgs e) { string curItem = cb_desc.SelectedItem.ToString(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Habilitado = 1 AND Tu_descripcion = '" + curItem + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 7) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewCell desc_cell = dataGridView1.Rows[e.RowIndex].Cells[3]; Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, chofer_id, chofer_text, Convert.ToInt32(cell.Value.ToString()), desc_cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_busqueda.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Habilitado = 1 AND Tu_descripcion LIKE '" + tb_busqueda.Text + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Turno.cs
C#
asf20
4,712
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Chofer : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Chofer(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void Listado_Chofer_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewCell cell_nombre = dataGridView1.Rows[e.RowIndex].Cells[1]; DataGridViewCell cell_apellido = dataGridView1.Rows[e.RowIndex].Cells[2]; Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, Convert.ToInt32(cell.Value.ToString()), String.Concat(cell_nombre.Value.ToString(), " - ", cell_apellido.Value.ToString()), turno_id, turno_text)); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string dni; if (tb_dni.Text == "") { dni = "0"; } else { dni = tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '" + tb_nombre.Text + "' OR Ch_Apellido LIKE '" + tb_apellido.Text + "' OR Ch_Dni = " + dni + " AND Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Chofer.cs
C#
asf20
4,872
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Modelo { public static class Modelo { //public static System.Data.SqlClient.SqlConnection con; public const string con_str = "Data Source=localhost\\SQLSERVER2005; Initial Catalog=GD1C2012; User ID = gd; Password = gd2012"; public static SqlConnection createConnection() { SqlConnection con = new SqlConnection(); con.ConnectionString = con_str; return con; } public static void openConnection(SqlConnection con) { con.Open(); } public static void closeConnection(SqlConnection con) { con.Close(); } } public class User { public void getRoles() { } } public class Roles { public void getPermissions() { } } public class Permissions { public static Dictionary<string, int> PermissionsDict= new Dictionary<string,int>() { {"ABM de Cliente",1}, {"ABM de Rol",2}, {"ABM de Usuario",3}, {"ABM de Auto",4}, {"ABM de Reloj",5}, {"ABM de Chofer",6}, {"ABM de Turno",7}, {"Asignación Chofer-Auto",8}, {"Registro de Viajes",9}, {"Rendición de Cuenta del Chofer",10}, {"Facturación del Cliente",11}, {"Listado Estadístico",12}, }; } public static class FormActions { public enum Actions { Alta, Baja, Modificacion } } public static class SqlQueries { #region Roles public static string getRoles = "SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles;"; public static string getEnabledRoles = "SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles WHERE Ro_Habilitado = 1;"; public static string getRolesFiltered(string filter_text) { return String.Format("SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles WHERE Ro_Descripcion LIKE '%{0}%';", filter_text); } public static string getRoleById(int id) { return String.Format("SELECT Id_Rol, Ro_Descripcion, Ro_Habilitado FROM NUNCA_TAXI.Roles WHERE Id_Rol = {0};", id); } public static string deleteRole(int id) { string delete_role = String.Format("UPDATE NUNCA_TAXI.Roles SET Ro_habilitado = 0 WHERE Id_Rol = {0};", id); string delete_user_role = String.Format("DELETE FROM NUNCA_TAXI.UsuariosRoles WHERE Id_Rol = {0};", id); return String.Concat(delete_role, delete_user_role); } public static string addRole(string role) { return String.Format("INSERT INTO NUNCA_TAXI.Roles(Ro_Descripcion, Ro_Habilitado)" + " VALUES('{0}',1);", role); } public static string getRoleIdByName(string role) { return String.Format("SELECT TOP 1 Id_Rol FROM NUNCA_TAXI.Roles WHERE Ro_Descripcion = '{0}';", role); } public static string addRolePermissions(int roleId, List<int> permissions) { string insert_role_permissions = String.Empty; foreach (int permission in permissions) { string insert_role_permission = String.Format("INSERT INTO NUNCA_TAXI.PermisosRoles(Id_Rol, Id_Permiso)" + " VALUES ({0}, {1});", roleId, permission); insert_role_permissions = String.Concat(insert_role_permissions, insert_role_permission); } return insert_role_permissions; } public static string updateRole(int roleId, string roleName, List<int> permissions, bool enabled) { string update_rol_info = String.Format("UPDATE NUNCA_TAXI.Roles SET Ro_Descripcion = '{1}', Ro_Habilitado = {2} " + "WHERE Id_Rol = {0};", roleId, roleName, Convert.ToInt32(enabled)); string delete_roles_permissions = String.Format("DELETE FROM NUNCA_TAXI.PermisosRoles WHERE Id_Rol = {0};", roleId); string update_roles_permissions = String.Concat(update_rol_info, delete_roles_permissions); foreach (int permission in permissions) { string update_role_permission = String.Format("INSERT INTO NUNCA_TAXI.PermisosRoles(Id_Rol, Id_Permiso)" + " VALUES ({0}, {1});", roleId, permission); update_roles_permissions = String.Concat(update_roles_permissions, update_role_permission); } return update_roles_permissions; } public static string getRolePermissions(int roleId) { return String.Format("SELECT Id_Permiso FROM NUNCA_TAXI.PermisosRoles WHERE Id_Rol = {0};", roleId); } #endregion #region Users public static string getUsers = "SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios;"; public static string getEnabledUsers = "SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_habilitado = 1;"; public static string getUsersFiltered(string filter_text) { return String.Format("SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario LIKE '%{0}%';", filter_text); } public static string getUserById(int id) { return String.Format("SELECT Id_Usuario, Us_Usuario, Us_Habilitado FROM NUNCA_TAXI.Usuarios WHERE Id_Usuario = {0};", id); } public static string getUserIdByUsername(string username) { return String.Format("SELECT Id_Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario = '{0}';", username); } public static string deleteUser(int id) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = 0 WHERE Id_Usuario = {0};", id); } public static string getUserRoles(int userId) { return String.Format("SELECT Rol.Id_Rol as Id, Rol.Ro_Descripcion as Descripcion, " + "ISNULL((SELECT 1 FROM NUNCA_TAXI.UsuariosRoles " + "WHERE Id_Rol = Rol.Id_Rol " + "AND Id_usuario = {0}), 0) as Habilitado " + "FROM NUNCA_TAXI.Roles Rol WHERE Rol.Ro_Habilitado = 1;", userId); } public static string addUser(string user, string passwd) { return String.Format("INSERT INTO NUNCA_TAXI.Usuarios(Us_Habilitado, Us_Usuario, Us_Password)" + " VALUES(1,'{0}','{1}');", user, passwd); } public static string addUserRoles(int userId, List<int> roles) { string insert_user_roles = String.Empty; foreach (int role in roles) { string insert_user_role = String.Format("INSERT INTO NUNCA_TAXI.UsuariosRoles(Id_Usuario, Id_Rol)" + " VALUES ({0}, {1});",userId, role); insert_user_roles = String.Concat(insert_user_roles, insert_user_role); } return insert_user_roles; } public static string updateUser(int userId, string passwd, List<int> roles, bool enabled) { string update_user = String.Empty; if (!String.IsNullOrEmpty(passwd) && !passwd.Equals("47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")) { update_user = String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Password = '{0}', Us_Habilitado = {2} " + "WHERE Id_Usuario = {1};", passwd, userId, Convert.ToInt32(enabled)); } else { update_user = String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = {0} " + "WHERE Id_Usuario = {1};", Convert.ToInt32(enabled), userId); } string delete_user_roles = String.Format("DELETE FROM NUNCA_TAXI.UsuariosRoles WHERE Id_Usuario = {0};", userId); string update_user_roles = String.Concat(update_user, delete_user_roles); foreach (int role in roles) { string update_user_role = String.Format("INSERT INTO NUNCA_TAXI.UsuariosRoles(Id_Usuario, Id_Rol)" + " VALUES ({0}, {1});", userId, role); update_user_roles = String.Concat(update_user_roles, update_user_role); } return update_user_roles; } public static string getUserInfo(string user) { return String.Format("SELECT Us_Usuario, Us_Password, Us_Login_Failed, Us_Habilitado FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario = '{0}';",user); } public static string resetLoginFails(string user) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Login_Failed = 0 WHERE Us_Usuario = '{0}'", user); } public static string disableUser(string user) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = 0 WHERE Us_Usuario = '{0}'", user); } public static string incUserLoginFailed(string user, int fails) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Login_Failed = {1} WHERE Us_Usuario = '{0}'", user, fails); } #endregion #region Auto public static string getAutoFiltered(int marca, string modelo, string patente, string licencia, int reloj){ string marca_where = String.Empty; string modelo_where = String.Empty; string patente_where = String.Empty; string licencia_where = String.Empty; string reloj_where = String.Empty; string auto_filtered = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj"; if (marca != -1) { marca_where = String.Format(" AND T.Id_MarcaTaxi = {0}", Convert.ToInt32(marca)); auto_filtered = String.Concat(auto_filtered, marca_where); } if (!String.IsNullOrEmpty(modelo)) { modelo_where = String.Format(" AND T.Ta_Modelo LIKE '%{0}%'", modelo); auto_filtered = String.Concat(auto_filtered, modelo_where); } if (!String.IsNullOrEmpty(patente)) { patente_where = String.Format(" AND T.Ta_Patente LIKE '%{0}%'", patente); auto_filtered = String.Concat(auto_filtered, patente_where); } if (!String.IsNullOrEmpty(licencia)) { licencia_where = String.Format(" AND T.Ta_Licencia LIKE '%{0}%'", licencia); auto_filtered = String.Concat(auto_filtered, licencia_where); } if (reloj != -1) { reloj_where = String.Format(" AND T.Id_Reloj = {0}", Convert.ToInt32(reloj)); auto_filtered = String.Concat(auto_filtered, reloj_where); } auto_filtered = String.Concat(auto_filtered, ";"); return auto_filtered; } public static string getAutos() { return "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj;"; } public static string getAutosComplete = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj, T.Ta_Rodado as Rodado, T.Ta_Habilitado as Habilitado " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj;;"; public static string getEnabledAutos = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj AND T.Ta_Habilitado = 1;"; public static string getAutoById(int id) { string getEnabledAutosById = "SELECT T.Id_Taxi as ID, T.Id_MarcaTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, T.Id_Reloj as Reloj, T.Ta_Rodado as Rodado, T.Ta_Habilitado as Habilitado " + "FROM NUNCA_TAXI.Taxis T " + "WHERE T.Id_Taxi = {0};"; return String.Format(getEnabledAutosById, id); } public static string deleteAuto(int id) { return String.Format("UPDATE NUNCA_TAXI.Taxis SET Ta_Habilitado = 0 WHERE Id_Taxi = {0};", id); } public static string updateAuto(int id, int marca, int reloj, string licencia, string modelo, string patente, string rodado, bool hab) { return String.Format("UPDATE NUNCA_TAXI.Taxis SET Id_MarcaTaxi = {1}, Id_Reloj = {2} , Ta_Licencia = '{3}', Ta_Modelo = '{4}', Ta_Patente = '{5}', Ta_Rodado = '{6}', Ta_Habilitado = {7} " + "WHERE Id_Taxi = {0};", id, marca, reloj, licencia, modelo, patente, rodado, Convert.ToInt32(hab)); } public static string addAuto(int marca, int reloj, string licencia, string modelo, string patente, string rodado, bool hab) { return String.Format("INSERT INTO NUNCA_TAXI.Taxis(Id_MarcaTaxi, Id_Reloj, Ta_Licencia, Ta_Modelo, Ta_Patente, Ta_Rodado, Ta_Habilitado) " + "VALUES({0}, {1}, '{2}', '{3}', '{4}', '{5}', {6})", marca, reloj, licencia, modelo, patente, rodado, Convert.ToInt32(hab)); } #endregion #region Relojes public static string getEnabledRelojes = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj AND R.Re_Habilitado = 1;"; public static string getRelojes = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj;"; public static string getRelojFiltered(int marca, string modelo, string nro_serie){ string marca_where = String.Empty; string modelo_where = String.Empty; string nro_serie_where = String.Empty; string reloj_filtered = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj"; if (marca != -1) { marca_where = String.Format(" AND R.Id_MarcaReloj = {0}", Convert.ToInt32(marca)); reloj_filtered = String.Concat(reloj_filtered, marca_where); } if (!String.IsNullOrEmpty(modelo)) { modelo_where = String.Format(" AND R.Re_Modelo LIKE '%{0}%'", modelo); reloj_filtered = String.Concat(reloj_filtered, modelo_where); } if (!String.IsNullOrEmpty(nro_serie)) { nro_serie_where = String.Format(" AND R.Re_NoSerie LIKE '%{0}%'", nro_serie); reloj_filtered = String.Concat(reloj_filtered, nro_serie_where); } reloj_filtered = String.Concat(reloj_filtered, ";"); return reloj_filtered; } public static string getRelojById(int id) { return String.Format("SELECT R.Re_Habilitado as Habilitado, R.Re_Fecha_Ver as FecVerific, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, R.Id_MarcaReloj as Marca " + "FROM NUNCA_TAXI.Relojes R " + "WHERE R.Id_Reloj = {0};", id); } public static string addReloj(int id_marca_reloj, string modelo, string nroserie, DateTime verific, bool hab) { return String.Format("INSERT INTO NUNCA_TAXI.Relojes(Id_MarcaReloj, Re_modelo, Re_NoSerie, Re_Habilitado, Re_Fecha_Ver) " + "VALUES({0}, '{1}', '{2}', {3}, '{4}');", id_marca_reloj, modelo, nroserie, Convert.ToInt32(hab), String.Format("{0:d/M/yyyy HH:mm:ss}", verific)); } public static string deleteReloj(int id) { return String.Format("UPDATE NUNCA_TAXI.Relojes SET Re_Habilitado = 0 WHERE Id_Reloj = {0};", id); } public static string updateReloj(int id, int id_marca_reloj, string modelo, string nroserie, DateTime verific, bool hab) { return String.Format("UPDATE NUNCA_TAXI.Relojes SET Id_MarcaReloj = {0}, Re_modelo = '{1}', Re_NoSerie = '{2}', Re_Habilitado = {3}, Re_Fecha_Ver = '{4}' " + "WHERE Id_Reloj = {5};", id_marca_reloj, modelo, nroserie, Convert.ToInt32(hab), String.Format("{0:d/M/yyyy HH:mm:ss}", verific), id); } #endregion #region MarcasTaxi public static string getMarcasTaxi() { return "SELECT Id_MarcaTaxi as Id, Ma_NombreTaxi as Marca FROM NUNCA_TAXI.MarcasTaxi;"; } #endregion #region MarcasReloj public static string getMarcasReloj() { return "SELECT Id_MarcaReloj as Id, Ma_NombreReloj as Marca FROM NUNCA_TAXI.MarcasReloj;"; } public static string getMarcaModeloReloj() { return "SELECT R.Id_Reloj as Id, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj AND R.Re_Habilitado = 1;"; } #endregion public static string addACA(DateTime fecha, int auto_id, int chofer_id, int turno_id) { return String.Format("INSERT INTO NUNCA_TAXI.ChoferesTurnosTaxis(Id_Chofer, Id_Turno, Id_Taxi, Fecha) " + " VALUES({2},{3},{1},'{0}');",String.Format("{0:d/M/yyyy}", fecha), auto_id,chofer_id,turno_id); } public static string getClientes = "SELECT Id_Cliente as Id, (Cl_Nombre + ' - ' + Cl_Apellido) as Cliente FROM NUNCA_TAXI.Clientes WHERE Clientes.Id_Cliente != 1;"; public static string getFacturas(int id_cliente, DateTime ini, DateTime fin) { return String.Format("SELECT (Ch.Ch_Nombre + ' - ' + Ch.Ch_Apellido) as Chofer, V.Vi_Cant_Fichas as CantidadFichas, V.Vi_Importe as Importe, V.Vi_Fecha as Fecha, T.Tu_Descripcion as Turno " + "FROM NUNCA_TAXI.Choferes Ch, NUNCA_TAXI.Viajes V, NUNCA_TAXI.Turnos T " + "WHERE V.Id_Chofer = Ch.Id_Chofer AND V.Id_Turno = T.Id_Turno AND V.Id_Cliente = {0} AND V.Vi_Fecha <= '{1}' AND V.Vi_Fecha >= '{2}' AND Vi_FFactura_Ini IS NULL AND Vi_FFactura_Fin IS NULL ;", id_cliente, String.Format("{0:d/M/yyyy HH:mm:ss}", fin), String.Format("{0:d/M/yyyy HH:mm:ss}", ini)); } public static string updateFacturas(int id_cliente, DateTime ini, DateTime fin) { return String.Format("UPDATE NUNCA_TAXI.Viajes SET Vi_FFactura_Ini = '{2}', Vi_FFactura_Fin = '{1}' WHERE Id_Cliente = {0};", id_cliente, String.Format("{0:d/M/yyyy HH:mm:ss}", fin), String.Format("{0:d/M/yyyy HH:mm:ss}", ini)); } public static string insertFacturas(int id_cliente, DateTime ini, DateTime fin, double total) { string insertSql = String.Format("INSERT INTO NUNCA_Taxi.Facturas(Id_Cliente, Fa_Feha_Inicio, Fa_Fecha_Fin, Fa_Importe)" + " VALUES({0},DATEADD(dd, 0, DATEDIFF(dd, 0, '{1}')),DATEADD(dd, 0, DATEDIFF(dd, 0, '{1}')), {3});", id_cliente, ini, fin, total); return insertSql; } public static string getTaxiMellizo(string patente, string licencia, int reloj) { return String.Format("SELECT Id_Taxi as Id " + "FROM NUNCA_TAXI.Taxis T " + "WHERE Ta_Patente = '{0}' OR Ta_Licencia = '{1}' OR Id_Reloj = {2}", patente, licencia, reloj); } public static string getRelojUsado(int reloj) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.Taxis T " + "WHERE Id_Reloj = {0} AND Ta_Habilitado = 1;", reloj); } public static string getFecAutCho(DateTime fecha, int autoId, int turnoId) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.ChoferesTurnosTaxis " + "WHERE Id_Turno = {0} AND Id_Taxi = {1} AND Fecha = '{2}';", turnoId, autoId, String.Format("{0:d/M/yyyy}", fecha)); } public static string getClienteByTel(string tel) { return String.Format("SELECT Id_Cliente FROM NUNCA_TAXI.Clientes WHERE Cl_Telefono = {0}", Convert.ToInt32(tel)); } public static string getTurnoByFranja(string hora_ini, string hora_fin) { return String.Format("SELECT Id_Turno FROM NUNCA_TAXI.Turnos WHERE (({0} > Tu_Hora_Ini AND {0} < Tu_Hora_Fin) OR ({1} > Tu_Hora_Ini AND {1} < Tu_Hora_Fin) OR({0} < Tu_Hora_Ini AND {1} > Tu_Hora_Fin) OR ({0} = Tu_Hora_Ini AND {1} = Tu_Hora_Fin)) AND Tu_Habilitado = 1;", hora_ini, hora_fin); } public static string getChoferByTel(string tel) { return String.Format("SELECT Id_Cliente FROM NUNCA_TAXI.Clientes WHERE Cl_Telefono = {0}", Convert.ToInt32(tel)); } public static string getIsRelojEnabled(DateTime fecha, int chofer, int turno) { return String.Format("SELECT Re_Habilitado FROM NUNCA_TAXI.Relojes " + "WHERE Id_Reloj = (SELECT Id_Reloj FROM NUNCA_TAXI.Taxis " + "WHERE Id_Taxi =(SELECT Id_Taxi FROM NUNCA_TAXI.ChoferesTurnosTaxis " + "WHERE Id_Chofer = {1} AND Id_Turno = {2} AND DATEADD(dd, 0, DATEDIFF(dd, 0, Fecha)) = DATEADD(dd, 0, DATEDIFF(dd, 0, '{0}'))));", fecha, chofer, turno); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Modelo/Modelo.cs
C#
asf20
24,737
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmReloj { public partial class Listado_Reloj : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Reloj(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_marca_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRelojes, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getRelojes, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmReloj(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRelojFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_nroserie_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRelojes, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmReloj/Listado_Reloj.cs
C#
asf20
3,403
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmReloj { public partial class AbmReloj : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmReloj(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; reloj_cb.Enabled = false; tb_modelo.Enabled = false; tb_nroserie.Enabled = false; verific_dtp.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar.Text = "Modificar"; break; } } public AbmReloj(Modelo.FormActions.Actions runAction) { InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_get_autos = new SqlCommand(Modelo.SqlQueries.getRelojById(selected_elem), con3); SqlDataReader reader = comando_get_autos.ExecuteReader(); while (reader.Read()) { reloj_cb.SelectedValue = Convert.ToInt32(reader["Marca"]); tb_modelo.Text = reader["Modelo"].ToString(); tb_nroserie.Text = reader["NroSerie"].ToString(); verific_dtp.Value = Convert.ToDateTime(reader["FecVerific"]); cb_hab.Checked = (Boolean)reader["Habilitado"]; } } } private void aceptar_Click(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_reloj = new SqlCommand(Modelo.SqlQueries.addReloj( Convert.ToInt32(reloj_cb.SelectedValue), tb_modelo.Text, tb_nroserie.Text, verific_dtp.Value, true), con); comando_add_reloj.ExecuteNonQuery(); MessageBox.Show("Reloj agregado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getRelojUsado(selected_elem), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Reloj estaba siendo usado por un taxi habilitado"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteReloj(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show("Reloj eliminado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateReloj(selected_elem, Convert.ToInt32(reloj_cb.SelectedValue), tb_modelo.Text, tb_nroserie.Text, verific_dtp.Value, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show("Reloj modificado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/AbmReloj/AbmReloj.cs
C#
asf20
7,882
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Listado { public partial class Listado : Form { public Listado() { InitializeComponent(); cb_tipo_listado.Items.Add("choferes"); cb_tipo_listado.Items.Add("taxis"); cb_tipo_listado.Items.Add("clientes"); cb_trimestre.Items.Add("1"); cb_trimestre.Items.Add("2"); cb_trimestre.Items.Add("3"); cb_trimestre.Items.Add("4"); } private void Listado_Load(object sender, EventArgs e) { } private void cb_tipo_listado_SelectedIndexChanged(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (tb_anio.Text != "" && cb_trimestre.SelectedIndex.ToString() != "" && cb_tipo_listado.SelectedIndex.ToString() != "") { string fecha_ini = ""; string fecha_fin = ""; string consulta = ""; if (cb_trimestre.SelectedItem.ToString() == "1") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-01-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-03-31 23:59:59', 120)"; } if (cb_trimestre.SelectedItem.ToString() == "2") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-04-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-06-30 23:59:59', 120)"; } if (cb_trimestre.SelectedItem.ToString() == "3") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-07-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-09-30 23:59:59', 120)"; } if (cb_trimestre.SelectedItem.ToString() == "4") { fecha_ini = "convert(datetime, '" + tb_anio.Text + "-10-01 00:00:00', 120)"; fecha_fin = "convert(datetime, '" + tb_anio.Text + "-12-31 23:59:59', 120)"; } //=============================================================================================== //0: choferes //=============================================================================================== if (cb_tipo_listado.SelectedIndex.ToString() == "0") { consulta += "SELECT TOP (5) Id_Chofer,(SELECT Ch_Dni FROM NUNCA_TAXI.Choferes WHERE (NUNCA_TAXI.Viajes.Id_Chofer = Id_Chofer)) AS DNI,(SELECT Ch_Nombre FROM NUNCA_TAXI.Choferes AS Choferes_2 WHERE (NUNCA_TAXI.Viajes.Id_Chofer = Id_Chofer)) AS NOMBRE,(SELECT Ch_Apellido FROM NUNCA_TAXI.Choferes AS Choferes_1 WHERE (NUNCA_TAXI.Viajes.Id_Chofer = Id_Chofer)) AS APELLIDO, SUM(Vi_Importe) AS GastoTotal FROM NUNCA_TAXI.Viajes WHERE (Vi_Fecha BETWEEN "; consulta += fecha_ini; consulta += " AND "; consulta += fecha_fin; consulta += ") GROUP BY Id_Chofer ORDER BY gastototal DESC"; SqlDataAdapter da = new SqlDataAdapter(consulta , con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } //=============================================================================================== //1: taxis //=============================================================================================== if (cb_tipo_listado.SelectedIndex.ToString() == "1") { consulta += "SELECT TOP (5) Id_Taxi,(SELECT Ta_Patente FROM NUNCA_TAXI.Taxis WHERE (NUNCA_TAXI.Viajes.Id_Taxi = Id_Taxi)) AS patente,(SELECT Ta_Licencia FROM NUNCA_TAXI.Taxis AS Choferes_2 WHERE (NUNCA_TAXI.Viajes.Id_Taxi = Id_Taxi)) AS licencia,(SELECT Ma_NombreTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE (Id_MarcaTaxi =(SELECT Id_MarcaTaxi FROM NUNCA_TAXI.Taxis AS Taxis_1 WHERE (NUNCA_TAXI.Viajes.Id_Taxi = Id_Taxi)))) AS MARCA, SUM(Vi_Importe) AS GastoTotal FROM NUNCA_TAXI.Viajes WHERE (Vi_Fecha BETWEEN "; consulta += fecha_ini; consulta += " AND "; consulta += fecha_fin; consulta += ")GROUP BY Id_Taxi ORDER BY gastototal DESC"; SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } //=============================================================================================== //2: clientes //=============================================================================================== if (cb_tipo_listado.SelectedIndex.ToString() == "2") { consulta += "SELECT TOP (5) Id_Cliente,(SELECT Cl_Dni FROM NUNCA_TAXI.Clientes WHERE (NUNCA_TAXI.Viajes.Id_Cliente = Id_Cliente)) AS DNI,(SELECT Cl_Nombre FROM NUNCA_TAXI.Clientes AS Clientes_2 WHERE (NUNCA_TAXI.Viajes.Id_Cliente = Id_Cliente)) AS NOMBRE,(SELECT Cl_Apellido FROM NUNCA_TAXI.Clientes AS Clientes_1 WHERE (NUNCA_TAXI.Viajes.Id_Cliente = Id_Cliente)) AS APELLIDO, SUM(Vi_Importe) AS GastoTotal FROM NUNCA_TAXI.Viajes WHERE (Id_Cliente != 1) AND (Vi_Fecha BETWEEN "; consulta += fecha_ini; consulta += " AND "; consulta += fecha_fin; consulta += ") GROUP BY Id_Cliente ORDER BY gastototal DESC"; SqlDataAdapter da = new SqlDataAdapter(consulta, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } else { MessageBox.Show("Por favor, complete todos los campos para continuar."); } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/TP1C2012 K3151 Nunca_Taxi/src/GestorDeFlotasDesktop/Listado/Listado.cs
C#
asf20
6,950
sqlcmd -S localhost\SQLSERVER2005 -U gd -P gd2012 -i script_creacion_inicial.sql -a 32767 -o resultado_output.txt
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/EjecutarScriptTablasNuncaTaxi.bat
Batchfile
asf20
114
--Grupo: -- NUNCA_TAXI --Integrantes: -- Dorati Hermida, Ivan -- Pereyra, Yohanna -- Torrente, Nicolas -- Schachner, Pablo --Cursada: -- 1er Cuatrimestre, 2012 --Curso: -- K3151-K3051 -------------------------------------------------- -- CREAR ESQUEMAS -- -------------------------------------------------- CREATE SCHEMA NUNCA_TAXI GO -------------------------------------------------- -- CREAR TABLAS -- -------------------------------------------------- CREATE PROCEDURE NUNCA_TAXI.CrearTablasNuncaTaxi AS BEGIN -- MarcasReloj CREATE TABLE NUNCA_TAXI.MarcasReloj( Id_MarcaReloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ma_NombreReloj varchar(255)UNIQUE NOT NULL) -- Relojes CREATE TABLE NUNCA_TAXI.Relojes( Id_Reloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_MarcaReloj numeric (18, 0) References NUNCA_TAXI.MarcasReloj(Id_MarcaReloj) NOT NULL, Re_Modelo varchar(255)UNIQUE NOT NULL, Re_Habilitado bit NOT NULL CONSTRAINT [DF_Relojes_R_Habilitado] DEFAULT ((1)), Re_Fecha_Ver datetime NOT NULL, Re_NoSerie varchar(18) NULL) -- Clientes CREATE TABLE NUNCA_TAXI.Clientes( Id_Cliente numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Cl_Nombre varchar(255) NOT NULL, Cl_Apellido varchar(255) NOT NULL, Cl_Dni numeric(18, 0)UNIQUE NOT NULL, Cl_Telefono numeric(18, 0)UNIQUE NOT NULL, Cl_Direccion varchar(255)UNIQUE NOT NULL, Cl_Mail varchar(255) NULL, Cl_Fecha_Nac datetime NOT NULL, Cl_Habilitado bit NOT NULL CONSTRAINT [DF_Clientes_Cl_Habilitacion] DEFAULT ((1))) -- Turnos CREATE TABLE NUNCA_TAXI.Turnos( Id_Turno numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Tu_Hora_Ini numeric(18, 0) NOT NULL, Tu_Hora_Fin numeric(18, 0) NOT NULL, Tu_Descripcion varchar(255)UNIQUE NOT NULL, Tu_Valor_Ficha numeric(18, 2) NOT NULL, Tu_Valor_Bandera numeric(18, 2) NOT NULL, Tu_Habilitado bit NOT NULL CONSTRAINT [DF_Turnos_Tu_Habilitado] DEFAULT ((1))) -- Choferes CREATE TABLE NUNCA_TAXI.Choferes( Id_Chofer numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ch_Nombre varchar(255) NOT NULL, Ch_Apellido varchar(255) NOT NULL, Ch_Dni numeric(18, 0)UNIQUE NOT NULL, Ch_Direccion varchar(255)UNIQUE NOT NULL, Ch_Telefono numeric(18, 0)UNIQUE NOT NULL, Ch_Mail varchar(255) NULL, Ch_Fecha_Nac datetime NOT NULL, Ch_Habilitado bit NOT NULL CONSTRAINT [DF_Choferes_Ch_Habilitado] DEFAULT ((1))) -- MarcasTaxi CREATE TABLE NUNCA_TAXI.MarcasTaxi( Id_MarcaTaxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ma_NombreTaxi varchar(255)UNIQUE NOT NULL) -- Taxis CREATE TABLE NUNCA_TAXI.Taxis( Id_Taxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_Reloj numeric(18, 0) References NUNCA_TAXI.Relojes(Id_Reloj) NULL, Id_MarcaTaxi numeric(18, 0)References NUNCA_TAXI.MarcasTaxi(Id_MarcaTaxi) NOT NULL, Ta_Patente varchar(255)UNIQUE NOT NULL, Ta_Licencia varchar(255)UNIQUE NOT NULL, Ta_Rodado varchar(250) NOT NULL, Ta_Modelo varchar(255) NOT NULL, Ta_Habilitado bit NOT NULL CONSTRAINT [DF_Taxis_Ta_Habilitado] DEFAULT ((1))) -- TiposViaje CREATE TABLE NUNCA_TAXI.TiposViaje (Id_TipoViaje numeric(18, 0) PRIMARY KEY IDENTITY(0,1) NOT NULL, Ti_DescripcionTipoViaje varchar(255)UNIQUE NOT NULL) -- Viajes CREATE TABLE NUNCA_TAXI.Viajes( Id_Viaje numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_Cliente numeric(18, 0)References NUNCA_TAXI.Clientes(Id_Cliente) NULL, Id_Chofer numeric(18, 0)References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL, Id_Turno numeric(18, 0)References NUNCA_TAXI.Turnos(Id_Turno)NOT NULL, Id_Taxi numeric(18, 0)References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL, Id_TipoViaje numeric(18, 0)References NUNCA_TAXI.TiposViaje(Id_TipoViaje) NOT NULL, Vi_Cant_Fichas numeric(18, 0) NOT NULL, Vi_Fecha datetime NOT NULL, Vi_Importe numeric(18, 2) NOT NULL, Vi_FechaRendido datetime NULL, Vi_FFactura_Ini datetime NULL, Vi_FFactura_Fin datetime NULL) -- ChoferesTurnosTaxis CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis( Id_Chofer numeric(18, 0)References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL, Id_Turno numeric(18, 0)References NUNCA_TAXI.Turnos(Id_Turno)NOT NULL, Id_Taxi numeric(18, 0)References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL, Fecha datetime CONSTRAINT [DF_ChoferesTurnosTaxis_Cat_Fecha] DEFAULT ((getdate())) NOT NULL) -- Rendiciones CREATE TABLE NUNCA_TAXI.Rendiciones( Id_Rendicion numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_Chofer numeric(18, 0)References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL, Id_Turno numeric(18, 0)References NUNCA_TAXI.Turnos(Id_Turno)NOT NULL, Ren_Fecha datetime NOT NULL, Ren_Importe numeric(18, 2) NOT NULL) -- Usuarios CREATE TABLE NUNCA_TAXI.Usuarios( Id_Usuario numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Us_Usuario varchar(255)UNIQUE NOT NULL, Us_Password varchar(255) NOT NULL, Us_Habilitado bit NOT NULL CONSTRAINT [DF_Usuarios_Us_Habilitado] DEFAULT ((1)), Us_Login_Failed numeric(18,0) CONSTRAINT [DF_Usuarios_Us_Login_Failed] DEFAULT ((0)) NOT NULL) -- Roles CREATE TABLE NUNCA_TAXI.Roles( Id_Rol numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ro_Descripcion varchar(255)UNIQUE NOT NULL, Ro_Habilitado bit NOT NULL CONSTRAINT [DF_Roles_Ro_Habilitado] DEFAULT ((1))) -- UsuariosRoles CREATE TABLE NUNCA_TAXI.UsuariosRoles( Id_Usuario numeric(18, 0) References NUNCA_TAXI.Usuarios(Id_Usuario) NOT NULL , Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL) -- Permisos CREATE TABLE NUNCA_TAXI.Permisos( Id_Permiso numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Pe_Descripcion varchar(255)UNIQUE NOT NULL) -- PermisosRoles CREATE TABLE NUNCA_TAXI.PermisosRoles( Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL, Id_Permiso numeric(18, 0) References NUNCA_TAXI.Permisos(Id_Permiso) NOT NULL) END GO -------------------------------------------------- -- MIGRAR Y COMPLETAR TABLAS -- -------------------------------------------------- CREATE PROCEDURE NUNCA_TAXI.CargarTablasNuncaTaxi AS BEGIN -- MarcasReloj INSERT INTO GD1C2012.NUNCA_TAXI.MarcasReloj (Ma_NombreReloj) SELECT DISTINCT Reloj_Marca FROM gd_esquema.Maestra -- Relojes INSERT INTO GD1C2012.NUNCA_TAXI.Relojes (Id_MarcaReloj ,Re_Modelo ,Re_Fecha_Ver) SELECT DISTINCT (SELECT Id_MarcaReloj FROM NUNCA_TAXI.MarcasReloj WHERE Ma_NombreReloj=gd_esquema.Maestra.Reloj_Marca) ,Reloj_Modelo ,Reloj_Fecha_Ver FROM gd_esquema.Maestra -- Clientes INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre ,Cl_Apellido ,Cl_Dni ,Cl_Telefono ,Cl_Direccion ,Cl_Mail ,Cl_Fecha_Nac ,Cl_Habilitado) SELECT DISTINCT Cliente_Nombre, Cliente_Apellido, Cliente_Dni, Cliente_Telefono, Cliente_Direccion, Cliente_Mail, Cliente_Fecha_Nac,1 FROM gd_esquema.Maestra WHERE (Auto_Marca IS NOT NULL) AND (Cliente_Nombre IS NOT NULL) -- Turnos INSERT INTO GD1C2012.NUNCA_TAXI.Turnos (Tu_Hora_Ini ,Tu_Hora_Fin ,Tu_Descripcion ,Tu_Valor_Ficha ,Tu_Valor_Bandera) SELECT DISTINCT Turno_Hora_Inicio, Turno_Hora_Fin, Turno_Descripcion, Turno_Valor_Ficha, Turno_Valor_Bandera FROM gd_esquema.Maestra -- Choferes INSERT INTO GD1C2012.NUNCA_TAXI.Choferes (Ch_Nombre ,Ch_Apellido ,Ch_Dni ,Ch_Direccion ,Ch_Telefono ,Ch_Mail ,Ch_Fecha_Nac) SELECT DISTINCT Chofer_Nombre, Chofer_Apellido, Chofer_Dni, Chofer_Direccion, Chofer_Telefono, Chofer_Mail, Chofer_Fecha_Nac FROM gd_esquema.Maestra -- MarcasTaxi INSERT INTO GD1C2012.NUNCA_TAXI.MarcasTaxi (Ma_NombreTaxi) SELECT DISTINCT Auto_Marca FROM gd_esquema.Maestra -- Taxis INSERT INTO [GD1C2012].[NUNCA_TAXI].[Taxis] (Id_Reloj ,Id_MarcaTaxi ,Ta_Patente ,Ta_Licencia ,Ta_Rodado ,Ta_Modelo) SELECT DISTINCT (SELECT Id_Reloj FROM NUNCA_TAXI.Relojes WHERE Re_Modelo=gd_esquema.Maestra.Reloj_Modelo) ,(SELECT id_MarcaTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE Ma_NombreTaxi=gd_esquema.Maestra.Auto_Marca) ,Auto_Patente ,Auto_Licencia ,Auto_Rodado ,Auto_Modelo FROM gd_esquema.Maestra -- TiposViaje INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Calle') INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Cliente') -- Viajes INSERT INTO GD1C2012.NUNCA_TAXI.Viajes (Id_Cliente ,Id_Chofer ,Id_Turno ,Id_Taxi ,Vi_Cant_Fichas ,Vi_Fecha ,Id_TipoViaje ,Vi_Importe ,Vi_FechaRendido ,Vi_FFactura_Ini ,Vi_FFactura_Fin) SELECT (SELECT id_cliente FROM NUNCA_TAXI.Clientes WHERE cl_Dni=gd_esquema.Maestra.cliente_dni) ,(SELECT id_chofer FROM NUNCA_TAXI.Choferes WHERE Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) , Viaje_Cant_Fichas , Viaje_Fecha ,(CASE WHEN gd_esquema.Maestra.cliente_dni IS NOT NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Cliente') WHEN gd_esquema.Maestra.cliente_dni IS NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Calle') END) ,(SELECT ((gd_esquema.Maestra.Viaje_Cant_Fichas*Tu_Valor_ficha)+Tu_Valor_Bandera) FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,gd_esquema.Maestra.Rendicion_Fecha ,gd_esquema.Maestra.Factura_Fecha_Inicio ,gd_esquema.Maestra.Factura_Fecha_Fin FROM gd_esquema.Maestra -- ChoferesTurnosTaxis INSERT INTO [GD1C2012].[NUNCA_TAXI].[ChoferesTurnosTaxis] (Id_Chofer ,Id_Turno ,Id_Taxi) SELECT DISTINCT (SELECT id_chofer FROM NUNCA_TAXI.Choferes Where Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos Where Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) FROM gd_esquema.Maestra -- Rendiciones INSERT INTO GD1C2012.NUNCA_TAXI.Rendiciones (Id_Chofer ,Id_Turno ,Ren_Fecha ,Ren_Importe) SELECT Id_Chofer , Id_Turno , Vi_FechaRendido , SUM(Vi_Importe) AS ImporteDeRendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NOT NULL) GROUP BY Id_Chofer, Id_Turno, Vi_FechaRendido -- Usuarios INSERT INTO GD1C2012.NUNCA_TAXI.Usuarios (Us_Usuario ,Us_Password) VALUES ('admin','Utd0YrJJhxdcjX2rkBpZZ+kn/8jQtuSiNOB6SuxeNyQ=') -- Permisos INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Rol') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos ([Pe_Descripcion]) VALUES ('ABM de Usuario') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Auto') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Reloj') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Chofer') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Turno') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Asignacion Chofer-Auto') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Registro de Viajes') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Rendicion de Cuenta del Chofer') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Facturacion del Cliente') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Listado Estadistico') -- Roles INSERT INTO [GD1C2012].[NUNCA_TAXI].[Roles] ([Ro_Descripcion]) VALUES ('Administrador del Generaal') -- UsuariosRoles INSERT INTO [GD1C2012].[NUNCA_TAXI].[UsuariosRoles] ([Id_Usuario] ,[Id_Rol]) VALUES (1,1) -- PermisosRoles INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,1) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,2) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,3) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,4) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,5) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,6) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,7) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,8) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,9) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,10) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,11) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,12) END GO EXEC NUNCA_TAXI.CrearTablasNuncaTaxi GO EXEC NUNCA_TAXI.CargarTablasNuncaTaxi GO
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/script_creacion_inicial.sql
TSQL
asf20
14,406
sqlcmd -S localhost\SQLSERVER2005 -U gd -P gd2012 -i script_creacion_inicial.sql -a 32767 -o resultado_output.txt
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/data/EjecutarScriptTablasNuncaTaxi.bat
Batchfile
asf20
114
--Grupo: -- NUNCA_TAXI --Integrantes: -- Dorati Hermida, Ivan -- Pereyra, Yohanna -- Torrente, Nicolas -- Schachner, Pablo --Cursada: -- 1er Cuatrimestre, 2012 --Curso: -- K3151-K3051 -------------------------------------------------- -- CREAR ESQUEMAS -- -------------------------------------------------- CREATE SCHEMA NUNCA_TAXI GO -------------------------------------------------- -- CREAR TABLAS -- -------------------------------------------------- CREATE PROCEDURE NUNCA_TAXI.CrearTablasNuncaTaxi AS BEGIN -- MarcasReloj CREATE TABLE NUNCA_TAXI.MarcasReloj( Id_MarcaReloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ma_NombreReloj varchar(255)UNIQUE NOT NULL) -- Relojes CREATE TABLE NUNCA_TAXI.Relojes( Id_Reloj numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_MarcaReloj numeric (18, 0) References NUNCA_TAXI.MarcasReloj(Id_MarcaReloj) NOT NULL, Re_Modelo varchar(255)UNIQUE NOT NULL, Re_Habilitado bit NOT NULL CONSTRAINT [DF_Relojes_R_Habilitado] DEFAULT ((1)), Re_Fecha_Ver datetime NOT NULL, Re_NoSerie varchar(18) NULL) -- Clientes CREATE TABLE NUNCA_TAXI.Clientes( Id_Cliente numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Cl_Nombre varchar(255) NOT NULL, Cl_Apellido varchar(255) NOT NULL, Cl_Dni numeric(18, 0)UNIQUE NOT NULL, Cl_Telefono numeric(18, 0)UNIQUE NOT NULL, Cl_Direccion varchar(255)UNIQUE NOT NULL, Cl_Mail varchar(255) NULL, Cl_Fecha_Nac datetime NOT NULL, Cl_Habilitado bit NOT NULL CONSTRAINT [DF_Clientes_Cl_Habilitacion] DEFAULT ((1))) -- Turnos CREATE TABLE NUNCA_TAXI.Turnos( Id_Turno numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Tu_Hora_Ini numeric(18, 0) NOT NULL, Tu_Hora_Fin numeric(18, 0) NOT NULL, Tu_Descripcion varchar(255)UNIQUE NOT NULL, Tu_Valor_Ficha numeric(18, 2) NOT NULL, Tu_Valor_Bandera numeric(18, 2) NOT NULL, Tu_Habilitado bit NOT NULL CONSTRAINT [DF_Turnos_Tu_Habilitado] DEFAULT ((1))) -- Choferes CREATE TABLE NUNCA_TAXI.Choferes( Id_Chofer numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ch_Nombre varchar(255) NOT NULL, Ch_Apellido varchar(255) NOT NULL, Ch_Dni numeric(18, 0)UNIQUE NOT NULL, Ch_Direccion varchar(255)UNIQUE NOT NULL, Ch_Telefono numeric(18, 0)UNIQUE NOT NULL, Ch_Mail varchar(255) NULL, Ch_Fecha_Nac datetime NOT NULL, Ch_Habilitado bit NOT NULL CONSTRAINT [DF_Choferes_Ch_Habilitado] DEFAULT ((1))) -- MarcasTaxi CREATE TABLE NUNCA_TAXI.MarcasTaxi( Id_MarcaTaxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ma_NombreTaxi varchar(255)UNIQUE NOT NULL) -- Taxis CREATE TABLE NUNCA_TAXI.Taxis( Id_Taxi numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_Reloj numeric(18, 0) References NUNCA_TAXI.Relojes(Id_Reloj) NULL, Id_MarcaTaxi numeric(18, 0)References NUNCA_TAXI.MarcasTaxi(Id_MarcaTaxi) NOT NULL, Ta_Patente varchar(255)UNIQUE NOT NULL, Ta_Licencia varchar(255)UNIQUE NOT NULL, Ta_Rodado varchar(250) NOT NULL, Ta_Modelo varchar(255) NOT NULL, Ta_Habilitado bit NOT NULL CONSTRAINT [DF_Taxis_Ta_Habilitado] DEFAULT ((1))) -- TiposViaje CREATE TABLE NUNCA_TAXI.TiposViaje (Id_TipoViaje numeric(18, 0) PRIMARY KEY IDENTITY(0,1) NOT NULL, Ti_DescripcionTipoViaje varchar(255)UNIQUE NOT NULL) -- Viajes CREATE TABLE NUNCA_TAXI.Viajes( Id_Viaje numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_Cliente numeric(18, 0)References NUNCA_TAXI.Clientes(Id_Cliente) NULL, Id_Chofer numeric(18, 0)References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL, Id_Turno numeric(18, 0)References NUNCA_TAXI.Turnos(Id_Turno)NOT NULL, Id_Taxi numeric(18, 0)References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL, Id_TipoViaje numeric(18, 0)References NUNCA_TAXI.TiposViaje(Id_TipoViaje) NOT NULL, Vi_Cant_Fichas numeric(18, 0) NOT NULL, Vi_Fecha datetime NOT NULL, Vi_Importe numeric(18, 2) NOT NULL, Vi_FechaRendido datetime NULL, Vi_FFactura_Ini datetime NULL, Vi_FFactura_Fin datetime NULL) -- ChoferesTurnosTaxis CREATE TABLE NUNCA_TAXI.ChoferesTurnosTaxis( Id_Chofer numeric(18, 0)References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL, Id_Turno numeric(18, 0)References NUNCA_TAXI.Turnos(Id_Turno)NOT NULL, Id_Taxi numeric(18, 0)References NUNCA_TAXI.Taxis(Id_Taxi) NOT NULL, Fecha datetime CONSTRAINT [DF_ChoferesTurnosTaxis_Cat_Fecha] DEFAULT ((getdate())) NOT NULL) -- Rendiciones CREATE TABLE NUNCA_TAXI.Rendiciones( Id_Rendicion numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Id_Chofer numeric(18, 0)References NUNCA_TAXI.Choferes(Id_Chofer) NOT NULL, Id_Turno numeric(18, 0)References NUNCA_TAXI.Turnos(Id_Turno)NOT NULL, Ren_Fecha datetime NOT NULL, Ren_Importe numeric(18, 2) NOT NULL) -- Usuarios CREATE TABLE NUNCA_TAXI.Usuarios( Id_Usuario numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Us_Usuario varchar(255)UNIQUE NOT NULL, Us_Password varchar(255) NOT NULL, Us_Habilitado bit NOT NULL CONSTRAINT [DF_Usuarios_Us_Habilitado] DEFAULT ((1)), Us_Login_Failed numeric(18,0) CONSTRAINT [DF_Usuarios_Us_Login_Failed] DEFAULT ((0)) NOT NULL) -- Roles CREATE TABLE NUNCA_TAXI.Roles( Id_Rol numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Ro_Descripcion varchar(255)UNIQUE NOT NULL, Ro_Habilitado bit NOT NULL CONSTRAINT [DF_Roles_Ro_Habilitado] DEFAULT ((1))) -- UsuariosRoles CREATE TABLE NUNCA_TAXI.UsuariosRoles( Id_Usuario numeric(18, 0) References NUNCA_TAXI.Usuarios(Id_Usuario) NOT NULL , Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL) -- Permisos CREATE TABLE NUNCA_TAXI.Permisos( Id_Permiso numeric(18, 0) PRIMARY KEY IDENTITY(1,1) NOT NULL, Pe_Descripcion varchar(255)UNIQUE NOT NULL) -- PermisosRoles CREATE TABLE NUNCA_TAXI.PermisosRoles( Id_Rol numeric(18, 0) References NUNCA_TAXI.Roles(Id_Rol) NOT NULL, Id_Permiso numeric(18, 0) References NUNCA_TAXI.Permisos(Id_Permiso) NOT NULL) END GO -------------------------------------------------- -- MIGRAR Y COMPLETAR TABLAS -- -------------------------------------------------- CREATE PROCEDURE NUNCA_TAXI.CargarTablasNuncaTaxi AS BEGIN -- MarcasReloj INSERT INTO GD1C2012.NUNCA_TAXI.MarcasReloj (Ma_NombreReloj) SELECT DISTINCT Reloj_Marca FROM gd_esquema.Maestra -- Relojes INSERT INTO GD1C2012.NUNCA_TAXI.Relojes (Id_MarcaReloj ,Re_Modelo ,Re_Fecha_Ver) SELECT DISTINCT (SELECT Id_MarcaReloj FROM NUNCA_TAXI.MarcasReloj WHERE Ma_NombreReloj=gd_esquema.Maestra.Reloj_Marca) ,Reloj_Modelo ,Reloj_Fecha_Ver FROM gd_esquema.Maestra -- Clientes INSERT INTO GD1C2012.NUNCA_TAXI.Clientes (Cl_Nombre ,Cl_Apellido ,Cl_Dni ,Cl_Telefono ,Cl_Direccion ,Cl_Mail ,Cl_Fecha_Nac ,Cl_Habilitado) SELECT DISTINCT Cliente_Nombre, Cliente_Apellido, Cliente_Dni, Cliente_Telefono, Cliente_Direccion, Cliente_Mail, Cliente_Fecha_Nac,1 FROM gd_esquema.Maestra WHERE (Auto_Marca IS NOT NULL) AND (Cliente_Nombre IS NOT NULL) -- Turnos INSERT INTO GD1C2012.NUNCA_TAXI.Turnos (Tu_Hora_Ini ,Tu_Hora_Fin ,Tu_Descripcion ,Tu_Valor_Ficha ,Tu_Valor_Bandera) SELECT DISTINCT Turno_Hora_Inicio, Turno_Hora_Fin, Turno_Descripcion, Turno_Valor_Ficha, Turno_Valor_Bandera FROM gd_esquema.Maestra -- Choferes INSERT INTO GD1C2012.NUNCA_TAXI.Choferes (Ch_Nombre ,Ch_Apellido ,Ch_Dni ,Ch_Direccion ,Ch_Telefono ,Ch_Mail ,Ch_Fecha_Nac) SELECT DISTINCT Chofer_Nombre, Chofer_Apellido, Chofer_Dni, Chofer_Direccion, Chofer_Telefono, Chofer_Mail, Chofer_Fecha_Nac FROM gd_esquema.Maestra -- MarcasTaxi INSERT INTO GD1C2012.NUNCA_TAXI.MarcasTaxi (Ma_NombreTaxi) SELECT DISTINCT Auto_Marca FROM gd_esquema.Maestra -- Taxis INSERT INTO [GD1C2012].[NUNCA_TAXI].[Taxis] (Id_Reloj ,Id_MarcaTaxi ,Ta_Patente ,Ta_Licencia ,Ta_Rodado ,Ta_Modelo) SELECT DISTINCT (SELECT Id_Reloj FROM NUNCA_TAXI.Relojes WHERE Re_Modelo=gd_esquema.Maestra.Reloj_Modelo) ,(SELECT id_MarcaTaxi FROM NUNCA_TAXI.MarcasTaxi WHERE Ma_NombreTaxi=gd_esquema.Maestra.Auto_Marca) ,Auto_Patente ,Auto_Licencia ,Auto_Rodado ,Auto_Modelo FROM gd_esquema.Maestra -- TiposViaje INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Calle') INSERT INTO GD1C2012.NUNCA_TAXI.TiposViaje (Ti_DescripcionTipoViaje) VALUES('Cliente') -- Viajes INSERT INTO GD1C2012.NUNCA_TAXI.Viajes (Id_Cliente ,Id_Chofer ,Id_Turno ,Id_Taxi ,Vi_Cant_Fichas ,Vi_Fecha ,Id_TipoViaje ,Vi_Importe ,Vi_FechaRendido ,Vi_FFactura_Ini ,Vi_FFactura_Fin) SELECT (SELECT id_cliente FROM NUNCA_TAXI.Clientes WHERE cl_Dni=gd_esquema.Maestra.cliente_dni) ,(SELECT id_chofer FROM NUNCA_TAXI.Choferes WHERE Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) , Viaje_Cant_Fichas , Viaje_Fecha ,(CASE WHEN gd_esquema.Maestra.cliente_dni IS NOT NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Cliente') WHEN gd_esquema.Maestra.cliente_dni IS NULL THEN(SELECT Id_TipoViaje FROM NUNCA_TAXI.TiposViaje WHERE TI_descripcionTipoViaje='Calle') END) ,(SELECT ((gd_esquema.Maestra.Viaje_Cant_Fichas*Tu_Valor_ficha)+Tu_Valor_Bandera) FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,gd_esquema.Maestra.Rendicion_Fecha ,gd_esquema.Maestra.Factura_Fecha_Inicio ,gd_esquema.Maestra.Factura_Fecha_Fin FROM gd_esquema.Maestra -- ChoferesTurnosTaxis INSERT INTO [GD1C2012].[NUNCA_TAXI].[ChoferesTurnosTaxis] (Id_Chofer ,Id_Turno ,Id_Taxi) SELECT DISTINCT (SELECT id_chofer FROM NUNCA_TAXI.Choferes Where Ch_DNI=gd_esquema.Maestra.Chofer_Dni) ,(SELECT id_Turno FROM NUNCA_TAXI.Turnos Where Tu_Descripcion=gd_esquema.Maestra.Turno_Descripcion) ,(SELECT id_Taxi FROM NUNCA_TAXI.Taxis Where Ta_Patente=gd_esquema.Maestra.Auto_Patente) FROM gd_esquema.Maestra -- Rendiciones INSERT INTO GD1C2012.NUNCA_TAXI.Rendiciones (Id_Chofer ,Id_Turno ,Ren_Fecha ,Ren_Importe) SELECT Id_Chofer , Id_Turno , Vi_FechaRendido , SUM(Vi_Importe) AS ImporteDeRendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NOT NULL) GROUP BY Id_Chofer, Id_Turno, Vi_FechaRendido -- Usuarios INSERT INTO GD1C2012.NUNCA_TAXI.Usuarios (Us_Usuario ,Us_Password) VALUES ('admin','Utd0YrJJhxdcjX2rkBpZZ+kn/8jQtuSiNOB6SuxeNyQ=') -- Permisos INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Cliente') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos (Pe_Descripcion) VALUES ('ABM de Rol') INSERT INTO GD1C2012.NUNCA_TAXI.Permisos ([Pe_Descripcion]) VALUES ('ABM de Usuario') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Auto') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Reloj') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Chofer') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('ABM de Turno') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Asignacion Chofer-Auto') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Registro de Viajes') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Rendicion de Cuenta del Chofer') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Facturacion del Cliente') INSERT INTO [GD1C2012].[NUNCA_TAXI].[Permisos] ([Pe_Descripcion]) VALUES ('Listado Estadistico') -- Roles INSERT INTO [GD1C2012].[NUNCA_TAXI].[Roles] ([Ro_Descripcion]) VALUES ('Administrador del Generaal') -- UsuariosRoles INSERT INTO [GD1C2012].[NUNCA_TAXI].[UsuariosRoles] ([Id_Usuario] ,[Id_Rol]) VALUES (1,1) -- PermisosRoles INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,1) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,2) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,3) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,4) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,5) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,6) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,7) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,8) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,9) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,10) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,11) INSERT INTO [GD1C2012].[NUNCA_TAXI].[PermisosRoles] ([Id_Rol] ,[Id_Permiso]) VALUES (1 ,12) END GO EXEC NUNCA_TAXI.CrearTablasNuncaTaxi GO EXEC NUNCA_TAXI.CargarTablasNuncaTaxi GO
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/data/script_creacion_inicial.sql
TSQL
asf20
14,406
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmCliente { public partial class AbmCliente : Form { public AbmCliente(Modelo.FormActions.Actions action, string id) { InitializeComponent(); pk.Visible = false; lbl_estado.Text = "ALTA"; tb_grande.Visible = false; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Id_Cliente = " + id, con); DataTable dt = new DataTable(); da.Fill(dt); pk.Name = id; tb_nombre.Text = dt.Rows[0]["Cl_Nombre"].ToString(); tb_apellido.Text = dt.Rows[0]["Cl_Apellido"].ToString(); tb_dni.Text = dt.Rows[0]["Cl_Dni"].ToString(); tb_grande.Text = dt.Rows[0]["Cl_Direccion"].ToString(); tb_tel.Text = dt.Rows[0]["Cl_Telefono"].ToString(); tb_mail.Text = dt.Rows[0]["Cl_Mail"].ToString(); dt_nacimiento.Value = DateTime.Parse(dt.Rows[0]["Cl_Fecha_Nac"].ToString()); label7.Visible = label8.Visible = label9.Visible = label11.Visible = false; tb_dpto.Visible = tb_localidad.Visible = tb_nropiso.Visible = tb_cp.Visible = false; tb_grande.Visible = true; if (Convert.ToBoolean(dt.Rows[0]["Cl_Habilitado"].ToString()) == false) { cb_habi.Checked = false; } else { cb_habi.Checked = true; } if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; Propiedades.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmCliente_Load(object sender, EventArgs e) { } private void aceptar_Click_1(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (lbl_estado.Text == "ALTA") { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Clientes(Cl_Nombre,Cl_Apellido,Cl_Dni,Cl_Direccion,Cl_Telefono,Cl_Mail,Cl_Fecha_Nac,Cl_Habilitado) VALUES(@nom,@ape,@dni,@dire,@tel,@mail,@fech,@habi)", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", tb_dni.Text); comando.Parameters.AddWithValue("dire", "(" + tb_dir.Text + ") (" + tb_dpto.Text + ") (" + tb_nropiso.Text + ") (" + tb_localidad.Text + ") (" + tb_cp.Text + ")"); comando.Parameters.AddWithValue("tel", tb_tel.Text); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_nombre.Text = ""; tb_apellido.Text = ""; tb_dni.Text = ""; tb_dir.Text = ""; tb_tel.Text = ""; tb_mail.Text = ""; tb_dpto.Text = ""; tb_nropiso.Text = ""; tb_localidad.Text = ""; tb_cp.Text = ""; cb_habi.Checked = false; dt_nacimiento.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "MODIFICACION") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Clientes SET Cl_Nombre=@nom,Cl_Apellido=@ape,Cl_Dni=@dni,Cl_Direccion=@dire,Cl_Telefono=@tel,Cl_Mail=@mail,Cl_Fecha_Nac=@fech,Cl_Habilitado=@habi WHERE Id_Cliente = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", Convert.ToDecimal(tb_dni.Text)); comando.Parameters.AddWithValue("dire", tb_grande.Text); comando.Parameters.AddWithValue("tel", Convert.ToDecimal(tb_tel.Text)); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Clientes SET Cl_Habilitado=@habi WHERE Id_Cliente = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmCliente/AbmCliente.cs
C#
asf20
8,015
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmCliente { public partial class Listado_Clientes : Form { private Modelo.FormActions.Actions action; public Listado_Clientes(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Clientes_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmCliente(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string dni; if (tb_dni.Text == "") { dni = "0"; } else { dni = tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Cl_Nombre LIKE '" + tb_nombre.Text + "' AND Cl_Apellido LIKE '" + tb_apellido.Text + "' AND Cl_Dni LIKE '" + dni + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmCliente/Listado_Clientes.cs
C#
asf20
4,182
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Security.Cryptography; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Login { public partial class Login : Form { #region Properties private Boolean isValidated = false; public static MainForm mainForm; public static List<int> permisosList = new List<int>(); #endregion #region Public public Login() { InitializeComponent(); } #endregion #region Events private void login_button_Click(Object sender, EventArgs e) { //TODO: agregar validacion de user&pass isValidated = validateUser(user.Text, passwd.Text); if (isValidated) { mainForm = new MainForm(this); mainForm.Show(); } else { MessageBox.Show("La combinación de usuario/contraseña es erronea, o usuario no habilitado", "Error de Login"); foreach (Control ctrl in this.Controls) { if (ctrl is TextBox) { ((TextBox)ctrl).Clear(); } } } } #endregion private Boolean validateUser(String user, String passwd) { bool return_value = false; if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(passwd)) { return return_value; } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { //Validate user Modelo.Modelo.openConnection(con); SqlCommand validate_user = new SqlCommand(Modelo.SqlQueries.getUserInfo(user), con); SqlDataReader reader = validate_user.ExecuteReader(); //If users exists if (reader.FieldCount > 0) { reader.Read(); string password = reader.GetString(1); int login_failed = Convert.ToInt32(reader.GetDecimal(2)); bool habilitado = reader.GetBoolean(3); //Validated passwd and enabled if (password.Equals(getSHA256(passwd)) && habilitado) { SqlConnection con2 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con2); SqlCommand reset_fails = new SqlCommand(Modelo.SqlQueries.resetLoginFails(user), con2); reset_fails.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con2); getPermissions(user); return_value = true; } //User exists, but wrong passwd or not enabled else { if (login_failed < 3) { SqlConnection con4 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con4); SqlCommand inc_login_fail = new SqlCommand(Modelo.SqlQueries.incUserLoginFailed(user, login_failed + 1), con4); inc_login_fail.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con4); //This is the third failed time. Disable user if (login_failed == 2) { SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand disable_user = new SqlCommand(Modelo.SqlQueries.disableUser(user), con3); disable_user.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } return return_value; } public static string getSHA256(string input) { string hashed = null; byte[] inputBytes = Encoding.Unicode.GetBytes(input); SHA256Managed hash = new SHA256Managed(); byte[] hashBytes = hash.ComputeHash(inputBytes); hashed = Convert.ToBase64String(hashBytes); return hashed; } private void Login_Load(object sender, EventArgs e) { } private void getPermissions(string username) { using (SqlConnection con2 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_user_id = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(username), con2); SqlDataReader reader = comando_get_user_id.ExecuteReader(); List<int> roles = new List<int>(); while (reader.Read()) { int user_id = Convert.ToInt32(reader.GetDecimal(0)); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter us_rol_da = new SqlDataAdapter(Modelo.SqlQueries.getUserRoles(user_id), con); DataTable us_rol_dt = new DataTable(); us_rol_da.Fill(us_rol_dt); foreach (DataRow rol in us_rol_dt.Rows) { bool added = Convert.ToBoolean(rol.ItemArray[2]); if (added) { int rol_id = Convert.ToInt32(rol.ItemArray[0].ToString()); using (SqlConnection con3 = Modelo.Modelo.createConnection()) { SqlDataAdapter rol_perm_da = new SqlDataAdapter(Modelo.SqlQueries.getRolePermissions(rol_id), con3); DataTable rol_perm_dt = new DataTable(); rol_perm_da.Fill(rol_perm_dt); foreach (DataRow perm in rol_perm_dt.Rows) { foreach (KeyValuePair<string, int> pair in Modelo.Permissions.PermissionsDict) { if (pair.Value == Convert.ToInt32(perm.ItemArray[0].ToString())) { permisosList.Add(pair.Value); break; } } } } } } } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/Login/Login.cs
C#
asf20
7,831
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmUsuario { public partial class Listado_Usuario : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Usuario(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledUsers, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getUsers, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmUsuario(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUsersFiltered(busqueda_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUsers, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmUsuario/Listado_Usuario.cs
C#
asf20
2,663
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmUsuario { public partial class AbmUsuario : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmUsuario(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; tb_usuario.Enabled = false; tb_passwd.Enabled = false; cb_hab.Enabled = false; dataGridView1.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; tb_usuario.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Modificar"; break; } } public AbmUsuario(Modelo.FormActions.Actions runAction) { InitializeComponent(); cb_hab.Enabled = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void loadData(int id) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getUserById(selected_elem), con); DataTable dt = new DataTable(); da.Fill(dt); DataRow user_info = dt.Rows[0]; tb_usuario.Text = user_info.ItemArray[1].ToString(); cb_hab.Checked = (bool) user_info.ItemArray[2]; SqlDataAdapter us_rol_da = new SqlDataAdapter(Modelo.SqlQueries.getUserRoles(selected_elem), con); DataTable us_rol_dt = new DataTable(); us_rol_da.Fill(us_rol_dt); dataGridView1.DataSource = us_rol_dt; } } private void aceptar_Click(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: string error_txt = "ERROR: "; if (String.IsNullOrEmpty(tb_usuario.Text)) { error_txt = String.Concat(error_txt, "\n Nombre de usuario es obligatorio"); } if (String.IsNullOrEmpty(tb_passwd.Text)) { error_txt = String.Concat(error_txt, "\n Password es obligatorio"); } if(!String.IsNullOrEmpty(tb_usuario.Text) && (!String.IsNullOrEmpty(tb_passwd.Text))){ using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(tb_usuario.Text), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Usuario duplicado"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addUser(tb_usuario.Text, Login.Login.getSHA256(tb_passwd.Text)), con); comando_add_user.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_user_id = new SqlCommand(Modelo.SqlQueries.getUserIdByUsername(tb_usuario.Text), con2); SqlDataReader reader = comando_get_user_id.ExecuteReader(); List<int> roles = new List<int>(); while (reader.Read()) { foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["Added"].Value != null && Convert.ToInt32(row.Cells["Added"].Value) == 1) { roles.Add(Convert.ToInt32(row.Cells["Id"].Value)); } } if (roles.Count > 0) { SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand comando_add_user_role = new SqlCommand(Modelo.SqlQueries.addUserRoles(Convert.ToInt32(reader.GetDecimal(0)), roles), con3); comando_add_user_role.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } } MessageBox.Show(String.Format("Usuario {0} agregado", tb_usuario.Text)); Login.Login.mainForm.openForm(new AbmUsuario(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } else { MessageBox.Show(error_txt); } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteUser(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Usuario {0} eliminado", tb_usuario.Text)); Login.Login.mainForm.openForm(new AbmUsuario(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: if (String.IsNullOrEmpty(tb_usuario.Text)) { MessageBox.Show("Nombre de usuario es obligatorio"); } else { List<int> roles_list = new List<int>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells["Added"].Value != null && Convert.ToInt32(row.Cells["Added"].Value) == 1) { roles_list.Add(Convert.ToInt32(row.Cells["Id"].Value)); } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateUser(selected_elem, Login.Login.getSHA256(tb_passwd.Text), roles_list), connection); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Usuario {0} modificado", tb_usuario.Text)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmUsuario/AbmUsuario.cs
C#
asf20
10,193
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.RegistrarViaje { public partial class RegistrarViajes : Form { public RegistrarViajes() { InitializeComponent(); tb_chofer_index.Visible = tb_cliente_index.Visible = tb_turno_index.Visible = tb_tipo_viaj_index.Visible = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.TiposViaje", con); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_tipo_viaje.Items.Add(dt.Rows[i]["Ti_DescripcionTipoViaje"].ToString()); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_turno.Items.Add(dt.Rows[i]["Tu_Descripcion"].ToString()); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_chofer.Items.Add("(" + dt.Rows[i]["Id_Chofer"].ToString() + ") (" + dt.Rows[i]["Ch_Nombre"].ToString() + ") (" + dt.Rows[i]["Ch_Apellido"].ToString() + ") (" + dt.Rows[i]["Ch_Dni"].ToString() + ")"); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Clientes WHERE Cl_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_cliente.Items.Add("(" + dt.Rows[i]["Id_Cliente"].ToString() + ") (" + dt.Rows[i]["Cl_Nombre"].ToString() + ") (" + dt.Rows[i]["Cl_Apellido"].ToString() + ") (" + dt.Rows[i]["Cl_Dni"].ToString() + ")"); } } } private void RegistrarViajes_Load(object sender, EventArgs e) { } private void cb_chofer_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_chofer.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_chofer_index.Text = numero.ToString(); } private void cb_turno_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_turno.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_turno_index.Text = numero.ToString(); } private void cb_tipo_viaje_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_tipo_viaje.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice); tb_tipo_viaj_index.Text = numero.ToString(); } private void cb_cliente_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_cliente.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_cliente_index.Text = numero.ToString(); } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Descripcion = '" + cb_turno.SelectedItem.ToString() + "'", con); DataTable dt = new DataTable(); da.Fill(dt); decimal valor_ficha = Convert.ToDecimal(dt.Rows[0]["Tu_Valor_Ficha"].ToString()); decimal importe = Convert.ToDecimal(tb_fichas.Text) * valor_ficha; da = new SqlDataAdapter("SELECT T.Id_Taxi FROM NUNCA_TAXI.Taxis T INNER JOIN NUNCA_TAXI.ChoferesTurnosTaxis ON T.Id_Taxi = NUNCA_TAXI.ChoferesTurnosTaxis.Id_Taxi INNER JOIN NUNCA_TAXI.Relojes ON T.Id_Reloj = NUNCA_TAXI.Relojes.Id_Reloj WHERE Ta_Habilitado = 1 AND Re_Habilitado = 1 AND Id_Turno = " + tb_turno_index.Text + " AND Id_Chofer = " + tb_chofer_index.Text, con); dt = new DataTable(); da.Fill(dt); string id_taxi = dt.Rows[0]["Id_Taxi"].ToString(); SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Viajes(Id_Cliente,Id_Chofer,Id_Turno,Id_Taxi,Id_TipoViaje,Vi_Cant_Fichas,Vi_Fecha,Vi_Importe) VALUES(@cliente,@chofer,@turno,@taxi,@tipo_viaje,@cant_fichas,@fecha,@importe)", con); comando.Parameters.AddWithValue("cliente", tb_cliente_index.Text); comando.Parameters.AddWithValue("chofer", tb_chofer_index.Text); comando.Parameters.AddWithValue("turno", tb_turno_index.Text); comando.Parameters.AddWithValue("taxi", id_taxi); comando.Parameters.AddWithValue("tipo_viaje", tb_tipo_viaj_index.Text); comando.Parameters.AddWithValue("cant_fichas", tb_fichas.Text); comando.Parameters.AddWithValue("fecha", dt_fecha.Value); comando.Parameters.AddWithValue("importe", importe); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { cb_tipo_viaje.SelectedIndex = -1; cb_turno.SelectedItem = -1; cb_cliente.SelectedIndex = -1; cb_chofer.SelectedIndex = -1; tb_cliente_index.Text = ""; tb_chofer_index.Text = ""; tb_turno_index.Text = ""; tb_tipo_viaj_index.Text = ""; tb_fichas.Text = ""; dt_fecha.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/RegistrarViaje/RegistrarViajes.cs
C#
asf20
6,736
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmAuto { public partial class AbmAuto : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmAuto(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); marca_cb.DataSource = ds.Tables[0].DefaultView; marca_cb.DisplayMember = "Marca"; marca_cb.ValueMember = "Id"; marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; marca_cb.Enabled = false; reloj_cb.Enabled = false; tb_licencia.Enabled = false; tb_modelo.Enabled = false; tb_patente.Enabled = false; tb_rodado.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar.Text = "Modificar"; break; } } public AbmAuto(Modelo.FormActions.Actions runAction) { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); marca_cb.DataSource = ds.Tables[0].DefaultView; marca_cb.DisplayMember = "Marca"; marca_cb.ValueMember = "Id"; marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_get_autos = new SqlCommand(Modelo.SqlQueries.getAutoById(selected_elem), con3); SqlDataReader reader = comando_get_autos.ExecuteReader(); while (reader.Read()) { marca_cb.SelectedValue= Convert.ToInt32(reader["Marca"]); reloj_cb.SelectedValue = Convert.ToInt32(reader["Reloj"]); tb_licencia.Text = reader["Licencia"].ToString(); tb_modelo.Text = reader["Modelo"].ToString(); tb_patente.Text = reader["Patente"].ToString(); tb_rodado.Text = reader["Rodado"].ToString(); cb_hab.Checked = (Boolean)reader["Habilitado"]; } } } private void aceptar_Click_1(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: string error_txt = "ERROR: "; if (String.IsNullOrEmpty(marca_cb.Text)) { error_txt = String.Concat(error_txt, "\n Marca es obligatorio"); } if (String.IsNullOrEmpty(reloj_cb.Text)) { error_txt = String.Concat(error_txt, "\n Reloj es obligatorio"); } if (String.IsNullOrEmpty(tb_licencia.Text)) { error_txt = String.Concat(error_txt, "\n Licencia es obligatorio"); } if (String.IsNullOrEmpty(tb_modelo.Text)) { error_txt = String.Concat(error_txt, "\n Modelo es obligatorio"); } if (String.IsNullOrEmpty(tb_patente.Text)) { error_txt = String.Concat(error_txt, "\n Patente es obligatorio"); } if (String.IsNullOrEmpty(tb_rodado.Text)) { error_txt = String.Concat(error_txt, "\n Rodado es obligatorio"); } if((!String.IsNullOrEmpty(marca_cb.Text)) && (!String.IsNullOrEmpty(reloj_cb.Text))&& (!String.IsNullOrEmpty(tb_licencia.Text))&& (!String.IsNullOrEmpty(tb_modelo.Text))&& (!String.IsNullOrEmpty(tb_patente.Text))&& (!String.IsNullOrEmpty(tb_rodado.Text))) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTaxiMellizo(tb_patente.Text, tb_licencia.Text, Convert.ToInt32(reloj_cb.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Taxi mellizo"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con_un2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un2); SqlCommand comando_check_unique2 = new SqlCommand(Modelo.SqlQueries.getRelojUsado(Convert.ToInt32(reloj_cb.SelectedValue)), con_un2); SqlDataReader reader = comando_check_unique2.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Reloj en uso"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addAuto( Convert.ToInt32(marca_cb.SelectedValue), Convert.ToInt32(reloj_cb.SelectedValue), tb_licencia.Text, tb_modelo.Text, tb_patente.Text, tb_rodado.Text, true), con); comando_add_user.ExecuteNonQuery(); MessageBox.Show("Taxi agregado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }else { MessageBox.Show(error_txt); } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteAuto(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show("Taxi eliminado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getTaxiMellizo(tb_patente.Text, tb_licencia.Text, Convert.ToInt32(reloj_cb.SelectedValue)), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Taxi mellizo"); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateAuto(selected_elem, Convert.ToInt32(marca_cb.SelectedValue), Convert.ToInt32(reloj_cb.SelectedValue), tb_licencia.Text, tb_modelo.Text, tb_patente.Text, tb_rodado.Text, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show("Taxi modificado"); Login.Login.mainForm.openForm(new AbmAuto(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmAuto/AbmAuto.cs
C#
asf20
13,195
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmAuto { public partial class Listado_Auto : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Auto(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); busqueda_marca_cb.DataSource = ds.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_reloj_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_reloj_cb.DisplayMember = "Marca"; busqueda_reloj_cb.ValueMember = "Id"; busqueda_reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getAutos(), con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmAuto(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutoFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_patente_tb.Text, busqueda_licencia_tb.Text, busqueda_reloj_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_reloj_cb.SelectedValue)), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutos(), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmAuto/Listado_Auto.cs
C#
asf20
4,080
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace GestorDeFlotasDesktop { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Login.Login()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/Program.cs
C#
asf20
519
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Facturar { public partial class Facturar : Form { public Facturar() { InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getClientes, con); DataSet ds = new DataSet(); da.Fill(ds); cb_cliente.DataSource = ds.Tables[0].DefaultView; cb_cliente.DisplayMember = "Cliente"; cb_cliente.ValueMember = "Id"; cb_cliente.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); } private void aceptar_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_Factura(Convert.ToInt32(cb_cliente.SelectedValue), dtp_ini.Value, dtp_fin.Value)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/Facturar/Facturar.cs
C#
asf20
1,118
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Facturar { public partial class Listado_Factura : Form { private DataTable dt; public Listado_Factura(int cliente_id, DateTime f_ini, DateTime f_fin) { InitializeComponent(); tb_fini.Text = f_ini.ToString(); tb_ffin.Text = f_fin.ToString(); FillData(cliente_id, f_ini, f_fin); } void FillData(int cliente_id, DateTime f_ini, DateTime f_fin) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); da = new SqlDataAdapter(Modelo.SqlQueries.getFacturas(cliente_id, f_ini, f_fin), con); da.Fill(dt); dataGridView1.DataSource = dt; } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con2); SqlCommand comando_up_fact = new SqlCommand(Modelo.SqlQueries.updateFacturas(cliente_id, f_ini, f_fin), con2); comando_up_fact.ExecuteNonQuery(); } double total = 0; foreach (DataRow dr in dt.Rows) { if (dr.RowState != DataRowState.Deleted) total += Convert.ToDouble(dr["Importe"]); } tb_importe.Text = total.ToString(); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/Facturar/Listado_Factura.cs
C#
asf20
1,726
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmChofer { public partial class Listado_Chofer : Form { private Modelo.FormActions.Actions action; public Listado_Chofer(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Chofer_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmChofer(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string dni; if (tb_dni.Text == "") { dni = "0"; } else { dni = tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '" + tb_nombre.Text + "' OR Ch_Apellido LIKE '" + tb_apellido.Text + "' OR Ch_Dni = " + dni, con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmChofer/Listado_Chofer.cs
C#
asf20
4,182
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmChofer { public partial class AbmChofer : Form { public AbmChofer(Modelo.FormActions.Actions action, string id) { InitializeComponent(); pk.Visible = false; lbl_estado.Text = "ALTA"; tb_grande.Visible = false; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Id_Chofer = " + id, con); DataTable dt = new DataTable(); da.Fill(dt); //Ch_Nombre,Ch_Apellido,Ch_Dni,Ch_Direccion,Ch_Telefono,Ch_Mail,Ch_Fecha_Nac,Ch_Habilitado pk.Name = id; tb_nombre.Text = dt.Rows[0]["Ch_Nombre"].ToString(); tb_apellido.Text = dt.Rows[0]["Ch_Apellido"].ToString(); tb_dni.Text = dt.Rows[0]["Ch_Dni"].ToString(); tb_grande.Text = dt.Rows[0]["Ch_Direccion"].ToString(); tb_tel.Text = dt.Rows[0]["Ch_Telefono"].ToString(); tb_mail.Text = dt.Rows[0]["Ch_Mail"].ToString(); dt_nacimiento.Value = DateTime.Parse(dt.Rows[0]["Ch_Fecha_Nac"].ToString()); label7.Visible = label8.Visible = label9.Visible = label11.Visible = false; tb_dpto.Visible = tb_localidad.Visible = tb_nropiso.Visible = tb_cp.Visible = false; tb_grande.Visible = true; if (Convert.ToBoolean(dt.Rows[0]["Ch_Habilitado"].ToString()) == false) { cb_habi.Checked = false; } else { cb_habi.Checked = true; } if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; Propiedades.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmChofer_Load(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (lbl_estado.Text == "ALTA") { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Choferes(Ch_Nombre,Ch_Apellido,Ch_Dni,Ch_Direccion,Ch_Telefono,Ch_Mail,Ch_Fecha_Nac,Ch_Habilitado) VALUES(@nom,@ape,@dni,@dire,@tel,@mail,@fech,@habi)", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", tb_dni.Text); comando.Parameters.AddWithValue("dire", "(" + tb_dir.Text + ") (" + tb_dpto.Text + ") (" + tb_nropiso.Text + ") (" + tb_localidad.Text + ") (" + tb_cp.Text + ")"); comando.Parameters.AddWithValue("tel", tb_tel.Text); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_nombre.Text = ""; tb_apellido.Text = ""; tb_dni.Text = ""; tb_dir.Text = ""; tb_tel.Text = ""; tb_mail.Text = ""; tb_dpto.Text = ""; tb_nropiso.Text = ""; tb_localidad.Text = ""; tb_cp.Text = ""; cb_habi.Checked = false; dt_nacimiento.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "MODIFICACION") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Choferes SET Ch_Nombre=@nom,Ch_Apellido=@ape,Ch_Dni=@dni,Ch_Direccion=@dire,Ch_Telefono=@tel,Ch_Mail=@mail,Ch_Fecha_Nac=@fech,Ch_Habilitado=@habi WHERE Id_Chofer = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("nom", tb_nombre.Text); comando.Parameters.AddWithValue("ape", tb_apellido.Text); comando.Parameters.AddWithValue("dni", Convert.ToDecimal(tb_dni.Text)); comando.Parameters.AddWithValue("dire", tb_grande.Text); comando.Parameters.AddWithValue("tel", Convert.ToDecimal(tb_tel.Text)); comando.Parameters.AddWithValue("mail", tb_mail.Text); comando.Parameters.AddWithValue("fech", dt_nacimiento.Value); if (cb_habi.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habi.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Choferes SET Ch_Habilitado=@habi WHERE Id_Chofer = '" + pk.Name + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmChofer/AbmChofer.cs
C#
asf20
8,134
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.RendirViajes { public partial class RendierViajes : Form { public RendierViajes() { InitializeComponent(); tb_chofer_index.Visible = tb_turno_index.Visible = false; tb_importe.Enabled = false; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Habilitado = 1", con); DataTable dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_chofer.Items.Add("(" + dt.Rows[i]["Id_Chofer"].ToString() + ") (" + dt.Rows[i]["Ch_Nombre"].ToString() + ") (" + dt.Rows[i]["Ch_Apellido"].ToString() + ") (" + dt.Rows[i]["Ch_Dni"].ToString() + ")"); } da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); dt = new DataTable(); da.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { cb_turno.Items.Add(dt.Rows[i]["Tu_Descripcion"].ToString()); } } } private void RendierViajes_Load(object sender, EventArgs e) { } private void cb_chofer_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_chofer.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_chofer_index.Text = numero.ToString(); } private void cb_turno_SelectedIndexChanged(object sender, EventArgs e) { string[] split = cb_turno.SelectedIndex.ToString().Split(); string indice = split[0]; int numero = Int32.Parse(indice) + 1; tb_turno_index.Text = numero.ToString(); } private void calcular_Click(object sender, EventArgs e) { if(tb_turno_index.Text != "" && tb_chofer_index.Text != ""){ using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + tb_turno_index.Text + ") AND (Id_Chofer = " + tb_chofer_index.Text + ")", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; da = new SqlDataAdapter("SELECT Id_Chofer, SUM(Vi_Importe) AS Monto_Rendicion FROM NUNCA_TAXI.Viajes WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + tb_turno_index.Text + ") AND (Id_Chofer = " + tb_chofer_index.Text + ") GROUP BY Id_Chofer", con); dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count == 0) { MessageBox.Show("No hay elementos a mostrar"); } else { tb_importe.Text = dt.Rows[0]["Monto_Rendicion"].ToString(); } } } } private void rendir_Click(object sender, EventArgs e) { if (tb_turno_index.Text != "" && tb_chofer_index.Text != "") { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Viajes SET Vi_FechaRendido=@fecha WHERE (Vi_FechaRendido IS NULL) AND (Id_Turno = " + tb_turno_index.Text + ") AND (Id_Chofer = " + tb_chofer_index.Text + ")", con); comando.Parameters.AddWithValue("fecha", dt_fecha.Value); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Rendiciones(Id_Chofer,Id_Turno,Ren_Fecha,Ren_Importe) VALUES(@chofer,@turno,@fecha,@importe)", con); comando.Parameters.AddWithValue("chofer", tb_chofer_index.Text); comando.Parameters.AddWithValue("turno", tb_turno_index.Text); comando.Parameters.AddWithValue("fecha", dt_fecha.Value); comando.Parameters.AddWithValue("importe", Convert.ToDecimal(tb_importe.Text)); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { cb_turno.SelectedItem = -1; cb_chofer.SelectedIndex = -1; tb_importe.Text = ""; dt_fecha.Value = System.DateTime.Now; Modelo.Modelo.closeConnection(con); } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/RendirViajes/RendierViajes.cs
C#
asf20
5,886
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using GestorDeFlotasDesktop.Modelo; // Objetos SQL using System.Data.SqlClient; namespace GestorDeFlotasDesktop { public partial class MainForm : Form { private Login.Login loginForm; private Form activeForm = null; public MainForm(Login.Login loginForm) { InitializeComponent(); this.loginForm = loginForm; this.loginForm.Hide(); this.filterOptions(); } private void filterOptions() { if(!Login.Login.permisosList.Contains(1)) { clienteToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(2)) { rolToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(3)) { usuarioToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(4)) { autoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(5)) { relojToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(6)) { choferToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(7)) { turnoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(8)) { asignarChoferAutoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(9)) { nuevoToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(10)) { rendicionToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(11)) { facturacionToolStripMenuItem.Visible = false; } if (!Login.Login.permisosList.Contains(12)) { reportesToolStripMenuItem.Visible = false; } } public void openForm(Form form){ //lo borro de la coleccion de controles, y seteo la activa a null if (this.activeForm != null) { this.Controls.Remove(this.activeForm); this.activeForm.Dispose(); this.activeForm = null; } this.activeForm = form; this.activeForm.TopLevel = false; this.activeForm.Dock = DockStyle.Fill; this.activeForm.FormBorderStyle = FormBorderStyle.None; this.activeForm.Visible = true; this.Controls.Add(this.activeForm); } private void MainForm_Load(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); toolStripStatusLabel1.Text = "Conectado."; } catch (Exception) { toolStripStatusLabel1.Text = "Sin Conexion !!"; toolStripStatusLabel1.ForeColor = Color.Red; } finally { Modelo.Modelo.closeConnection(con); } } } #region Salir private void salirToolStripMenuItem_Click(object sender, EventArgs e) { Application.Exit(); } #endregion #region Formulario Cliente private void altaClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.AbmCliente(Modelo.FormActions.Actions.Alta, "")); } private void bajaClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Baja)); } private void modificacionClienteLink_Click(object sender, EventArgs e) { this.openForm(new AbmCliente.Listado_Clientes(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Rol private void altaRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.AbmRol(Modelo.FormActions.Actions.Alta)); } private void bajaRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Baja)); } private void modificacionRolLink_Click(object sender, EventArgs e) { this.openForm(new AbmRol.Listado_Rol(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Usuario private void altaUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.AbmUsuario(Modelo.FormActions.Actions.Alta)); } private void bajaUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Baja)); } private void modificacionUsuarioLink_Click(object sender, EventArgs e) { this.openForm(new AbmUsuario.Listado_Usuario(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Auto private void altaAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.AbmAuto(Modelo.FormActions.Actions.Alta)); } private void bajaAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Baja)); } private void modificacionAutoLink_Click(object sender, EventArgs e) { this.openForm(new AbmAuto.Listado_Auto(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Reloj private void altaRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.AbmReloj(Modelo.FormActions.Actions.Alta)); } private void bajaRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Baja)); } private void modificacionRelojLink_Click(object sender, EventArgs e) { this.openForm(new AbmReloj.Listado_Reloj(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Chofer private void altaChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.AbmChofer(Modelo.FormActions.Actions.Alta, "")); } private void bajaChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Baja)); } private void modificacionChoferLink_Click(object sender, EventArgs e) { this.openForm(new AbmChofer.Listado_Chofer(Modelo.FormActions.Actions.Modificacion)); } #endregion #region Formulario Turno-Tarifa private void altaTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTarifa.AbmTurno(Modelo.FormActions.Actions.Alta, "")); } private void bajaTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Baja)); } private void modificacionTurnoLink_Click(object sender, EventArgs e) { this.openForm(new AbmTurno.Listado(Modelo.FormActions.Actions.Modificacion)); } #endregion private void nuevoToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new RegistrarViaje.RegistrarViajes()); } private void asignarChoferAutoToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new AsignChoferAuto.AsignChoferAuto()); } private void facturacionToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new Facturar.Facturar()); } private void rendicionToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new RendirViajes.RendierViajes()); } private void reportesToolStripMenuItem_Click(object sender, EventArgs e) { this.openForm(new Listado.Listado()); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/MainForm.cs
C#
asf20
9,199
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmRol { public partial class AbmRol : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmRol(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; func.Enabled = false; this.aceptar_btn.Text = "Eliminar"; this.tb_rol.Enabled = false; cb_hab.Enabled = false; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar_btn.Text = "Modificar"; cb_hab.Enabled = true; tb_rol.Enabled = true; break; } } public AbmRol(Modelo.FormActions.Actions runAction) { InitializeComponent(); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoleById(selected_elem), con); DataTable dt = new DataTable(); da.Fill(dt); DataRow rol_info = dt.Rows[0]; tb_rol.Text = rol_info.ItemArray[1].ToString(); cb_hab.Checked = (bool)rol_info.ItemArray[2]; SqlDataAdapter rol_perm_da = new SqlDataAdapter(Modelo.SqlQueries.getRolePermissions(selected_elem), con); DataTable rol_perm_dt = new DataTable(); rol_perm_da.Fill(rol_perm_dt); foreach (DataRow perm in rol_perm_dt.Rows) { Convert.ToInt32(perm.ItemArray[0].ToString()); string key = String.Empty; foreach (KeyValuePair<string, int> pair in Modelo.Permissions.PermissionsDict) { if (pair.Value == Convert.ToInt32(perm.ItemArray[0].ToString())) { key = pair.Key; break; } } foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Text.Equals(key)) { ((CheckBox)c).Checked = true; } } } } } } private void aceptar_btn_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(tb_rol.Text)) { switch (action) { case Modelo.FormActions.Actions.Alta: { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_user = new SqlCommand(Modelo.SqlQueries.addRole(tb_rol.Text), con); comando_add_user.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con2 = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con2); SqlCommand comando_get_role_id = new SqlCommand(Modelo.SqlQueries.getRoleIdByName(tb_rol.Text), con2); SqlDataReader reader = comando_get_role_id.ExecuteReader(); List<int> permissions = new List<int>(); while (reader.Read()) { foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked) { permissions.Add(Modelo.Permissions.PermissionsDict[c.Text]); } } } SqlConnection con3 = Modelo.Modelo.createConnection(); Modelo.Modelo.openConnection(con3); SqlCommand comando_add_role_permissions = new SqlCommand(Modelo.SqlQueries.addRolePermissions(Convert.ToInt32(reader.GetDecimal(0)), permissions), con3); comando_add_role_permissions.ExecuteNonQuery(); Modelo.Modelo.closeConnection(con3); } MessageBox.Show(String.Format("Rol {0} agregado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteRole(selected_elem), con); Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Rol {0} eliminado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } break; case Modelo.FormActions.Actions.Modificacion: List<int> permissions_list = new List<int>(); foreach (Control c in func.Controls) { if (c is CheckBox) { if (((CheckBox)c).Checked) { permissions_list.Add(Modelo.Permissions.PermissionsDict[c.Text]); } } } using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateRole(selected_elem, tb_rol.Text, permissions_list, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show(String.Format("Rol {0} modificado", tb_rol.Text)); Login.Login.mainForm.openForm(new AbmRol(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } else { MessageBox.Show("ERROR: El nombre del rol es obligatorio."); } } private void AbmRol_Load(object sender, EventArgs e) { } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmRol/AbmRol.cs
C#
asf20
9,771
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmRol { public partial class Listado_Rol : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Rol(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRoles, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmRol(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRolesFiltered(busqueda_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRoles, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmRol/Listado_Rol.cs
C#
asf20
2,647
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("GestorDeFlotasDesktop")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("GestorDeFlotasDesktop")] [assembly: AssemblyCopyright("Copyright © 2012")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("a1c2fdc9-25c4-4ac4-9e6f-a482c920e7f3")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/Properties/AssemblyInfo.cs
C#
asf20
1,454
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmTurno { public partial class Listado : Form { private Modelo.FormActions.Actions action; public Listado(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); if (action == Modelo.FormActions.Actions.Baja || action == Modelo.FormActions.Actions.Modificacion) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Modificar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Modificar"] = "Modificar"; } dataGridView1.DataSource = dt; for (int i = 0; i < dt.Rows.Count; i++) { cb_desc.Items.Add(dt.Rows[i]["Tu_Descripcion"]); } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void Listado_Load(object sender, EventArgs e) { } private void cb_desc_SelectedIndexChanged(object sender, EventArgs e) { string curItem = cb_desc.SelectedItem.ToString(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_descripcion = '" + curItem + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 7) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; Login.Login.mainForm.openForm(new AbmTarifa.AbmTurno(action, cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_busqueda.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_descripcion LIKE '" + tb_busqueda.Text + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmTurno/Listado.cs
C#
asf20
3,762
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmTarifa { public partial class AbmTurno : Form { public AbmTurno(Modelo.FormActions.Actions action, string id) { InitializeComponent(); lbl_estado.Text = "ALTA"; if (action == Modelo.FormActions.Actions.Modificacion || action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "MODIFICACION"; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Id_Turno = " + id , con); DataTable dt = new DataTable(); da.Fill(dt); tb_desc.Text = dt.Rows[0]["Tu_Descripcion"].ToString(); tb_ini.Text = dt.Rows[0]["Tu_Hora_Ini"].ToString(); tb_fin.Text = dt.Rows[0]["Tu_Hora_Fin"].ToString(); tb_ficha.Text = dt.Rows[0]["Tu_Valor_Ficha"].ToString(); tb_bandera.Text = dt.Rows[0]["Tu_Valor_Bandera"].ToString(); if (Convert.ToBoolean(dt.Rows[0]["Tu_Habilitado"].ToString()) == false) { cb_habilitado.Checked = false; } else { cb_habilitado.Checked = true; } tb_desc.Enabled = false; if (action == Modelo.FormActions.Actions.Baja) { lbl_estado.Text = "BAJA"; gb_car.Enabled = false; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } private void AbmTurno_Load(object sender, EventArgs e) { } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { if (lbl_estado.Text == "ALTA") { SqlCommand comando = new SqlCommand("INSERT INTO NUNCA_TAXI.Turnos(Tu_Hora_Ini,Tu_Hora_Fin,Tu_Descripcion,Tu_Valor_Ficha,Tu_Valor_Bandera,Tu_Habilitado) VALUES(@h_ini,@h_fin,@desc,@ficha,@bandera,@habi)", con); comando.Parameters.AddWithValue("h_ini", tb_ini.Text); comando.Parameters.AddWithValue("h_fin", tb_fin.Text); comando.Parameters.AddWithValue("desc", tb_desc.Text); comando.Parameters.AddWithValue("ficha", Convert.ToDecimal(tb_ficha.Text)); comando.Parameters.AddWithValue("bandera", Convert.ToDecimal(tb_bandera.Text)); if (cb_habilitado.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habilitado.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { tb_ini.Text = ""; tb_fin.Text = ""; tb_desc.Text = ""; tb_ficha.Text = ""; tb_bandera.Text = ""; Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "MODIFICACION") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Turnos SET Tu_Hora_Ini=@h_ini,Tu_Hora_Fin=@h_fin,Tu_Descripcion=@desc,Tu_Valor_Ficha=@ficha,Tu_Valor_Bandera=@bandera,Tu_Habilitado=@habi WHERE Tu_Descripcion = '" + tb_desc.Text + "'", con); comando.Parameters.AddWithValue("h_ini", tb_ini.Text); comando.Parameters.AddWithValue("h_fin", tb_fin.Text); comando.Parameters.AddWithValue("desc", tb_desc.Text); comando.Parameters.AddWithValue("ficha", Convert.ToDecimal(tb_ficha.Text)); comando.Parameters.AddWithValue("bandera", Convert.ToDecimal(tb_bandera.Text)); if (cb_habilitado.Checked == true) { comando.Parameters.AddWithValue("habi", 1); } else if (cb_habilitado.Checked == false) { comando.Parameters.AddWithValue("habi", 0); } try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } if (lbl_estado.Text == "BAJA") { SqlCommand comando = new SqlCommand("UPDATE NUNCA_TAXI.Turnos SET Tu_Habilitado=@habi WHERE Tu_Descripcion = '" + tb_desc.Text + "'", con); comando.Parameters.AddWithValue("habi", 0); try { Modelo.Modelo.openConnection(con); comando.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmTurno/AbmTurno.cs
C#
asf20
6,843
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class AsignChoferAuto : Form { private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public AsignChoferAuto() { InitializeComponent(); fecha = dtp_fecha.Value; } public AsignChoferAuto(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; auto_text = auto_txt; chofer_id = chofer; chofer_text = chofer_txt; turno_id = turno; turno_text = turno_txt; InitializeComponent(); dtp_fecha.Value = fecha; tb_auto.Text = auto_text; tb_chofer.Text = chofer_text; tb_turno.Text = turno_text; } private void aceptar_Click_1(object sender, EventArgs e) { using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getFecAutCho(fecha, auto_id, chofer_id), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("La combinacion Fecha-Auto-Chofer ya existe en la BD"); } else { using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_ACA = new SqlCommand(Modelo.SqlQueries.addACA( fecha, auto_id, chofer_id, turno_id), con); comando_add_ACA.ExecuteNonQuery(); MessageBox.Show("Asignacion Chofer-Auto agregada"); Login.Login.mainForm.openForm(new AsignChoferAuto()); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } private void bt_auto_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Auto(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void bt_chofer_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Chofer(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void bt_turno_Click(object sender, EventArgs e) { Login.Login.mainForm.openForm(new Listado_ACA_Turno(dtp_fecha.Value, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AsignChoferAuto/AsignChoferAuto.cs
C#
asf20
4,162
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Auto : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Auto(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); SqlConnection con = Modelo.Modelo.createConnection(); SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getMarcasTaxi(), con); DataSet ds = new DataSet(); da.Fill(ds); busqueda_marca_cb.DataSource = ds.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcaModeloReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_reloj_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_reloj_cb.DisplayMember = "Marca"; busqueda_reloj_cb.ValueMember = "Id"; busqueda_reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; auto_id = Convert.ToInt32(row.Cells["Id"].Value); auto_text = String.Concat(row.Cells["Marca"].Value, " - ", row.Cells["Model"].Value); Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, chofer_id, chofer_text, turno_id, turno_text)); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getAutoFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_patente_tb.Text, busqueda_licencia_tb.Text, busqueda_reloj_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_reloj_cb.SelectedValue)), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledAutos, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Auto.cs
C#
asf20
4,340
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Turno : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Turno(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; for (int i = 0; i < dt.Rows.Count; i++) { cb_desc.Items.Add(dt.Rows[i]["Tu_Descripcion"]); } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void Listado_Load(object sender, EventArgs e) { } private void cb_desc_SelectedIndexChanged(object sender, EventArgs e) { string curItem = cb_desc.SelectedItem.ToString(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Habilitado = 1 AND Tu_descripcion = '" + curItem + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 7) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewCell desc_cell = dataGridView1.Rows[e.RowIndex].Cells[3]; Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, chofer_id, chofer_text, Convert.ToInt32(cell.Value.ToString()), desc_cell.Value.ToString())); } } private void limpiar_Click(object sender, EventArgs e) { tb_busqueda.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos WHERE Tu_Habilitado = 1", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Turnos where Tu_Habilitado = 1 AND Tu_descripcion LIKE '" + tb_busqueda.Text + "'", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Turno.cs
C#
asf20
4,298
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AsignChoferAuto { public partial class Listado_ACA_Chofer : Form { private DataTable dt; private DateTime fecha; private int auto_id; private int chofer_id; private int turno_id; private string auto_text; private string chofer_text; private string turno_text; public Listado_ACA_Chofer(DateTime fec, int auto, string auto_txt, int chofer, string chofer_txt, int turno, string turno_txt) { fecha = fec; auto_id = auto; chofer_id = chofer; turno_id = turno; auto_text = auto_txt; chofer_text = chofer_txt; turno_text = turno_txt; InitializeComponent(); using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void Listado_Chofer_Load(object sender, EventArgs e) { } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 9) { DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewCell cell_nombre = dataGridView1.Rows[e.RowIndex].Cells[1]; DataGridViewCell cell_apellido = dataGridView1.Rows[e.RowIndex].Cells[2]; Login.Login.mainForm.openForm(new AsignChoferAuto(fecha, auto_id, auto_text, Convert.ToInt32(cell.Value.ToString()), String.Concat(cell_nombre.Value.ToString(), " - ", cell_apellido.Value.ToString()), turno_id, turno_text)); } } private void limpiar_Click(object sender, EventArgs e) { tb_apellido.Text = tb_dni.Text = tb_nombre.Text = ""; using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } try { Modelo.Modelo.openConnection(con); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Modelo.Modelo.closeConnection(con); } } } private void aceptar_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { string dni; if (tb_dni.Text == "") { dni = "0"; } else { dni = tb_dni.Text; } SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM NUNCA_TAXI.Choferes WHERE Ch_Nombre LIKE '" + tb_nombre.Text + "' OR Ch_Apellido LIKE '" + tb_apellido.Text + "' OR Ch_Dni = " + dni + " AND Ch_habilitado = 1;", con); DataTable dt = new DataTable(); da.Fill(dt); dt.Columns.Add("Seleccionar"); for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i]["Seleccionar"] = "Seleccionar"; } dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AsignChoferAuto/Listado_ACA_Chofer.cs
C#
asf20
4,872
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.Modelo { public static class Modelo { //public static System.Data.SqlClient.SqlConnection con; public const string con_str = "Data Source=localhost\\SQLSERVER2005; Initial Catalog=GD1C2012; User ID = gd; Password = gd2012"; public static SqlConnection createConnection() { SqlConnection con = new SqlConnection(); con.ConnectionString = con_str; return con; } public static void openConnection(SqlConnection con) { con.Open(); } public static void closeConnection(SqlConnection con) { con.Close(); } } public class User { public void getRoles() { } } public class Roles { public void getPermissions() { } } public class Permissions { public static Dictionary<string, int> PermissionsDict= new Dictionary<string,int>() { {"ABM de Cliente",1}, {"ABM de Rol",2}, {"ABM de Usuario",3}, {"ABM de Auto",4}, {"ABM de Reloj",5}, {"ABM de Chofer",6}, {"ABM de Turno",7}, {"Asignación Chofer-Auto",8}, {"Registro de Viajes",9}, {"Rendición de Cuenta del Chofer",10}, {"Facturación del Cliente",11}, {"Listado Estadístico",12}, }; } public static class FormActions { public enum Actions { Alta, Baja, Modificacion } } public static class SqlQueries { #region Roles public static string getRoles = "SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles;"; public static string getEnabledRoles = "SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles WHERE Ro_Habilitado = 1;"; public static string getRolesFiltered(string filter_text) { return String.Format("SELECT Id_Rol as Id, Ro_Descripcion as Descripcion FROM NUNCA_TAXI.Roles WHERE Ro_Descripcion LIKE '%{0}%';", filter_text); } public static string getRoleById(int id) { return String.Format("SELECT Id_Rol, Ro_Descripcion, Ro_Habilitado FROM NUNCA_TAXI.Roles WHERE Id_Rol = {0};", id); } public static string deleteRole(int id) { string delete_role = String.Format("UPDATE NUNCA_TAXI.Roles SET Ro_habilitado = 0 WHERE Id_Rol = {0};", id); string delete_user_role = String.Format("DELETE FROM NUNCA_TAXI.UsuariosRoles WHERE Id_Rol = {0};", id); return String.Concat(delete_role, delete_user_role); } public static string addRole(string role) { return String.Format("INSERT INTO NUNCA_TAXI.Roles(Ro_Descripcion, Ro_Habilitado)" + " VALUES('{0}',1);", role); } public static string getRoleIdByName(string role) { return String.Format("SELECT TOP 1 Id_Rol FROM NUNCA_TAXI.Roles WHERE Ro_Descripcion = '{0}';", role); } public static string addRolePermissions(int roleId, List<int> permissions) { string insert_role_permissions = String.Empty; foreach (int permission in permissions) { string insert_role_permission = String.Format("INSERT INTO NUNCA_TAXI.PermisosRoles(Id_Rol, Id_Permiso)" + " VALUES ({0}, {1});", roleId, permission); insert_role_permissions = String.Concat(insert_role_permissions, insert_role_permission); } return insert_role_permissions; } public static string updateRole(int roleId, string roleName, List<int> permissions, bool enabled) { string update_rol_info = String.Format("UPDATE NUNCA_TAXI.Roles SET Ro_Descripcion = '{1}', Ro_Habilitado = {2} " + "WHERE Id_Rol = {0};", roleId, roleName, Convert.ToInt32(enabled)); string delete_roles_permissions = String.Format("DELETE FROM NUNCA_TAXI.PermisosRoles WHERE Id_Rol = {0};", roleId); string update_roles_permissions = String.Concat(update_rol_info, delete_roles_permissions); foreach (int permission in permissions) { string update_role_permission = String.Format("INSERT INTO NUNCA_TAXI.PermisosRoles(Id_Rol, Id_Permiso)" + " VALUES ({0}, {1});", roleId, permission); update_roles_permissions = String.Concat(update_roles_permissions, update_role_permission); } return update_roles_permissions; } public static string getRolePermissions(int roleId) { return String.Format("SELECT Id_Permiso FROM NUNCA_TAXI.PermisosRoles WHERE Id_Rol = {0};", roleId); } #endregion #region Users public static string getUsers = "SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios;"; public static string getEnabledUsers = "SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_habilitado = 1;"; public static string getUsersFiltered(string filter_text) { return String.Format("SELECT Id_Usuario as Id, Us_Usuario as Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario LIKE '%{0}%';", filter_text); } public static string getUserById(int id) { return String.Format("SELECT Id_Usuario, Us_Usuario, Us_Habilitado FROM NUNCA_TAXI.Usuarios WHERE Id_Usuario = {0};", id); } public static string getUserIdByUsername(string username) { return String.Format("SELECT Id_Usuario FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario = '{0}';", username); } public static string deleteUser(int id) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = 0 WHERE Id_Usuario = {0};", id); } public static string getUserRoles(int userId) { return String.Format("SELECT Rol.Id_Rol as Id, Rol.Ro_Descripcion as Descripcion, " + "ISNULL((SELECT 1 FROM NUNCA_TAXI.UsuariosRoles " + "WHERE Id_Rol = Rol.Id_Rol " + "AND Id_usuario = {0}), 0) as Habilitado " + "FROM NUNCA_TAXI.Roles Rol;", userId); } public static string addUser(string user, string passwd) { return String.Format("INSERT INTO NUNCA_TAXI.Usuarios(Us_Habilitado, Us_Usuario, Us_Password)" + " VALUES(1,'{0}','{1}');", user, Login.Login.getSHA256(passwd)); } public static string addUserRoles(int userId, List<int> roles) { string insert_user_roles = String.Empty; foreach (int role in roles) { string insert_user_role = String.Format("INSERT INTO NUNCA_TAXI.UsuariosRoles(Id_Usuario, Id_Rol)" + " VALUES ({0}, {1});",userId, role); insert_user_roles = String.Concat(insert_user_roles, insert_user_role); } return insert_user_roles; } public static string updateUser(int userId, string passwd, List<int> roles) { string update_user = String.Empty; if (!String.IsNullOrEmpty(passwd)) { update_user = String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Password = '{0}' " + "WHERE Id_Usuario = {1};", passwd, userId); } string delete_user_roles = String.Format("DELETE FROM NUNCA_TAXI.UsuariosRoles WHERE Id_Usuario = {0};", userId); string update_user_roles = String.Concat(update_user, delete_user_roles); foreach (int role in roles) { string update_user_role = String.Format("INSERT INTO NUNCA_TAXI.UsuariosRoles(Id_Usuario, Id_Rol)" + " VALUES ({0}, {1});", userId, role); update_user_roles = String.Concat(update_user_roles, update_user_role); } return update_user_roles; } public static string getUserInfo(string user) { return String.Format("SELECT Us_Usuario, Us_Password, Us_Login_Failed, Us_Habilitado FROM NUNCA_TAXI.Usuarios WHERE Us_Usuario = '{0}';",user); } public static string resetLoginFails(string user) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Login_Failed = 0 WHERE Us_Usuario = '{0}'", user); } public static string disableUser(string user) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Habilitado = 0 WHERE Us_Usuario = '{0}'", user); } public static string incUserLoginFailed(string user, int fails) { return String.Format("UPDATE NUNCA_TAXI.Usuarios SET Us_Login_Failed = {1} WHERE Us_Usuario = '{0}'", user, fails); } #endregion #region Auto public static string getAutoFiltered(int marca, string modelo, string patente, string licencia, int reloj){ string marca_where = String.Empty; string modelo_where = String.Empty; string patente_where = String.Empty; string licencia_where = String.Empty; string reloj_where = String.Empty; string auto_filtered = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj"; if (marca != -1) { marca_where = String.Format(" AND T.Id_MarcaTaxi = {0}", Convert.ToInt32(marca)); auto_filtered = String.Concat(auto_filtered, marca_where); } if (!String.IsNullOrEmpty(modelo)) { modelo_where = String.Format(" AND T.Ta_Modelo LIKE '%{0}%'", modelo); auto_filtered = String.Concat(auto_filtered, modelo_where); } if (!String.IsNullOrEmpty(patente)) { patente_where = String.Format(" AND T.Ta_Patente LIKE '%{0}%'", patente); auto_filtered = String.Concat(auto_filtered, patente_where); } if (!String.IsNullOrEmpty(licencia)) { licencia_where = String.Format(" AND T.Ta_Licencia LIKE '%{0}%'", licencia); auto_filtered = String.Concat(auto_filtered, licencia_where); } if (reloj != -1) { reloj_where = String.Format(" AND T.Id_Reloj = {0}", Convert.ToInt32(reloj)); auto_filtered = String.Concat(auto_filtered, reloj_where); } auto_filtered = String.Concat(auto_filtered, ";"); return auto_filtered; } public static string getAutos() { return "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj;"; } public static string getAutosComplete = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj, T.Ta_Rodado as Rodado, T.Ta_Habilitado as Habilitado " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj;;"; public static string getEnabledAutos = "SELECT T.Id_Taxi as ID, MT.Ma_NombreTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Reloj " + "FROM NUNCA_TAXI.Taxis T, NUNCA_TAXI.MarcasReloj MR, NUNCA_TAXI.MarcasTaxi MT, NUNCA_TAXI.Relojes R " + "WHERE T.Id_MarcaTaxi = MT.Id_MarcaTaxi AND T.Id_Reloj = R.Id_Reloj AND R.Id_MarcaReloj = MR.Id_MarcaReloj AND T.Ta_Habilitado = 1;"; public static string getAutoById(int id) { string getEnabledAutosById = "SELECT T.Id_Taxi as ID, T.Id_MarcaTaxi as Marca, T.Ta_Modelo as Modelo, T.Ta_Patente as Patente, T.Ta_Licencia as Licencia, T.Id_Reloj as Reloj, T.Ta_Rodado as Rodado, T.Ta_Habilitado as Habilitado " + "FROM NUNCA_TAXI.Taxis T " + "WHERE T.Id_Taxi = {0};"; return String.Format(getEnabledAutosById, id); } public static string deleteAuto(int id) { return String.Format("UPDATE NUNCA_TAXI.Taxis SET Ta_Habilitado = 0 WHERE Id_Taxi = {0};", id); } public static string updateAuto(int id, int marca, int reloj, string licencia, string modelo, string patente, string rodado, bool hab) { return String.Format("UPDATE NUNCA_TAXI.Taxis SET Id_MarcaTaxi = {1}, Id_Reloj = {2} , Ta_Licencia = '{3}', Ta_Modelo = '{4}', Ta_Patente = '{5}', Ta_Rodado = '{6}', Ta_Habilitado = {7} " + "WHERE Id_Taxi = {0};", id, marca, reloj, licencia, modelo, patente, rodado, Convert.ToInt32(hab)); } public static string addAuto(int marca, int reloj, string licencia, string modelo, string patente, string rodado, bool hab) { return String.Format("INSERT INTO NUNCA_TAXI.Taxis(Id_MarcaTaxi, Id_Reloj, Ta_Licencia, Ta_Modelo, Ta_Patente, Ta_Rodado, Ta_Habilitado) " + "VALUES({0}, {1}, '{2}', '{3}', '{4}', '{5}', {6})", marca, reloj, licencia, modelo, patente, rodado, Convert.ToInt32(hab)); } #endregion #region Relojes public static string getEnabledRelojes = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj AND R.Re_Habilitado = 1;"; public static string getRelojes = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj;"; public static string getRelojFiltered(int marca, string modelo, string nro_serie){ string marca_where = String.Empty; string modelo_where = String.Empty; string nro_serie_where = String.Empty; string reloj_filtered = "SELECT R.Id_Reloj as Id, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, MR.Ma_NombreReloj as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR " + "WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj"; if (marca != -1) { marca_where = String.Format(" AND R.Id_MarcaReloj = {0}", Convert.ToInt32(marca)); reloj_filtered = String.Concat(reloj_filtered, marca_where); } if (!String.IsNullOrEmpty(modelo)) { modelo_where = String.Format(" AND R.Re_Modelo LIKE '%{0}%'", modelo); reloj_filtered = String.Concat(reloj_filtered, modelo_where); } if (!String.IsNullOrEmpty(nro_serie)) { nro_serie_where = String.Format(" AND R.Re_NoSerie LIKE '%{0}%'", nro_serie); reloj_filtered = String.Concat(reloj_filtered, nro_serie_where); } reloj_filtered = String.Concat(reloj_filtered, ";"); return reloj_filtered; } public static string getRelojById(int id) { return String.Format("SELECT R.Re_Habilitado as Habilitado, R.Re_Fecha_Ver as FecVerific, R.Re_Modelo as Modelo, R.Re_NoSerie as NroSerie, R.Id_MarcaReloj as Marca " + "FROM NUNCA_TAXI.Relojes R " + "WHERE R.Id_Reloj = {0};", id); } public static string addReloj(int id_marca_reloj, string modelo, string nroserie, DateTime verific, bool hab) { return String.Format("INSERT INTO NUNCA_TAXI.Relojes(Id_MarcaReloj, Re_modelo, Re_NoSerie, Re_Habilitado, Re_Fecha_Ver) " + "VALUES({0}, '{1}', '{2}', {3}, '{4}');", id_marca_reloj, modelo, nroserie, Convert.ToInt32(hab), String.Format("{0:d/M/yyyy HH:mm:ss}", verific)); } public static string deleteReloj(int id) { return String.Format("UPDATE NUNCA_TAXI.Relojes SET Re_Habilitado = 0 WHERE Id_Reloj = {0};", id); } public static string updateReloj(int id, int id_marca_reloj, string modelo, string nroserie, DateTime verific, bool hab) { return String.Format("UPDATE NUNCA_TAXI.Relojes SET Id_MarcaReloj = {0}, Re_modelo = '{1}', Re_NoSerie = '{2}', Re_Habilitado = {3}, Re_Fecha_Ver = '{4}' " + "WHERE Id_Reloj = {5};", id_marca_reloj, modelo, nroserie, Convert.ToInt32(hab), String.Format("{0:d/M/yyyy HH:mm:ss}", verific), id); } #endregion #region MarcasTaxi public static string getMarcasTaxi() { return "SELECT Id_MarcaTaxi as Id, Ma_NombreTaxi as Marca FROM NUNCA_TAXI.MarcasTaxi;"; } #endregion #region MarcasReloj public static string getMarcasReloj() { return "SELECT Id_MarcaReloj as Id, Ma_NombreReloj as Marca FROM NUNCA_TAXI.MarcasReloj;"; } public static string getMarcaModeloReloj() { return "SELECT R.Id_Reloj as Id, (MR.Ma_NombreReloj + ' - ' + R.Re_Modelo) as Marca " + "FROM NUNCA_TAXI.Relojes R, NUNCA_TAXI.MarcasReloj MR WHERE R.Id_MarcaReloj = MR.Id_MarcaReloj;"; } #endregion public static string addACA(DateTime fecha, int auto_id, int chofer_id, int turno_id) { return String.Format("INSERT INTO NUNCA_TAXI.ChoferesTurnosTaxis(Id_Chofer, Id_Turno, Id_Taxi, Fecha) " + " VALUES({2},{3},{1},'{0}');",String.Format("{0:d/M/yyyy}", fecha), auto_id,chofer_id,turno_id); } public static string getClientes = "SELECT Id_Cliente as Id, (Cl_Nombre + ' - ' + Cl_Apellido) as Cliente FROM NUNCA_TAXI.Clientes;"; public static string getFacturas(int id_cliente, DateTime ini, DateTime fin) { return String.Format("SELECT (Ch.Ch_Nombre + ' - ' + Ch.Ch_Apellido) as Chofer, V.Vi_Cant_Fichas as CantidadFichas, V.Vi_Importe as Importe, V.Vi_Fecha as Fecha, T.Tu_Descripcion as Turno " + "FROM NUNCA_TAXI.Choferes Ch, NUNCA_TAXI.Viajes V, NUNCA_TAXI.Turnos T " + "WHERE V.Id_Chofer = Ch.Id_Chofer AND V.Id_Turno = T.Id_Turno AND V.Id_Cliente = {0} AND V.Vi_Fecha <= '{1}' AND V.Vi_Fecha >= '{2}' AND Vi_FFactura_Ini IS NULL AND Vi_FFactura_Fin IS NULL ;", id_cliente, String.Format("{0:d/M/yyyy HH:mm:ss}", fin), String.Format("{0:d/M/yyyy HH:mm:ss}", ini)); } public static string updateFacturas(int id_cliente, DateTime ini, DateTime fin) { return String.Format("UPDATE NUNCA_TAXI.Viajes SET Vi_FFactura_Ini = '{2}', Vi_FFactura_Fin = '{1}' WHERE Id_Cliente = {0};", id_cliente, String.Format("{0:d/M/yyyy HH:mm:ss}", fin), String.Format("{0:d/M/yyyy HH:mm:ss}", ini)); } public static string getTaxiMellizo(string patente, string licencia, int reloj) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.Taxis T " + "WHERE Ta_Patente = '{0}' AND Ta_Licencia = '{1}' AND Id_Reloj = {2}", patente, licencia, reloj); } public static string getRelojUsado(int reloj) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.Taxis T " + "WHERE Id_Reloj = {0} AND Ta_Habilitado = 1;", reloj); } public static string getFecAutCho(DateTime fecha, int autoId, int choferId) { return String.Format("SELECT 1 " + "FROM NUNCA_TAXI.ChoferesTurnosTaxis " + "WHERE Id_Chofer = {0} AND Id_Taxi = {1} AND Fecha = '{2}';", choferId, autoId, String.Format("{0:d/M/yyyy}", fecha)); } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/Modelo/Modelo.cs
C#
asf20
22,396
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmReloj { public partial class Listado_Reloj : Form { private DataTable dt; private Modelo.FormActions.Actions action; public Listado_Reloj(Modelo.FormActions.Actions runAction) { action = runAction; InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); busqueda_marca_cb.DataSource = ds2.Tables[0].DefaultView; busqueda_marca_cb.DisplayMember = "Marca"; busqueda_marca_cb.ValueMember = "Id"; busqueda_marca_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); FillData(); } void FillData() { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da; dt = new DataTable(); switch (action) { case Modelo.FormActions.Actions.Baja: da = new SqlDataAdapter(Modelo.SqlQueries.getEnabledRelojes, con); da.Fill(dt); break; case Modelo.FormActions.Actions.Modificacion: da = new SqlDataAdapter(Modelo.SqlQueries.getRelojes, con); da.Fill(dt); break; } dataGridView1.DataSource = dt; } } private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { int rowIndex = e.RowIndex; int columnIndex = e.ColumnIndex; DataGridViewRow row = dataGridView1.Rows[rowIndex]; Login.Login.mainForm.openForm(new AbmReloj(action, Convert.ToInt32(row.Cells["Id"].Value))); } private void buscar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRelojFiltered( busqueda_marca_cb.SelectedValue == null ? -1 : Convert.ToInt32(busqueda_marca_cb.SelectedValue), busqueda_modelo_tb.Text, busqueda_nroserie_tb.Text), con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } private void limpiar_btn_Click(object sender, EventArgs e) { using (SqlConnection con = Modelo.Modelo.createConnection()) { SqlDataAdapter da = new SqlDataAdapter(Modelo.SqlQueries.getRelojes, con); dt.Dispose(); dt = new DataTable(); da.Fill(dt); dataGridView1.DataSource = dt; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmReloj/Listado_Reloj.cs
C#
asf20
3,403
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace GestorDeFlotasDesktop.AbmReloj { public partial class AbmReloj : Form { private Modelo.FormActions.Actions action = Modelo.FormActions.Actions.Alta; private int selected_elem = -1; public AbmReloj(Modelo.FormActions.Actions runAction, int id) { InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); switch (runAction) { case Modelo.FormActions.Actions.Baja: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Baja; reloj_cb.Enabled = false; tb_modelo.Enabled = false; tb_nroserie.Enabled = false; verific_dtp.Enabled = false; cb_hab.Enabled = false; aceptar.Text = "Eliminar"; break; case Modelo.FormActions.Actions.Modificacion: selected_elem = id; this.loadData(selected_elem); action = Modelo.FormActions.Actions.Modificacion; aceptar.Text = "Modificar"; break; } } public AbmReloj(Modelo.FormActions.Actions runAction) { InitializeComponent(); SqlConnection con2 = Modelo.Modelo.createConnection(); SqlDataAdapter da2 = new SqlDataAdapter(Modelo.SqlQueries.getMarcasReloj(), con2); DataSet ds2 = new DataSet(); da2.Fill(ds2); reloj_cb.DataSource = ds2.Tables[0].DefaultView; reloj_cb.DisplayMember = "Marca"; reloj_cb.ValueMember = "Id"; reloj_cb.SelectedIndex = -1; Modelo.Modelo.closeConnection(con2); cb_hab.Enabled = false; } private void loadData(int id) { using (SqlConnection con3 = Modelo.Modelo.createConnection()) { Modelo.Modelo.openConnection(con3); SqlCommand comando_get_autos = new SqlCommand(Modelo.SqlQueries.getRelojById(selected_elem), con3); SqlDataReader reader = comando_get_autos.ExecuteReader(); while (reader.Read()) { reloj_cb.SelectedValue = Convert.ToInt32(reader["Marca"]); tb_modelo.Text = reader["Modelo"].ToString(); tb_nroserie.Text = reader["NroSerie"].ToString(); verific_dtp.Value = Convert.ToDateTime(reader["FecVerific"]); cb_hab.Checked = (Boolean)reader["Habilitado"]; } } } private void aceptar_Click(object sender, EventArgs e) { switch (action) { case Modelo.FormActions.Actions.Alta: using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando_add_reloj = new SqlCommand(Modelo.SqlQueries.addReloj( Convert.ToInt32(reloj_cb.SelectedValue), tb_modelo.Text, tb_nroserie.Text, verific_dtp.Value, true), con); comando_add_reloj.ExecuteNonQuery(); MessageBox.Show("Reloj agregado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Baja: using (SqlConnection con_un = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con_un); SqlCommand comando_check_unique = new SqlCommand(Modelo.SqlQueries.getRelojUsado(selected_elem), con_un); SqlDataReader reader = comando_check_unique.ExecuteReader(); if (reader.Read()) { MessageBox.Show("Reloj estaba siendo usado por un taxi habilitado"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } using (SqlConnection con = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(con); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.deleteReloj(selected_elem), con); comando.ExecuteNonQuery(); MessageBox.Show("Reloj eliminado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; case Modelo.FormActions.Actions.Modificacion: using (SqlConnection connection = Modelo.Modelo.createConnection()) { try { Modelo.Modelo.openConnection(connection); SqlCommand comando = new SqlCommand(Modelo.SqlQueries.updateReloj(selected_elem, Convert.ToInt32(reloj_cb.SelectedValue), tb_modelo.Text, tb_nroserie.Text, verific_dtp.Value, cb_hab.Checked), connection); comando.ExecuteNonQuery(); MessageBox.Show("Reloj modificado"); Login.Login.mainForm.openForm(new AbmReloj(Modelo.FormActions.Actions.Alta)); } catch (Exception ex) { MessageBox.Show(ex.Message); } } break; } } } }
09066bd9cc483c8928891679d8ad73b5
trunk/ArchivosEntrega/TP1C2012 K3051 NUNCA_TAXI/src/GestorDeFlotasDesktop/AbmReloj/AbmReloj.cs
C#
asf20
7,882